aboutsummaryrefslogtreecommitdiffstats
path: root/src/pcm_utils.c
diff options
context:
space:
mode:
authorJ. Alexander Treuman <jat@spatialrift.net>2007-05-26 16:39:55 +0000
committerJ. Alexander Treuman <jat@spatialrift.net>2007-05-26 16:39:55 +0000
commit355d18a593c4e79aae733dbd0bb3157b3b5f7014 (patch)
treea7e4227dde83330eed683c37621a6544811ee94f /src/pcm_utils.c
parentb3726bcc93c4d7eb8b2b7a4e37a76b467b5bfd29 (diff)
downloadmpd-355d18a593c4e79aae733dbd0bb3157b3b5f7014.tar.gz
mpd-355d18a593c4e79aae733dbd0bb3157b3b5f7014.tar.xz
mpd-355d18a593c4e79aae733dbd0bb3157b3b5f7014.zip
Make pcm_convertAudioFormat return the buffer size. This is necessary
because lsr may return less than the input buffer size, and the rest of the audio code needs to know the new size. This fixes the clicking that was introduced with recent changes to the lsr code. A huge thanks to remiss for figuring this out. git-svn-id: https://svn.musicpd.org/mpd/trunk@6273 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to 'src/pcm_utils.c')
-rw-r--r--src/pcm_utils.c37
1 files changed, 20 insertions, 17 deletions
diff --git a/src/pcm_utils.c b/src/pcm_utils.c
index 8cc19a9d4..bf4b5e4c8 100644
--- a/src/pcm_utils.c
+++ b/src/pcm_utils.c
@@ -182,10 +182,10 @@ static int pcm_getSampleRateConverter(void)
#endif
#ifdef HAVE_LIBSAMPLERATE
-static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
- char *inBuffer, size_t inSize,
- mpd_uint32 outSampleRate, char *outBuffer,
- size_t outSize, ConvState *convState)
+static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
+ char *inBuffer, size_t inSize,
+ mpd_uint32 outSampleRate, char *outBuffer,
+ size_t outSize, ConvState *convState)
{
static int convalgo = -1;
SRC_DATA *data = &convState->data;
@@ -254,14 +254,14 @@ static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
src_float_to_short_array(data->data_out, (short *)outBuffer,
data->output_frames_gen * channels);
- return 1;
+ return data->output_frames_gen * 2 * channels;
}
#else /* !HAVE_LIBSAMPLERATE */
/* resampling code blatantly ripped from ESD */
-static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
- char *inBuffer, size_t inSize,
- mpd_uint32 outSampleRate, char *outBuffer,
- size_t outSize, ConvState *convState)
+static size_t pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
+ char *inBuffer, size_t inSize,
+ mpd_uint32 outSampleRate, char *outBuffer,
+ size_t outSize, ConvState *convState)
{
mpd_uint32 rd_dat = 0;
mpd_uint32 wr_dat = 0;
@@ -294,7 +294,7 @@ static int pcm_convertSampleRate(mpd_sint8 channels, mpd_uint32 inSampleRate,
break;
}
- return 1;
+ return outSize;
}
#endif /* !HAVE_LIBSAMPLERATE */
@@ -391,9 +391,9 @@ static char *pcm_convertTo16bit(mpd_sint8 bits, char *inBuffer, size_t inSize,
}
/* outFormat bits must be 16 and channels must be 1 or 2! */
-void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
- size_t inSize, AudioFormat * outFormat,
- char *outBuffer, ConvState *convState)
+size_t pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
+ size_t inSize, AudioFormat * outFormat,
+ char *outBuffer, ConvState *convState)
{
char *buf;
size_t len;
@@ -417,12 +417,15 @@ void pcm_convertAudioFormat(AudioFormat * inFormat, char *inBuffer,
assert(outSize >= len);
memcpy(outBuffer, buf, len);
} else {
- if (!pcm_convertSampleRate(outFormat->channels,
- inFormat->sampleRate, buf, len,
- outFormat->sampleRate, outBuffer,
- outSize, convState))
+ len = pcm_convertSampleRate(outFormat->channels,
+ inFormat->sampleRate, buf, len,
+ outFormat->sampleRate, outBuffer,
+ outSize, convState);
+ if (len == 0)
exit(EXIT_FAILURE);
}
+
+ return len;
}
size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize,