Ignore:
Timestamp:
Sep 15, 2001, 11:47:44 AM (24 years ago)
Author:
sandervl
Message:

restored old version

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/msacm32/pcmconverter.c

    r6648 r6712  
    11/* -*- tab-width: 8; c-basic-offset: 4 -*- */
    2 /* $Id: pcmconverter.c,v 1.2 2001-09-05 13:11:26 bird Exp $ */
     2
    33/*
    44 *      MSACM32 library
    55 *
    6  *      Copyright 2000      Eric Pouech
    7  *
    8  *  FIXME / TODO list
    9  *  + most of the computation should be done in fixed point arithmetic
    10  *    instead of floating point (16 bits for integral part, and 16 bits
    11  *    for fractional part for example)
    12  *  + implement PCM_FormatSuggest function
    13  *  + get rid of hack for PCM_DriverProc (msacm32.dll shouldn't export
    14  *    a DriverProc, but this would require implementing a generic
    15  *    embedded driver handling scheme in msacm32.dll which isn't done yet
     6 *      Copyright 2000          Eric Pouech
     7 *
     8 *      FIXME / TODO list
     9 *      + most of the computation should be done in fixed point arithmetic
     10 *        instead of floating point (16 bits for integral part, and 16 bits
     11 *        for fractional part for example)
     12 *      + implement PCM_FormatSuggest function
     13 *      + get rid of hack for PCM_DriverProc (msacm32.dll shouldn't export
     14 *        a DriverProc, but this would require implementing a generic
     15 *        embedded driver handling scheme in msacm32.dll which isn't done yet
    1616 */
    1717
     
    3535 *           PCM_drvOpen
    3636 */
    37 static  DWORD   PCM_drvOpen(LPCSTR str)
     37static  DWORD   PCM_drvOpen(LPCSTR str)
    3838{
    3939    return 1;
     
    4343 *           PCM_drvClose
    4444 */
    45 static  DWORD   PCM_drvClose(DWORD dwDevID)
     45static  DWORD   PCM_drvClose(DWORD dwDevID)
    4646{
    4747    return 1;
    4848}
    4949
    50 #define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
    51 #define NUM_OF(a,b) (((a)+(b)-1)/(b))
     50#define NUM_PCM_FORMATS (sizeof(PCM_Formats) / sizeof(PCM_Formats[0]))
     51#define NUM_OF(a,b)     (((a)+(b)-1)/(b))
    5252
    5353/* flags for fdwDriver */
    54 #define PCM_RESAMPLE    1
     54#define PCM_RESAMPLE    1
    5555
    5656/* data used while converting */
     
    5858    /* conversion routine, depending if rate conversion is required */
    5959    union {
    60     void (*cvtKeepRate)(const unsigned char*, int, unsigned char*);
    61     void (*cvtChangeRate)(struct tagAcmPcmData*, const unsigned char*,
    62                   LPDWORD, unsigned char*, LPDWORD);
     60        void (*cvtKeepRate)(const unsigned char*, int, unsigned char*);
     61        void (*cvtChangeRate)(struct tagAcmPcmData*, const unsigned char*,
     62                              LPDWORD, unsigned char*, LPDWORD);
    6363    } cvt;
    6464    /* the following fields are used only with rate conversion) */
    65     DWORD   srcPos;     /* position in source stream */
    66     double  dstPos;     /* position in destination stream */
    67     double  dstIncr;    /* value to increment dst stream when src stream
    68                    is incremented by 1 */
     65    DWORD       srcPos;         /* position in source stream */
     66    double      dstPos;         /* position in destination stream */
     67    double      dstIncr;        /* value to increment dst stream when src stream
     68                                   is incremented by 1 */
    6969    /* last source stream value read */
    7070    union {
    71     unsigned char   b;  /*  8 bit value */
    72     short       s;  /* 16 bit value */
     71        unsigned char   b;      /*  8 bit value */
     72        short           s;      /* 16 bit value */
    7373    } last[2]; /* two channels max (stereo) */
    7474} AcmPcmData;
     
    7777 * also helps given a unique index to each of the supported formats
    7878 */
    79 static  struct {
    80     int     nChannels;
    81     int     nBits;
    82     int     rate;
     79static  struct {
     80    int         nChannels;
     81    int         nBits;
     82    int         rate;
    8383} PCM_Formats[] = {
    8484    {1,  8,  8000}, {2,  8,  8000}, {1, 16,  8000}, {2, 16,  8000},
     
    9191 *           PCM_GetFormatIndex
    9292 */
    93 static  DWORD   PCM_GetFormatIndex(LPWAVEFORMATEX wfx)
     93static  DWORD   PCM_GetFormatIndex(LPWAVEFORMATEX wfx)
    9494{
    9595    int i;
    96 
     96   
    9797    for (i = 0; i < NUM_PCM_FORMATS; i++) {
    98     if (wfx->nChannels == PCM_Formats[i].nChannels &&
    99         wfx->nSamplesPerSec == PCM_Formats[i].rate &&
    100         wfx->wBitsPerSample == PCM_Formats[i].nBits)
    101         return i;
     98        if (wfx->nChannels == PCM_Formats[i].nChannels &&
     99            wfx->nSamplesPerSec == PCM_Formats[i].rate &&
     100            wfx->wBitsPerSample == PCM_Formats[i].nBits)
     101            return i;
    102102    }
    103103    return 0xFFFFFFFF;
     
    107107 *
    108108 * parameters:
    109  *  + 8 bit unsigned vs 16 bit signed
    110  *  + mono vs stereo (1 or 2 channels)
    111  *  + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo shall work
    112  *    in all cases)
     109 *      + 8 bit unsigned vs 16 bit signed
     110 *      + mono vs stereo (1 or 2 channels)
     111 *      + sampling rate (8.0, 11.025, 22.05, 44.1 kHz are defined, but algo shall work
     112 *        in all cases)
    113113 *
    114114 * mono => stereo: copy the same sample on Left & Right channels
    115115 * stereo =) mono: use the average value of samples from Left & Right channels
    116116 * resampling; we lookup for each destination sample the two source adjacent samples
    117  *  were src <= dst < src+1 (dst is increased by a fractional value which is
    118  *  equivalent to the increment by one on src); then we use a linear
    119  *  interpolation between src and src+1
     117 *      were src <= dst < src+1 (dst is increased by a fractional value which is
     118 *      equivalent to the increment by one on src); then we use a linear
     119 *      interpolation between src and src+1
    120120 */
    121121
     
    125125 * Converts a 8 bit sample to a 16 bit one
    126126 */
    127 static inline short C816(unsigned char b)
     127static inline short C816(unsigned char b) 
    128128{
    129129    return (short)(b ^ 0x80) * 256;
     
    135135 * Converts a 16 bit sample to a 8 bit one (data loss !!)
    136136 */
    137 static inline unsigned char C168(short s)
     137static inline unsigned char C168(short s) 
    138138{
    139139    return HIBYTE(s) ^ (unsigned char)0x80;
     
    164164 *           M16
    165165 *
    166  * Convert the (l,r) 16 bit stereo sample into a 16 bit mono
     166 * Convert the (l,r) 16 bit stereo sample into a 16 bit mono 
    167167 * (takes the mid-point of the two values)
    168168 */
     
    175175 *           M8
    176176 *
    177  * Convert the (l,r) 8 bit stereo sample into a 8 bit mono
     177 * Convert the (l,r) 8 bit stereo sample into a 8 bit mono 
    178178 * (takes the mid-point of the two values)
    179179 */
     
    194194 */
    195195
    196 static  void cvtMM88K(const unsigned char* src, int ns, unsigned char* dst)
     196static  void cvtMM88K(const unsigned char* src, int ns, unsigned char* dst)
    197197{
    198198    memcpy(dst, src, ns);
    199199}
    200200
    201 static  void cvtSS88K(const unsigned char* src, int ns, unsigned char* dst)
     201static  void cvtSS88K(const unsigned char* src, int ns, unsigned char* dst)
    202202{
    203203    memcpy(dst, src, ns * 2);
    204204}
    205205
    206 static  void cvtMM1616K(const unsigned char* src, int ns, unsigned char* dst)
     206static  void cvtMM1616K(const unsigned char* src, int ns, unsigned char* dst)
    207207{
    208208    memcpy(dst, src, ns * 2);
    209209}
    210210
    211 static  void cvtSS1616K(const unsigned char* src, int ns, unsigned char* dst)
     211static  void cvtSS1616K(const unsigned char* src, int ns, unsigned char* dst)
    212212{
    213213    memcpy(dst, src, ns * 4);
    214214}
    215215
    216 static  void cvtMS88K(const unsigned char* src, int ns, unsigned char* dst)
    217 {
    218     while (ns--) {
    219     *dst++ = *src;
    220     *dst++ = *src++;
    221     }
    222 }
    223 
    224 static  void cvtMS816K(const unsigned char* src, int ns, unsigned char* dst)
    225 {
    226     short   v;
    227 
    228     while (ns--) {
    229     v = C816(*src++);
    230     W16(dst, v);        dst += 2;
    231     W16(dst, v);        dst += 2;
    232     }
    233 }
    234 
    235 static  void cvtMS168K(const unsigned char* src, int ns, unsigned char* dst)
     216static  void cvtMS88K(const unsigned char* src, int ns, unsigned char* dst)
     217{
     218    while (ns--) {
     219        *dst++ = *src;
     220        *dst++ = *src++;
     221    }
     222}
     223
     224static  void cvtMS816K(const unsigned char* src, int ns, unsigned char* dst)
     225{
     226    short       v;
     227   
     228    while (ns--) {
     229        v = C816(*src++);
     230        W16(dst, v);            dst += 2;
     231        W16(dst, v);            dst += 2;
     232    }
     233}
     234
     235static  void cvtMS168K(const unsigned char* src, int ns, unsigned char* dst)
    236236{
    237237    unsigned char v;
    238 
    239     while (ns--) {
    240     v = C168(R16(src));     src += 2;
    241     *dst++ = v;
    242     *dst++ = v;
    243     }
    244 }
    245 
    246 static  void cvtMS1616K(const unsigned char* src, int ns, unsigned char* dst)
    247 {
    248     short   v;
    249 
    250     while (ns--) {
    251     v = R16(src);       src += 2;
    252     W16(dst, v);        dst += 2;
    253     W16(dst, v);        dst += 2;
    254     }
    255 }
    256 
    257 static  void cvtSM88K(const unsigned char* src, int ns, unsigned char* dst)
    258 {
    259     while (ns--) {
    260     *dst++ = M8(src[0], src[1]);
    261     src += 2;
    262     }
    263 }
    264 
    265 static  void cvtSM816K(const unsigned char* src, int ns, unsigned char* dst)
    266 {
    267     short   v;
    268 
    269     while (ns--) {
    270     v = M16(C816(src[0]), C816(src[1]));
    271     src += 2;
    272     W16(dst, v);        dst += 2;
    273     }
    274 }
    275 
    276 static  void cvtSM168K(const unsigned char* src, int ns, unsigned char* dst)
    277 {
    278     while (ns--) {
    279     *dst++ = C168(M16(R16(src), R16(src + 2)));
    280     src += 4;
    281     }
    282 }
    283 
    284 static  void cvtSM1616K(const unsigned char* src, int ns, unsigned char* dst)
    285 {
    286     while (ns--) {
    287     W16(dst, M16(R16(src),R16(src+2))); dst += 2;
    288     src += 4;
    289     }
    290 }
    291 
    292 static  void cvtMM816K(const unsigned char* src, int ns, unsigned char* dst)
    293 {
    294     while (ns--) {
    295     W16(dst, C816(*src++));     dst += 2;
    296     }
    297 }
    298 
    299 static  void cvtSS816K(const unsigned char* src, int ns, unsigned char* dst)
    300 {
    301     while (ns--) {
    302     W16(dst, C816(*src++)); dst += 2;
    303     W16(dst, C816(*src++)); dst += 2;
    304     }
    305 }
    306 
    307 static  void cvtMM168K(const unsigned char* src, int ns, unsigned char* dst)
    308 {
    309     while (ns--) {
    310     *dst++ = C168(R16(src));    src += 2;
    311     }
    312 }
    313 
    314 static  void cvtSS168K(const unsigned char* src, int ns, unsigned char* dst)
    315 {
    316     while (ns--) {
    317     *dst++ = C168(R16(src));    src += 2;
    318     *dst++ = C168(R16(src));    src += 2;
    319     }
    320 }
    321 
    322 static  void (*PCM_ConvertKeepRate[16])(const unsigned char*, int, unsigned char*) = {
    323     cvtSS88K,   cvtSM88K,   cvtMS88K,   cvtMM88K,
    324     cvtSS816K,  cvtSM816K,  cvtMS816K,  cvtMM816K,
    325     cvtSS168K,  cvtSM168K,  cvtMS168K,  cvtMM168K,
     238   
     239    while (ns--) {
     240        v = C168(R16(src));             src += 2;
     241        *dst++ = v;
     242        *dst++ = v;
     243    }
     244}
     245
     246static  void cvtMS1616K(const unsigned char* src, int ns, unsigned char* dst)
     247{
     248    short       v;
     249
     250    while (ns--) {
     251        v = R16(src);           src += 2;
     252        W16(dst, v);            dst += 2;
     253        W16(dst, v);            dst += 2;
     254    }
     255}
     256
     257static  void cvtSM88K(const unsigned char* src, int ns, unsigned char* dst)
     258{
     259    while (ns--) {
     260        *dst++ = M8(src[0], src[1]);
     261        src += 2;
     262    }
     263}
     264
     265static  void cvtSM816K(const unsigned char* src, int ns, unsigned char* dst)
     266{
     267    short       v;
     268   
     269    while (ns--) {
     270        v = M16(C816(src[0]), C816(src[1]));
     271        src += 2;
     272        W16(dst, v);            dst += 2;
     273    }
     274}
     275
     276static  void cvtSM168K(const unsigned char* src, int ns, unsigned char* dst)
     277{
     278    while (ns--) {
     279        *dst++ = C168(M16(R16(src), R16(src + 2)));
     280        src += 4;
     281    }
     282}
     283
     284static  void cvtSM1616K(const unsigned char* src, int ns, unsigned char* dst)
     285{
     286    while (ns--) {
     287        W16(dst, M16(R16(src),R16(src+2)));     dst += 2;
     288        src += 4;
     289    }
     290}
     291
     292static  void cvtMM816K(const unsigned char* src, int ns, unsigned char* dst)
     293{
     294    while (ns--) {
     295        W16(dst, C816(*src++));         dst += 2;
     296    }
     297}
     298
     299static  void cvtSS816K(const unsigned char* src, int ns, unsigned char* dst)
     300{
     301    while (ns--) {
     302        W16(dst, C816(*src++)); dst += 2;
     303        W16(dst, C816(*src++)); dst += 2;
     304    }
     305}
     306
     307static  void cvtMM168K(const unsigned char* src, int ns, unsigned char* dst)
     308{
     309    while (ns--) {
     310        *dst++ = C168(R16(src));        src += 2;
     311    }
     312}
     313
     314static  void cvtSS168K(const unsigned char* src, int ns, unsigned char* dst)
     315{
     316    while (ns--) {
     317        *dst++ = C168(R16(src));        src += 2;
     318        *dst++ = C168(R16(src));        src += 2;
     319    }
     320}
     321
     322static  void (*PCM_ConvertKeepRate[16])(const unsigned char*, int, unsigned char*) = {
     323    cvtSS88K,   cvtSM88K,   cvtMS88K,   cvtMM88K,
     324    cvtSS816K,  cvtSM816K,  cvtMS816K,  cvtMM816K,
     325    cvtSS168K,  cvtSM168K,  cvtMS168K,  cvtMM168K,
    326326    cvtSS1616K, cvtSM1616K, cvtMS1616K, cvtMM1616K,
    327327};
     
    333333 * Linear interpolation is used
    334334 */
    335 static  inline double   I(double v1, double v2, double r)
     335static  inline double   I(double v1, double v2, double r)
    336336{
    337337    if (0.0 >= r || r > 1.0) FIXME("r!! %f\n", r);
     
    339339}
    340340
    341 static  void cvtSS88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    342               unsigned char* dst, LPDWORD ndst)
    343 {
    344     double          r;
    345 
    346     while (*nsrc != 0 && *ndst != 0) {
    347     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    348         if (*nsrc == 0) return;
    349         apd->last[0].b = *src++;
    350         apd->last[1].b = *src++;
    351         apd->srcPos++;
    352         (*nsrc)--;
    353     }
    354     /* now do the interpolation */
    355     *dst++ = I(apd->last[0].b, src[0], r);
    356     *dst++ = I(apd->last[1].b, src[1], r);
    357     apd->dstPos += apd->dstIncr;
    358     (*ndst)--;
     341static  void cvtSS88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     342                      unsigned char* dst, LPDWORD ndst)
     343{
     344    double              r;
     345
     346    while (*nsrc != 0 && *ndst != 0) {
     347        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     348            if (*nsrc == 0) return;
     349            apd->last[0].b = *src++;
     350            apd->last[1].b = *src++;
     351            apd->srcPos++;
     352            (*nsrc)--;
     353        }
     354        /* now do the interpolation */
     355        *dst++ = I(apd->last[0].b, src[0], r);
     356        *dst++ = I(apd->last[1].b, src[1], r);
     357        apd->dstPos += apd->dstIncr;
     358        (*ndst)--;
    359359    }
    360360}
     
    368368 *
    369369 */
    370 static  void cvtSM88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    371               unsigned char* dst, LPDWORD ndst)
    372 {
    373     double      r;
    374 
    375     while (*nsrc != 0 && *ndst != 0) {
    376     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    377         if (*nsrc == 0) return;
    378         apd->last[0].b = *src++;
    379         apd->last[1].b = *src++;
    380         apd->srcPos++;
    381         (*nsrc)--;
    382     }
    383     /* now do the interpolation */
    384     *dst++ = I(M8(apd->last[0].b, apd->last[1].b), M8(src[0], src[1]), r);
    385     apd->dstPos += apd->dstIncr;
    386     (*ndst)--;
    387     }
    388 }
    389 
    390 static  void cvtMS88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    391               unsigned char* dst, LPDWORD ndst)
    392 {
    393     double  r;
    394 
    395     while (*nsrc != 0 && *ndst != 0) {
    396     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    397         if (*nsrc == 0) return;
    398         apd->last[0].b = *src++;
    399         apd->srcPos++;
    400         (*nsrc)--;
    401     }
    402     /* now do the interpolation */
    403     dst[0] = dst[1] = I(apd->last[0].b, src[0], r);
    404     dst += 2;
    405     apd->dstPos += apd->dstIncr;
    406     (*ndst)--;
    407     }
    408 }
    409 
    410 static  void cvtMM88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    411               unsigned char* dst, LPDWORD ndst)
    412 {
    413     double      r;
    414 
    415     while (*nsrc != 0 && *ndst != 0) {
    416     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    417         if (*nsrc == 0) return;
    418         apd->last[0].b = *src++;
    419         apd->srcPos++;
    420         (*nsrc)--;
    421     }
    422     /* now do the interpolation */
    423     *dst++ = I(apd->last[0].b, src[0], r);
    424     apd->dstPos += apd->dstIncr;
    425     (*ndst)--;
    426     }
    427 }
    428 
    429 static  void cvtSS816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    430                unsigned char* dst, LPDWORD ndst)
    431 {
    432     double  r;
    433 
    434     while (*nsrc != 0 && *ndst != 0) {
    435     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    436         if (*nsrc == 0) return;
    437         apd->last[0].b = *src++;
    438         apd->last[1].b = *src++;
    439         apd->srcPos++;
    440         (*nsrc)--;
    441     }
    442     /* now do the interpolation */
    443     W16(dst, I(C816(apd->last[0].b), C816(src[0]), r)); dst += 2;
    444     W16(dst, I(C816(apd->last[1].b), C816(src[1]), r)); dst += 2;
    445     apd->dstPos += apd->dstIncr;
    446     (*ndst)--;
    447     }
    448 }
    449 
    450 static  void cvtSM816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    451             unsigned char* dst, LPDWORD ndst)
    452 {
    453     double      r;
    454 
    455     while (*nsrc != 0 && *ndst != 0) {
    456     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    457         if (*nsrc == 0) return;
    458         apd->last[0].b = *src++;
    459         apd->last[1].b = *src++;
    460         apd->srcPos++;
    461         (*nsrc)--;
    462     }
    463     /* now do the interpolation */
    464     W16(dst, I(M16(C816(apd->last[0].b), C816(apd->last[1].b)),
    465             M16(C816(src[0]), C816(src[1])), r));
    466     dst += 2;
    467     apd->dstPos += apd->dstIncr;
    468     (*ndst)--;
    469     }
    470 }
    471 
    472 static  void cvtMS816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    473             unsigned char* dst, LPDWORD ndst)
    474 {
    475     double      r;
    476     short   v;
    477 
    478     while (*nsrc != 0 && *ndst != 0) {
    479     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    480         if (*nsrc == 0) return;
    481         apd->last[0].b = *src++;
    482         apd->srcPos++;
    483         (*nsrc)--;
    484     }
    485     /* now do the interpolation */
    486     v = I(C816(apd->last[0].b), C816(src[0]), r);
    487     W16(dst, v);        dst += 2;
    488     W16(dst, v);        dst += 2;
    489     apd->dstPos += apd->dstIncr;
    490     (*ndst)--;
    491     }
    492 }
    493 
    494 static  void cvtMM816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    495             unsigned char* dst, LPDWORD ndst)
    496 {
    497     double      r;
    498 
    499     while (*nsrc != 0 && *ndst != 0) {
    500     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    501         if (*nsrc == 0) return;
    502         apd->last[0].b = *src++;
    503         apd->srcPos++;
    504         (*nsrc)--;
    505     }
    506     /* now do the interpolation */
    507     W16(dst, I(C816(apd->last[0].b), C816(src[0]), r));
    508     dst += 2;
    509     apd->dstPos += apd->dstIncr;
    510     (*ndst)--;
    511     }
    512 }
    513 
    514 static  void cvtSS168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    515             unsigned char* dst, LPDWORD ndst)
    516 {
    517     double      r;
    518 
    519     while (*nsrc != 0 && *ndst != 0) {
    520     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    521         if (*nsrc == 0) return;
    522         apd->last[0].s = R16(src);  src += 2;
    523         apd->last[1].s = R16(src);  src += 2;
    524         apd->srcPos++;
    525         (*nsrc)--;
    526     }
    527     /* now do the interpolation */
    528     *dst++ = C168(I(apd->last[0].s, R16(src)  , r));
    529     *dst++ = C168(I(apd->last[1].s, R16(src+2), r));
    530     apd->dstPos += apd->dstIncr;
    531     (*ndst)--;
    532     }
    533 }
    534 
    535 static  void cvtSM168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    536             unsigned char* dst, LPDWORD ndst)
    537 {
    538     double      r;
    539 
    540     while (*nsrc != 0 && *ndst != 0) {
    541     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    542         if (*nsrc == 0) return;
    543         apd->last[0].s = R16(src);  src += 2;
    544         apd->last[1].s = R16(src);  src += 2;
    545         apd->srcPos++;
    546         (*nsrc)--;
    547     }
    548     /* now do the interpolation */
    549     *dst++ = C168(I(M16(apd->last[0].s, apd->last[1].s),
    550             M16(R16(src), R16(src + 2)), r));
    551     apd->dstPos += apd->dstIncr;
    552     (*ndst)--;
    553     }
    554 }
    555 
    556 
    557 static  void cvtMS168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    558             unsigned char* dst, LPDWORD ndst)
    559 {
    560     double      r;
    561 
    562     while (*nsrc != 0 && *ndst != 0) {
    563     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    564         if (*nsrc == 0) return;
    565         apd->last[0].s = R16(src);  src += 2;
    566         apd->srcPos++;
    567         (*nsrc)--;
    568     }
    569     /* now do the interpolation */
    570     dst[0] = dst[1] = C168(I(apd->last[0].s, R16(src), r)); dst += 2;
    571     apd->dstPos += apd->dstIncr;
    572     (*ndst)--;
    573     }
    574 }
    575 
    576 
    577 static  void cvtMM168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    578             unsigned char* dst, LPDWORD ndst)
    579 {
    580     double      r;
    581 
    582     while (*nsrc != 0 && *ndst != 0) {
    583     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    584         if (*nsrc == 0) return;
    585         apd->last[0].s = R16(src);  src += 2;
    586         apd->srcPos++;
    587         (*nsrc)--;
    588     }
    589     /* now do the interpolation */
    590     *dst++ = C168(I(apd->last[0].s, R16(src), r));
    591     apd->dstPos += apd->dstIncr;
    592     (*ndst)--;
    593     }
    594 }
    595 
    596 static  void cvtSS1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    597             unsigned char* dst, LPDWORD ndst)
    598 {
    599     double      r;
    600 
    601     while (*nsrc != 0 && *ndst != 0) {
    602     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    603         if (*nsrc == 0) return;
    604         apd->last[0].s = R16(src);  src += 2;
    605         apd->last[1].s = R16(src);  src += 2;
    606         apd->srcPos++;
    607         (*nsrc)--;
    608     }
    609     /* now do the interpolation */
    610     W16(dst, I(apd->last[0].s, R16(src)  , r)); dst += 2;
    611     W16(dst, I(apd->last[1].s, R16(src+2), r)); dst += 2;
    612     apd->dstPos += apd->dstIncr;
    613     (*ndst)--;
    614     }
    615 }
    616 
    617 static  void cvtSM1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    618             unsigned char* dst, LPDWORD ndst)
    619 {
    620     double      r;
    621 
    622     while (*nsrc != 0 && *ndst != 0) {
    623     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    624         if (*nsrc == 0) return;
    625         apd->last[0].s = R16(src);  src += 2;
    626         apd->last[1].s = R16(src);  src += 2;
    627         apd->srcPos++;
    628         (*nsrc)--;
    629     }
    630     /* now do the interpolation */
    631     W16(dst, I(M16(apd->last[0].s, apd->last[1].s),
    632            M16(R16(src), R16(src+2)), r));
    633     dst += 2;
    634     apd->dstPos += apd->dstIncr;
    635     (*ndst)--;
    636     }
    637 }
    638 
    639 static  void cvtMS1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    640             unsigned char* dst, LPDWORD ndst)
    641 {
    642     double      r;
    643     short   v;
    644 
    645     while (*nsrc != 0 && *ndst != 0) {
    646     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    647         if (*nsrc == 0) return;
    648         apd->last[0].s = R16(src);  src += 2;
    649         apd->srcPos++;
    650         (*nsrc)--;
    651     }
    652     /* now do the interpolation */
    653     v = I(apd->last[0].s, R16(src), r);
    654     W16(dst, v);        dst += 2;
    655     W16(dst, v);        dst += 2;
    656     apd->dstPos += apd->dstIncr;
    657     (*ndst)--;
    658     }
    659 }
    660 
    661 static  void cvtMM1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
    662             unsigned char* dst, LPDWORD ndst)
    663 {
    664     double      r;
    665 
    666     while (*nsrc != 0 && *ndst != 0) {
    667     while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
    668         if (*nsrc == 0) return;
    669         apd->last[0].s = R16(src);  src += 2;
    670         apd->srcPos++;
    671         (*nsrc)--;
    672     }
    673     /* now do the interpolation */
    674     W16(dst, I(apd->last[0].s, R16(src), r));   dst += 2;
    675     apd->dstPos += apd->dstIncr;
    676     (*ndst)--;
    677     }
    678 }
    679 
    680 static  void (*PCM_ConvertChangeRate[16])(AcmPcmData* apd,
    681                       const unsigned char* src, LPDWORD nsrc,
    682                       unsigned char* dst, LPDWORD ndst) = {
     370static  void cvtSM88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     371                      unsigned char* dst, LPDWORD ndst)
     372{
     373    double      r;
     374
     375    while (*nsrc != 0 && *ndst != 0) {
     376        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     377            if (*nsrc == 0) return;
     378            apd->last[0].b = *src++;
     379            apd->last[1].b = *src++;
     380            apd->srcPos++;
     381            (*nsrc)--;
     382        }
     383        /* now do the interpolation */
     384        *dst++ = I(M8(apd->last[0].b, apd->last[1].b), M8(src[0], src[1]), r);
     385        apd->dstPos += apd->dstIncr;
     386        (*ndst)--;
     387    }
     388}
     389
     390static  void cvtMS88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     391                      unsigned char* dst, LPDWORD ndst)
     392{
     393    double      r;
     394
     395    while (*nsrc != 0 && *ndst != 0) {
     396        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     397            if (*nsrc == 0) return;
     398            apd->last[0].b = *src++;
     399            apd->srcPos++;
     400            (*nsrc)--;
     401        }
     402        /* now do the interpolation */
     403        dst[0] = dst[1] = I(apd->last[0].b, src[0], r);
     404        dst += 2;
     405        apd->dstPos += apd->dstIncr;
     406        (*ndst)--;
     407    }
     408}
     409
     410static  void cvtMM88C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     411                      unsigned char* dst, LPDWORD ndst)
     412{
     413    double      r;
     414
     415    while (*nsrc != 0 && *ndst != 0) {
     416        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     417            if (*nsrc == 0) return;
     418            apd->last[0].b = *src++;
     419            apd->srcPos++;
     420            (*nsrc)--;
     421        }
     422        /* now do the interpolation */
     423        *dst++ = I(apd->last[0].b, src[0], r);
     424        apd->dstPos += apd->dstIncr;
     425        (*ndst)--;
     426    }
     427}
     428
     429static  void cvtSS816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     430                       unsigned char* dst, LPDWORD ndst)
     431{
     432    double      r;
     433       
     434    while (*nsrc != 0 && *ndst != 0) {
     435        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     436            if (*nsrc == 0) return;
     437            apd->last[0].b = *src++;
     438            apd->last[1].b = *src++;
     439            apd->srcPos++;
     440            (*nsrc)--;
     441        }
     442        /* now do the interpolation */
     443        W16(dst, I(C816(apd->last[0].b), C816(src[0]), r));     dst += 2;
     444        W16(dst, I(C816(apd->last[1].b), C816(src[1]), r));     dst += 2;
     445        apd->dstPos += apd->dstIncr;
     446        (*ndst)--;
     447    }
     448}
     449
     450static  void cvtSM816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     451                        unsigned char* dst, LPDWORD ndst)
     452{
     453    double      r;
     454
     455    while (*nsrc != 0 && *ndst != 0) {
     456        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     457            if (*nsrc == 0) return;
     458            apd->last[0].b = *src++;
     459            apd->last[1].b = *src++;
     460            apd->srcPos++;
     461            (*nsrc)--;
     462        }
     463        /* now do the interpolation */
     464        W16(dst, I(M16(C816(apd->last[0].b), C816(apd->last[1].b)),
     465                    M16(C816(src[0]), C816(src[1])), r));
     466        dst += 2;
     467        apd->dstPos += apd->dstIncr;
     468        (*ndst)--;
     469    }
     470}
     471
     472static  void cvtMS816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     473                        unsigned char* dst, LPDWORD ndst)
     474{
     475    double      r;
     476    short       v;
     477
     478    while (*nsrc != 0 && *ndst != 0) {
     479        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     480            if (*nsrc == 0) return;
     481            apd->last[0].b = *src++;
     482            apd->srcPos++;
     483            (*nsrc)--;
     484        }
     485        /* now do the interpolation */
     486        v = I(C816(apd->last[0].b), C816(src[0]), r);
     487        W16(dst, v);            dst += 2;
     488        W16(dst, v);            dst += 2;
     489        apd->dstPos += apd->dstIncr;
     490        (*ndst)--;
     491    }
     492}
     493
     494static  void cvtMM816C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     495                        unsigned char* dst, LPDWORD ndst)
     496{
     497    double      r;
     498
     499    while (*nsrc != 0 && *ndst != 0) {
     500        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     501            if (*nsrc == 0) return;
     502            apd->last[0].b = *src++;
     503            apd->srcPos++;
     504            (*nsrc)--;
     505        }
     506        /* now do the interpolation */
     507        W16(dst, I(C816(apd->last[0].b), C816(src[0]), r));
     508        dst += 2;
     509        apd->dstPos += apd->dstIncr;
     510        (*ndst)--;
     511    }
     512}
     513
     514static  void cvtSS168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     515                        unsigned char* dst, LPDWORD ndst)
     516{
     517    double      r;
     518
     519    while (*nsrc != 0 && *ndst != 0) {
     520        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     521            if (*nsrc == 0) return;
     522            apd->last[0].s = R16(src);  src += 2;
     523            apd->last[1].s = R16(src);  src += 2;
     524            apd->srcPos++;
     525            (*nsrc)--;
     526        }
     527        /* now do the interpolation */
     528        *dst++ = C168(I(apd->last[0].s, R16(src)  , r));
     529        *dst++ = C168(I(apd->last[1].s, R16(src+2), r));
     530        apd->dstPos += apd->dstIncr;
     531        (*ndst)--;
     532    }
     533}
     534
     535static  void cvtSM168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     536                        unsigned char* dst, LPDWORD ndst)
     537{
     538    double      r;
     539
     540    while (*nsrc != 0 && *ndst != 0) {
     541        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     542            if (*nsrc == 0) return;
     543            apd->last[0].s = R16(src);  src += 2;
     544            apd->last[1].s = R16(src);  src += 2;
     545            apd->srcPos++;
     546            (*nsrc)--;
     547        }
     548        /* now do the interpolation */
     549        *dst++ = C168(I(M16(apd->last[0].s, apd->last[1].s),
     550                        M16(R16(src), R16(src + 2)), r));
     551        apd->dstPos += apd->dstIncr;
     552        (*ndst)--;
     553    }
     554}
     555
     556
     557static  void cvtMS168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     558                        unsigned char* dst, LPDWORD ndst)
     559{
     560    double      r;
     561
     562    while (*nsrc != 0 && *ndst != 0) {
     563        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     564            if (*nsrc == 0) return;
     565            apd->last[0].s = R16(src);  src += 2;
     566            apd->srcPos++;
     567            (*nsrc)--;
     568        }
     569        /* now do the interpolation */
     570        dst[0] = dst[1] = C168(I(apd->last[0].s, R16(src), r)); dst += 2;
     571        apd->dstPos += apd->dstIncr;
     572        (*ndst)--;
     573    }
     574}
     575
     576
     577static  void cvtMM168C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     578                        unsigned char* dst, LPDWORD ndst)
     579{
     580    double      r;
     581
     582    while (*nsrc != 0 && *ndst != 0) {
     583        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     584            if (*nsrc == 0) return;
     585            apd->last[0].s = R16(src);  src += 2;
     586            apd->srcPos++;
     587            (*nsrc)--;
     588        }
     589        /* now do the interpolation */
     590        *dst++ = C168(I(apd->last[0].s, R16(src), r));
     591        apd->dstPos += apd->dstIncr;
     592        (*ndst)--;
     593    }
     594}
     595
     596static  void cvtSS1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     597                        unsigned char* dst, LPDWORD ndst)
     598{
     599    double      r;
     600
     601    while (*nsrc != 0 && *ndst != 0) {
     602        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     603            if (*nsrc == 0) return;
     604            apd->last[0].s = R16(src);  src += 2;
     605            apd->last[1].s = R16(src);  src += 2;
     606            apd->srcPos++;
     607            (*nsrc)--;
     608        }
     609        /* now do the interpolation */
     610        W16(dst, I(apd->last[0].s, R16(src)  , r));     dst += 2;
     611        W16(dst, I(apd->last[1].s, R16(src+2), r));     dst += 2;
     612        apd->dstPos += apd->dstIncr;
     613        (*ndst)--;
     614    }
     615}
     616
     617static  void cvtSM1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     618                        unsigned char* dst, LPDWORD ndst)
     619{
     620    double      r;
     621
     622    while (*nsrc != 0 && *ndst != 0) {
     623        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     624            if (*nsrc == 0) return;
     625            apd->last[0].s = R16(src);  src += 2;
     626            apd->last[1].s = R16(src);  src += 2;
     627            apd->srcPos++;
     628            (*nsrc)--;
     629        }
     630        /* now do the interpolation */
     631        W16(dst, I(M16(apd->last[0].s, apd->last[1].s),
     632                   M16(R16(src), R16(src+2)), r));
     633        dst += 2;
     634        apd->dstPos += apd->dstIncr;
     635        (*ndst)--;
     636    }
     637}
     638
     639static  void cvtMS1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     640                        unsigned char* dst, LPDWORD ndst)
     641{
     642    double      r;
     643    short       v;
     644
     645    while (*nsrc != 0 && *ndst != 0) {
     646        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     647            if (*nsrc == 0) return;
     648            apd->last[0].s = R16(src);  src += 2;
     649            apd->srcPos++;
     650            (*nsrc)--;
     651        }
     652        /* now do the interpolation */
     653        v = I(apd->last[0].s, R16(src), r);
     654        W16(dst, v);            dst += 2;
     655        W16(dst, v);            dst += 2;
     656        apd->dstPos += apd->dstIncr;
     657        (*ndst)--;
     658    }
     659}
     660
     661static  void cvtMM1616C(AcmPcmData* apd, const unsigned char* src, LPDWORD nsrc,
     662                        unsigned char* dst, LPDWORD ndst)
     663{
     664    double      r;
     665
     666    while (*nsrc != 0 && *ndst != 0) {
     667        while ((r = (double)apd->srcPos - apd->dstPos) <= 0) {
     668            if (*nsrc == 0) return;
     669            apd->last[0].s = R16(src);  src += 2;
     670            apd->srcPos++;
     671            (*nsrc)--;
     672        }
     673        /* now do the interpolation */
     674        W16(dst, I(apd->last[0].s, R16(src), r));       dst += 2;
     675        apd->dstPos += apd->dstIncr;
     676        (*ndst)--;
     677    }
     678}
     679
     680static  void (*PCM_ConvertChangeRate[16])(AcmPcmData* apd,
     681                                          const unsigned char* src, LPDWORD nsrc,
     682                                          unsigned char* dst, LPDWORD ndst) = {
    683683    cvtSS88C,   cvtSM88C,   cvtMS88C,   cvtMM88C,
    684     cvtSS816C,  cvtSM816C,  cvtMS816C,  cvtMM816C,
    685     cvtSS168C,  cvtSM168C,  cvtMS168C,  cvtMM168C,
     684    cvtSS816C,  cvtSM816C,  cvtMS816C,  cvtMM816C,
     685    cvtSS168C,  cvtSM168C,  cvtMS168C,  cvtMM168C,
    686686    cvtSS1616C, cvtSM1616C, cvtMS1616C, cvtMM1616C,
    687687};
     
    691691 *
    692692 */
    693 static  LRESULT PCM_DriverDetails(PACMDRIVERDETAILSW add)
     693static  LRESULT PCM_DriverDetails(PACMDRIVERDETAILSW add)
    694694{
    695695    add->fccType = ACMDRIVERDETAILS_FCCTYPE_AUDIOCODEC;
     
    712712                         add->szLicensing, sizeof(add->szLicensing)/sizeof(WCHAR) );
    713713    add->szFeatures[0] = 0;
    714 
     714   
    715715    return MMSYSERR_NOERROR;
    716716}
     
    720720 *
    721721 */
    722 static  LRESULT PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
     722static  LRESULT PCM_FormatTagDetails(PACMFORMATTAGDETAILSW aftd, DWORD dwQuery)
    723723{
    724724    switch (dwQuery) {
    725725    case ACM_FORMATTAGDETAILSF_INDEX:
    726     if (aftd->dwFormatTagIndex != 0) return ACMERR_NOTPOSSIBLE;
    727     break;
    728     case ACM_FORMATTAGDETAILSF_FORMATTAG:
    729     if (aftd->dwFormatTag != WAVE_FORMAT_PCM) return ACMERR_NOTPOSSIBLE;
    730     break;
     726        if (aftd->dwFormatTagIndex != 0) return ACMERR_NOTPOSSIBLE;
     727        break;
     728    case ACM_FORMATTAGDETAILSF_FORMATTAG: 
     729        if (aftd->dwFormatTag != WAVE_FORMAT_PCM) return ACMERR_NOTPOSSIBLE;
     730        break;
    731731    case ACM_FORMATTAGDETAILSF_LARGESTSIZE:
    732     if (aftd->dwFormatTag != WAVE_FORMAT_UNKNOWN &&
    733         aftd->dwFormatTag != WAVE_FORMAT_UNKNOWN)
    734         return ACMERR_NOTPOSSIBLE;
    735     break;
     732        if (aftd->dwFormatTag != WAVE_FORMAT_UNKNOWN &&
     733            aftd->dwFormatTag != WAVE_FORMAT_UNKNOWN)
     734            return ACMERR_NOTPOSSIBLE;
     735        break;
    736736    default:
    737     WARN("Unsupported query %08lx\n", dwQuery);
    738     return MMSYSERR_NOTSUPPORTED;
    739     }
    740 
     737        WARN("Unsupported query %08lx\n", dwQuery);
     738        return MMSYSERR_NOTSUPPORTED;
     739    }
     740   
    741741    aftd->dwFormatTagIndex = 0;
    742742    aftd->dwFormatTag = WAVE_FORMAT_PCM;
     
    745745    aftd->cStandardFormats = NUM_PCM_FORMATS;
    746746    aftd->szFormatTag[0] = 0;
    747 
     747   
    748748    return MMSYSERR_NOERROR;
    749749}
     
    753753 *
    754754 */
    755 static  LRESULT PCM_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
     755static  LRESULT PCM_FormatDetails(PACMFORMATDETAILSW afd, DWORD dwQuery)
    756756{
    757757    switch (dwQuery) {
    758758    case ACM_FORMATDETAILSF_FORMAT:
    759     afd->dwFormatIndex = PCM_GetFormatIndex(afd->pwfx);
    760     if (afd->dwFormatIndex == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
    761     break;
     759        afd->dwFormatIndex = PCM_GetFormatIndex(afd->pwfx);
     760        if (afd->dwFormatIndex == 0xFFFFFFFF) return ACMERR_NOTPOSSIBLE;
     761        break;
    762762    case ACM_FORMATDETAILSF_INDEX:
    763     assert(afd->dwFormatIndex < NUM_PCM_FORMATS);
    764     afd->pwfx->wFormatTag = WAVE_FORMAT_PCM;
    765     afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels;
    766     afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate;
    767     afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits;
    768     /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
    769      * afd->pwfx->cbSize = 0;
    770     */
    771     afd->pwfx->nBlockAlign =
    772         (afd->pwfx->nChannels * afd->pwfx->wBitsPerSample) / 8;
    773     afd->pwfx->nAvgBytesPerSec =
    774         afd->pwfx->nSamplesPerSec * afd->pwfx->nBlockAlign;
    775     break;
     763        assert(afd->dwFormatIndex < NUM_PCM_FORMATS);
     764        afd->pwfx->wFormatTag = WAVE_FORMAT_PCM;
     765        afd->pwfx->nChannels = PCM_Formats[afd->dwFormatIndex].nChannels;
     766        afd->pwfx->nSamplesPerSec = PCM_Formats[afd->dwFormatIndex].rate;
     767        afd->pwfx->wBitsPerSample = PCM_Formats[afd->dwFormatIndex].nBits;
     768        /* native MSACM uses a PCMWAVEFORMAT structure, so cbSize is not accessible
     769         * afd->pwfx->cbSize = 0;
     770        */
     771        afd->pwfx->nBlockAlign =
     772            (afd->pwfx->nChannels * afd->pwfx->wBitsPerSample) / 8;
     773        afd->pwfx->nAvgBytesPerSec =
     774            afd->pwfx->nSamplesPerSec * afd->pwfx->nBlockAlign;
     775        break;
    776776    default:
    777     WARN("Unsupported query %08lx\n", dwQuery);
    778     return MMSYSERR_NOTSUPPORTED;
    779     }
    780 
     777        WARN("Unsupported query %08lx\n", dwQuery);
     778        return MMSYSERR_NOTSUPPORTED;   
     779    }
     780   
    781781    afd->dwFormatTag = WAVE_FORMAT_PCM;
    782782    afd->fdwSupport = ACMDRIVERDETAILS_SUPPORTF_CONVERTER;
    783783    afd->szFormat[0] = 0; /* let MSACM format this for us... */
    784 
     784   
    785785    return MMSYSERR_NOERROR;
    786786}
     
    790790 *
    791791 */
    792 static  LRESULT PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
     792static  LRESULT PCM_FormatSuggest(PACMDRVFORMATSUGGEST adfs)
    793793{
    794794    FIXME("(%p);\n", adfs);
     
    800800 *
    801801 */
    802 static  void    PCM_Reset(AcmPcmData* apd, int srcNumBits)
     802static  void    PCM_Reset(AcmPcmData* apd, int srcNumBits)
    803803{
    804804    apd->srcPos = 0;
     
    806806    /* initialize with neutral value */
    807807    if (srcNumBits == 16) {
    808     apd->last[0].s = 0;
    809     apd->last[1].s = 0;
     808        apd->last[0].s = 0;
     809        apd->last[1].s = 0;
    810810    } else {
    811     apd->last[0].b = (BYTE)0x80;
    812     apd->last[1].b = (BYTE)0x80;
     811        apd->last[0].b = (BYTE)0x80;
     812        apd->last[1].b = (BYTE)0x80;
    813813    }
    814814}
     
    818818 *
    819819 */
    820 static  LRESULT PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
    821 {
    822     AcmPcmData* apd;
    823     int     idx = 0;
     820static  LRESULT PCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi)
     821{
     822    AcmPcmData* apd;
     823    int         idx = 0;
    824824
    825825    assert(!(adsi->fdwOpen & ACM_STREAMOPENF_ASYNC));
    826 
     826   
    827827    if (PCM_GetFormatIndex(adsi->pwfxSrc) == 0xFFFFFFFF ||
    828     PCM_GetFormatIndex(adsi->pwfxDst) == 0xFFFFFFFF)
    829     return ACMERR_NOTPOSSIBLE;
     828        PCM_GetFormatIndex(adsi->pwfxDst) == 0xFFFFFFFF)
     829        return ACMERR_NOTPOSSIBLE;
    830830
    831831    apd = HeapAlloc(GetProcessHeap(), 0, sizeof(AcmPcmData));
     
    834834    adsi->dwDriver = (DWORD)apd;
    835835    adsi->fdwDriver = 0;
    836 
     836   
    837837    if (adsi->pwfxSrc->wBitsPerSample == 16) idx += 8;
    838838    if (adsi->pwfxDst->wBitsPerSample == 16) idx += 4;
     
    841841
    842842    if (adsi->pwfxSrc->nSamplesPerSec == adsi->pwfxDst->nSamplesPerSec) {
    843     apd->cvt.cvtKeepRate = PCM_ConvertKeepRate[idx];
     843        apd->cvt.cvtKeepRate = PCM_ConvertKeepRate[idx];
    844844    } else {
    845     adsi->fdwDriver |= PCM_RESAMPLE;
    846     apd->dstIncr = (double)(adsi->pwfxSrc->nSamplesPerSec) /
    847         (double)(adsi->pwfxDst->nSamplesPerSec);
    848     PCM_Reset(apd, adsi->pwfxSrc->wBitsPerSample);
    849     apd->cvt.cvtChangeRate = PCM_ConvertChangeRate[idx];
     845        adsi->fdwDriver |= PCM_RESAMPLE;
     846        apd->dstIncr = (double)(adsi->pwfxSrc->nSamplesPerSec) /
     847            (double)(adsi->pwfxDst->nSamplesPerSec);
     848        PCM_Reset(apd, adsi->pwfxSrc->wBitsPerSample);
     849        apd->cvt.cvtChangeRate = PCM_ConvertChangeRate[idx];
    850850    }
    851851
     
    857857 *
    858858 */
    859 static  LRESULT PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi)
     859static  LRESULT PCM_StreamClose(PACMDRVSTREAMINSTANCE adsi)
    860860{
    861861    HeapFree(GetProcessHeap(), 0, (void*)adsi->dwDriver);
     
    867867 *
    868868 */
    869 static  inline DWORD    PCM_round(DWORD a, DWORD b, DWORD c)
     869static  inline DWORD    PCM_round(DWORD a, DWORD b, DWORD c)
    870870{
    871871    assert(a && b && c);
     
    878878 *
    879879 */
    880 static  LRESULT PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE adss)
     880static  LRESULT PCM_StreamSize(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMSIZE adss)
    881881{
    882882    switch (adss->fdwSize) {
    883883    case ACM_STREAMSIZEF_DESTINATION:
    884     /* cbDstLength => cbSrcLength */
    885     adss->cbSrcLength = PCM_round(adss->cbDstLength,
    886                       adsi->pwfxSrc->nAvgBytesPerSec,
    887                       adsi->pwfxDst->nAvgBytesPerSec);
    888     break;
     884        /* cbDstLength => cbSrcLength */
     885        adss->cbSrcLength = PCM_round(adss->cbDstLength,
     886                                      adsi->pwfxSrc->nAvgBytesPerSec,
     887                                      adsi->pwfxDst->nAvgBytesPerSec);
     888        break;
    889889    case ACM_STREAMSIZEF_SOURCE:
    890     /* cbSrcLength => cbDstLength */
    891     adss->cbDstLength =  PCM_round(adss->cbSrcLength,
    892                        adsi->pwfxDst->nAvgBytesPerSec,
    893                        adsi->pwfxSrc->nAvgBytesPerSec);
    894     break;
     890        /* cbSrcLength => cbDstLength */
     891        adss->cbDstLength =  PCM_round(adss->cbSrcLength,
     892                                       adsi->pwfxDst->nAvgBytesPerSec,
     893                                       adsi->pwfxSrc->nAvgBytesPerSec);
     894        break;
    895895    default:
    896     WARN("Unsupported query %08lx\n", adss->fdwSize);
    897     return MMSYSERR_NOTSUPPORTED;
     896        WARN("Unsupported query %08lx\n", adss->fdwSize);
     897        return MMSYSERR_NOTSUPPORTED;   
    898898    }
    899899    return MMSYSERR_NOERROR;
     
    906906static LRESULT PCM_StreamConvert(PACMDRVSTREAMINSTANCE adsi, PACMDRVSTREAMHEADER adsh)
    907907{
    908     AcmPcmData* apd = (AcmPcmData*)adsi->dwDriver;
    909     DWORD   nsrc = NUM_OF(adsh->cbSrcLength, adsi->pwfxSrc->nBlockAlign);
    910     DWORD   ndst = NUM_OF(adsh->cbDstLength, adsi->pwfxDst->nBlockAlign);
    911 
    912     if (adsh->fdwConvert &
    913     ~(ACM_STREAMCONVERTF_BLOCKALIGN|
    914       ACM_STREAMCONVERTF_END|
    915       ACM_STREAMCONVERTF_START)) {
    916     FIXME("Unsupported fdwConvert (%08lx), ignoring it\n", adsh->fdwConvert);
     908    AcmPcmData* apd = (AcmPcmData*)adsi->dwDriver;
     909    DWORD       nsrc = NUM_OF(adsh->cbSrcLength, adsi->pwfxSrc->nBlockAlign);
     910    DWORD       ndst = NUM_OF(adsh->cbDstLength, adsi->pwfxDst->nBlockAlign);
     911
     912    if (adsh->fdwConvert & 
     913        ~(ACM_STREAMCONVERTF_BLOCKALIGN|
     914          ACM_STREAMCONVERTF_END|
     915          ACM_STREAMCONVERTF_START)) {
     916        FIXME("Unsupported fdwConvert (%08lx), ignoring it\n", adsh->fdwConvert);
    917917    }
    918918    /* ACM_STREAMCONVERTF_BLOCKALIGN
    919      *  currently all conversions are block aligned, so do nothing for this flag
     919     *  currently all conversions are block aligned, so do nothing for this flag
    920920     * ACM_STREAMCONVERTF_END
    921      *  no pending data, so do nothing for this flag
     921     *  no pending data, so do nothing for this flag
    922922     */
    923     if ((adsh->fdwConvert & ACM_STREAMCONVERTF_START) &&
    924     (adsi->fdwDriver & PCM_RESAMPLE)) {
    925     PCM_Reset(apd, adsi->pwfxSrc->wBitsPerSample);
     923    if ((adsh->fdwConvert & ACM_STREAMCONVERTF_START) && 
     924        (adsi->fdwDriver & PCM_RESAMPLE)) {
     925        PCM_Reset(apd, adsi->pwfxSrc->wBitsPerSample);
    926926    }
    927927
    928928    /* do the job */
    929929    if (adsi->fdwDriver & PCM_RESAMPLE) {
    930     DWORD   nsrc2 = nsrc;
    931     DWORD   ndst2 = ndst;
    932 
    933     apd->cvt.cvtChangeRate(apd, adsh->pbSrc, &nsrc2, adsh->pbDst, &ndst2);
    934     nsrc -= nsrc2;
    935     ndst -= ndst2;
     930        DWORD   nsrc2 = nsrc;
     931        DWORD   ndst2 = ndst;
     932
     933        apd->cvt.cvtChangeRate(apd, adsh->pbSrc, &nsrc2, adsh->pbDst, &ndst2);
     934        nsrc -= nsrc2;
     935        ndst -= ndst2;
    936936    } else {
    937     if (nsrc < ndst) ndst = nsrc; else nsrc = ndst;
    938 
    939     /* nsrc is now equal to ndst */
    940     apd->cvt.cvtKeepRate(adsh->pbSrc, nsrc, adsh->pbDst);
     937        if (nsrc < ndst) ndst = nsrc; else nsrc = ndst;
     938
     939        /* nsrc is now equal to ndst */
     940        apd->cvt.cvtKeepRate(adsh->pbSrc, nsrc, adsh->pbDst);
    941941    }
    942942
     
    948948
    949949/**************************************************************************
    950  *          PCM_DriverProc          [exported]
    951  */
    952 LRESULT CALLBACK    PCM_DriverProc(DWORD dwDevID, HDRVR hDriv, UINT wMsg,
    953                        LPARAM dwParam1, LPARAM dwParam2)
    954 {
    955     TRACE("(%08lx %08lx %u %08lx %08lx);\n",
    956       dwDevID, (DWORD)hDriv, wMsg, dwParam1, dwParam2);
    957 
     950 *                      PCM_DriverProc                  [exported]
     951 */
     952LRESULT CALLBACK        PCM_DriverProc(DWORD dwDevID, HDRVR hDriv, UINT wMsg,
     953                                       LPARAM dwParam1, LPARAM dwParam2)
     954{
     955    TRACE("(%08lx %08lx %u %08lx %08lx);\n", 
     956          dwDevID, (DWORD)hDriv, wMsg, dwParam1, dwParam2);
     957   
    958958    switch (wMsg) {
    959     case DRV_LOAD:      return 1;
    960     case DRV_FREE:      return 1;
    961     case DRV_OPEN:      return PCM_drvOpen((LPSTR)dwParam1);
    962     case DRV_CLOSE:     return PCM_drvClose(dwDevID);
    963     case DRV_ENABLE:        return 1;
    964     case DRV_DISABLE:       return 1;
    965     case DRV_QUERYCONFIGURE:    return 1;
    966     case DRV_CONFIGURE:     MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK); return 1;
    967     case DRV_INSTALL:       return DRVCNF_RESTART;
    968     case DRV_REMOVE:        return DRVCNF_RESTART;
    969 
     959    case DRV_LOAD:              return 1;
     960    case DRV_FREE:              return 1;
     961    case DRV_OPEN:              return PCM_drvOpen((LPSTR)dwParam1);
     962    case DRV_CLOSE:             return PCM_drvClose(dwDevID);
     963    case DRV_ENABLE:            return 1;       
     964    case DRV_DISABLE:           return 1;
     965    case DRV_QUERYCONFIGURE:    return 1;
     966    case DRV_CONFIGURE:         MessageBoxA(0, "MSACM PCM filter !", "Wine Driver", MB_OK); return 1;
     967    case DRV_INSTALL:           return DRVCNF_RESTART;
     968    case DRV_REMOVE:            return DRVCNF_RESTART;
     969       
    970970    case ACMDM_DRIVER_NOTIFY:
    971     /* no caching from other ACM drivers is done so far */
    972     return MMSYSERR_NOERROR;
    973 
     971        /* no caching from other ACM drivers is done so far */
     972        return MMSYSERR_NOERROR;
     973       
    974974    case ACMDM_DRIVER_DETAILS:
    975     return PCM_DriverDetails((PACMDRIVERDETAILSW)dwParam1);
    976 
     975        return PCM_DriverDetails((PACMDRIVERDETAILSW)dwParam1);
     976       
    977977    case ACMDM_FORMATTAG_DETAILS:
    978     return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW)dwParam1, dwParam2);
    979 
     978        return PCM_FormatTagDetails((PACMFORMATTAGDETAILSW)dwParam1, dwParam2);
     979       
    980980    case ACMDM_FORMAT_DETAILS:
    981     return PCM_FormatDetails((PACMFORMATDETAILSW)dwParam1, dwParam2);
    982 
     981        return PCM_FormatDetails((PACMFORMATDETAILSW)dwParam1, dwParam2);
     982       
    983983    case ACMDM_FORMAT_SUGGEST:
    984     return PCM_FormatSuggest((PACMDRVFORMATSUGGEST)dwParam1);
    985 
     984        return PCM_FormatSuggest((PACMDRVFORMATSUGGEST)dwParam1);
     985       
    986986    case ACMDM_STREAM_OPEN:
    987     return PCM_StreamOpen((PACMDRVSTREAMINSTANCE)dwParam1);
    988 
     987        return PCM_StreamOpen((PACMDRVSTREAMINSTANCE)dwParam1);
     988       
    989989    case ACMDM_STREAM_CLOSE:
    990     return PCM_StreamClose((PACMDRVSTREAMINSTANCE)dwParam1);
    991 
     990        return PCM_StreamClose((PACMDRVSTREAMINSTANCE)dwParam1);
     991       
    992992    case ACMDM_STREAM_SIZE:
    993     return PCM_StreamSize((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMSIZE)dwParam2);
    994 
     993        return PCM_StreamSize((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMSIZE)dwParam2);
     994       
    995995    case ACMDM_STREAM_CONVERT:
    996     return PCM_StreamConvert((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMHEADER)dwParam2);
    997 
     996        return PCM_StreamConvert((PACMDRVSTREAMINSTANCE)dwParam1, (PACMDRVSTREAMHEADER)dwParam2);
     997       
    998998    case ACMDM_HARDWARE_WAVE_CAPS_INPUT:
    999999    case ACMDM_HARDWARE_WAVE_CAPS_OUTPUT:
    1000     /* this converter is not a hardware driver */
     1000        /* this converter is not a hardware driver */
    10011001    case ACMDM_FILTERTAG_DETAILS:
    10021002    case ACMDM_FILTER_DETAILS:
    1003     /* this converter is not a filter */
     1003        /* this converter is not a filter */
    10041004    case ACMDM_STREAM_RESET:
    1005     /* only needed for asynchronous driver... we aren't, so just say it */
     1005        /* only needed for asynchronous driver... we aren't, so just say it */
    10061006    case ACMDM_STREAM_PREPARE:
    10071007    case ACMDM_STREAM_UNPREPARE:
    1008     /* nothing special to do here... so don't do anything */
    1009     return MMSYSERR_NOTSUPPORTED;
    1010 
     1008        /* nothing special to do here... so don't do anything */
     1009        return MMSYSERR_NOTSUPPORTED;
     1010       
    10111011    default:
    1012     return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
     1012        return DefDriverProc(dwDevID, hDriv, wMsg, dwParam1, dwParam2);
    10131013    }
    10141014    return 0;
Note: See TracChangeset for help on using the changeset viewer.