aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-05-23 11:04:04 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-05-23 11:04:04 +0000
commit495e1b6cf9f4ef037c7462c8a2973744688b8665 (patch)
treefbe781365cf189f88221533a7e7ace7a2efbda14
parentfbb3a94f17836aa33de78fd73db0f5d54464379d (diff)
downloadmpd-495e1b6cf9f4ef037c7462c8a2973744688b8665.tar.gz
mpd-495e1b6cf9f4ef037c7462c8a2973744688b8665.tar.xz
mpd-495e1b6cf9f4ef037c7462c8a2973744688b8665.zip
Tidying up pcm_utils.c a bit more.
git-svn-id: https://svn.musicpd.org/mpd/trunk@6230 09075e82-0dd4-0310-85a5-a0d7c8717e4f
-rw-r--r--src/pcm_utils.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 4cf5f2a7d..b3c6689ae 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -275,7 +275,7 @@ static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
}
#endif /* !HAVE_LIBSAMPLERATE */
-static char *pcm_convertChannels(mpd_sint8 inChannels, char *inBuffer,
+static char *pcm_convertChannels(mpd_sint8 channels, char *inBuffer,
size_t inSize, size_t *outSize)
{
static char *buf;
@@ -285,7 +285,7 @@ static char *pcm_convertChannels(mpd_sint8 inChannels, char *inBuffer,
mpd_sint16 *out;
int inSamples, i;
- switch (inChannels) {
+ switch (channels) {
/* convert from 1 -> 2 channels */
case 1:
*outSize = (inSize >> 1) << 2;
@@ -329,7 +329,7 @@ static char *pcm_convertChannels(mpd_sint8 inChannels, char *inBuffer,
return outBuffer;
}
-static char *pcm_convertTo16bit(mpd_sint8 inBits, char *inBuffer, size_t inSize,
+static char *pcm_convertTo16bit(mpd_sint8 bits, char *inBuffer, size_t inSize,
size_t *outSize)
{
static char *buf;
@@ -339,7 +339,7 @@ static char *pcm_convertTo16bit(mpd_sint8 inBits, char *inBuffer, size_t inSize,
mpd_sint16 *out;
int i;
- switch (inBits) {
+ switch (bits) {
case 8:
*outSize = inSize << 1;
if (*outSize > len) {
@@ -405,12 +405,14 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize,
AudioFormat * outFormat)
{
- const int shift = sizeof(mpd_sint16) * outFormat->channels;
+ const double ratio = (double)outFormat->sampleRate /
+ (double)inFormat->sampleRate;
+ const int shift = 2 * outFormat->channels;
size_t outSize = inSize;
switch (inFormat->bits) {
case 8:
- outSize = outSize << 1;
+ outSize <<= 1;
break;
case 16:
break;
@@ -431,8 +433,7 @@ size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize,
}
outSize /= shift;
- outSize = floor(0.5 + (double)outSize *
- ((double)outFormat->sampleRate / (double)inFormat->sampleRate));
+ outSize = floor(0.5 + (double)outSize * ratio);
outSize *= shift;
return outSize;