diff options
author | Warren Dukes <warren.dukes@gmail.com> | 2004-05-10 17:15:04 +0000 |
---|---|---|
committer | Warren Dukes <warren.dukes@gmail.com> | 2004-05-10 17:15:04 +0000 |
commit | 5b4a0a1821aa959bfabcf480da1899e750be2b25 (patch) | |
tree | cdf07e771f905b918054e01c01a94ea074d2ae1d /src | |
parent | 4f76ba5a427b27c9d354f2fca762eebacea5ee0c (diff) | |
download | mpd-5b4a0a1821aa959bfabcf480da1899e750be2b25.tar.gz mpd-5b4a0a1821aa959bfabcf480da1899e750be2b25.tar.xz mpd-5b4a0a1821aa959bfabcf480da1899e750be2b25.zip |
fix computation of conversion buffer size
git-svn-id: https://svn.musicpd.org/mpd/trunk@974 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r-- | src/pcm_utils.c | 33 |
1 files changed, 26 insertions, 7 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c index 5465af65e..c1be8d167 100644 --- a/src/pcm_utils.c +++ b/src/pcm_utils.c @@ -255,17 +255,36 @@ size_t pcm_sizeOfOutputBufferForAudioFormatConversion(AudioFormat * inFormat, char * inBuffer, size_t inSize, AudioFormat * outFormat) { const int shift = sizeof(mpd_sint16); - mpd_uint32 nlen = (((inSize >> shift) * - (mpd_uint32)(outFormat->sampleRate)) / - inFormat->sampleRate); + size_t outSize = inSize; - nlen <<= shift; + switch(inFormat->bits) { + case 8: + outSize = outSize << 1; + break; + case 16: + break; + default: + ERROR("only 8 or 16 bits are supported for conversion!\n"); + exit(EXIT_FAILURE); + } + switch(inFormat->channels) { + case 1: + outSize = (outSize >> 1) << 2; + break; + case 2: + break; + default: + ERROR("only 1 or 2 channels are supported for conversion!\n"); + exit(EXIT_FAILURE); + } + + outSize = (((outSize >> shift) * (mpd_uint32)(outFormat->sampleRate)) / + inFormat->sampleRate); - assert(outFormat->bits==16); - assert(outFormat->channels==2); + outSize <<= shift; - return nlen; + return outSize; } /* vim:set shiftwidth=8 tabstop=8 expandtab: */ |