From 39185814b1e51348d50458632f44e0756fba8426 Mon Sep 17 00:00:00 2001 From: Andrew Eikum Date: Mon, 4 Nov 2013 10:05:58 -0600 Subject: [PATCH] msadp32: Also convert to 8-bit PCM. --- dlls/msadp32.acm/msadp32.c | 92 +++++++++++++++++++++++++------------- 1 file changed, 62 insertions(+), 30 deletions(-) diff --git a/dlls/msadp32.acm/msadp32.c b/dlls/msadp32.acm/msadp32.c index d76a2f86e35..59f71b51d4e 100644 --- a/dlls/msadp32.acm/msadp32.c +++ b/dlls/msadp32.acm/msadp32.c @@ -223,6 +223,11 @@ static inline void process_nibble(unsigned nibble, int* idelta, if (*idelta < 16) *idelta = 16; } +static inline unsigned char C168(short s) +{ + return HIBYTE(s) ^ (unsigned char)0x80; +} + static void cvtSSms16K(const ACMDRVSTREAMINSTANCE *adsi, const unsigned char* src, LPDWORD nsrc, unsigned char* dst, LPDWORD ndst) @@ -234,10 +239,10 @@ static void cvtSSms16K(const ACMDRVSTREAMINSTANCE *adsi, int nsamp; int nsamp_blk = ((ADPCMWAVEFORMAT*)adsi->pwfxSrc)->wSamplesPerBlock; DWORD nblock = min(*nsrc / adsi->pwfxSrc->nBlockAlign, - *ndst / (nsamp_blk * 2 * 2)); + *ndst / (nsamp_blk * adsi->pwfxDst->nBlockAlign)); *nsrc = nblock * adsi->pwfxSrc->nBlockAlign; - *ndst = nblock * nsamp_blk * 2 * 2; + *ndst = nblock * nsamp_blk * adsi->pwfxDst->nBlockAlign; nsamp_blk -= 2; /* see below for samples from block head */ for (; nblock > 0; nblock--) @@ -256,18 +261,34 @@ static void cvtSSms16K(const ACMDRVSTREAMINSTANCE *adsi, sample2L = R16(src); src += 2; sample2R = R16(src); src += 2; - /* store samples from block head */ - W16(dst, sample2L); dst += 2; - W16(dst, sample2R); dst += 2; - W16(dst, sample1L); dst += 2; - W16(dst, sample1R); dst += 2; + if(adsi->pwfxDst->wBitsPerSample == 8){ + /* store samples from block head */ + *dst = C168(sample2L); ++dst; + *dst = C168(sample2R); ++dst; + *dst = C168(sample1L); ++dst; + *dst = C168(sample1R); ++dst; - for (nsamp = nsamp_blk; nsamp > 0; nsamp--) - { - process_nibble(*src >> 4, &ideltaL, &sample1L, &sample2L, &coeffL); - W16(dst, sample1L); dst += 2; - process_nibble(*src++ & 0x0F, &ideltaR, &sample1R, &sample2R, &coeffR); - W16(dst, sample1R); dst += 2; + for (nsamp = nsamp_blk; nsamp > 0; nsamp--) + { + process_nibble(*src >> 4, &ideltaL, &sample1L, &sample2L, &coeffL); + *dst = C168(sample1L); ++dst; + process_nibble(*src++ & 0x0F, &ideltaR, &sample1R, &sample2R, &coeffR); + *dst = C168(sample1R); ++dst; + } + }else if(adsi->pwfxDst->wBitsPerSample == 16){ + /* store samples from block head */ + W16(dst, sample2L); dst += 2; + W16(dst, sample2R); dst += 2; + W16(dst, sample1L); dst += 2; + W16(dst, sample1R); dst += 2; + + for (nsamp = nsamp_blk; nsamp > 0; nsamp--) + { + process_nibble(*src >> 4, &ideltaL, &sample1L, &sample2L, &coeffL); + W16(dst, sample1L); dst += 2; + process_nibble(*src++ & 0x0F, &ideltaR, &sample1R, &sample2R, &coeffR); + W16(dst, sample1R); dst += 2; + } } src = in_src + adsi->pwfxSrc->nBlockAlign; } @@ -283,10 +304,10 @@ static void cvtMMms16K(const ACMDRVSTREAMINSTANCE *adsi, int nsamp; int nsamp_blk = ((ADPCMWAVEFORMAT*)adsi->pwfxSrc)->wSamplesPerBlock; DWORD nblock = min(*nsrc / adsi->pwfxSrc->nBlockAlign, - *ndst / (nsamp_blk * 2)); + *ndst / (nsamp_blk * adsi->pwfxDst->nBlockAlign)); *nsrc = nblock * adsi->pwfxSrc->nBlockAlign; - *ndst = nblock * nsamp_blk * 2; + *ndst = nblock * nsamp_blk * adsi->pwfxDst->nBlockAlign; nsamp_blk -= 2; /* see below for samples from block head */ for (; nblock > 0; nblock--) @@ -301,16 +322,30 @@ static void cvtMMms16K(const ACMDRVSTREAMINSTANCE *adsi, sample2 = R16(src); src += 2; /* store samples from block head */ - W16(dst, sample2); dst += 2; - W16(dst, sample1); dst += 2; + if(adsi->pwfxDst->wBitsPerSample == 8){ + *dst = C168(sample2); ++dst; + *dst = C168(sample1); ++dst; - for (nsamp = nsamp_blk; nsamp > 0; nsamp -= 2) - { - process_nibble(*src >> 4, &idelta, &sample1, &sample2, &coeff); - W16(dst, sample1); dst += 2; - process_nibble(*src++ & 0x0F, &idelta, &sample1, &sample2, &coeff); - W16(dst, sample1); dst += 2; + for (nsamp = nsamp_blk; nsamp > 0; nsamp -= 2) + { + process_nibble(*src >> 4, &idelta, &sample1, &sample2, &coeff); + *dst = C168(sample1); ++dst; + process_nibble(*src++ & 0x0F, &idelta, &sample1, &sample2, &coeff); + *dst = C168(sample1); ++dst; + } + }else if(adsi->pwfxDst->wBitsPerSample == 16){ + W16(dst, sample2); dst += 2; + W16(dst, sample1); dst += 2; + + for (nsamp = nsamp_blk; nsamp > 0; nsamp -= 2) + { + process_nibble(*src >> 4, &idelta, &sample1, &sample2, &coeff); + W16(dst, sample1); dst += 2; + process_nibble(*src++ & 0x0F, &idelta, &sample1, &sample2, &coeff); + W16(dst, sample1); dst += 2; + } } + src = in_src + adsi->pwfxSrc->nBlockAlign; } } @@ -553,12 +588,9 @@ static LRESULT ADPCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi) else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_ADPCM && adsi->pwfxDst->wFormatTag == WAVE_FORMAT_PCM) { - /* resampling or mono <=> stereo not available - * ADPCM algo only define 16 bit per sample output - */ + /* resampling or mono <=> stereo not available */ if (adsi->pwfxSrc->nSamplesPerSec != adsi->pwfxDst->nSamplesPerSec || - adsi->pwfxSrc->nChannels != adsi->pwfxDst->nChannels || - adsi->pwfxDst->wBitsPerSample != 16) + adsi->pwfxSrc->nChannels != adsi->pwfxDst->nChannels) goto theEnd; #if 0 @@ -577,9 +609,9 @@ static LRESULT ADPCM_StreamOpen(PACMDRVSTREAMINSTANCE adsi) #endif /* adpcm decoding... */ - if (adsi->pwfxDst->wBitsPerSample == 16 && adsi->pwfxDst->nChannels == 2) + if (adsi->pwfxDst->nChannels == 2) aad->convert = cvtSSms16K; - if (adsi->pwfxDst->wBitsPerSample == 16 && adsi->pwfxDst->nChannels == 1) + else if (adsi->pwfxDst->nChannels == 1) aad->convert = cvtMMms16K; } else if (adsi->pwfxSrc->wFormatTag == WAVE_FORMAT_PCM &&