aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/audioOutput.c14
-rw-r--r--src/outputBuffer.c6
-rw-r--r--src/pcm_utils.c37
-rw-r--r--src/pcm_utils.h6
4 files changed, 32 insertions, 31 deletions
diff --git a/src/audioOutput.c b/src/audioOutput.c
index ccc701451..9f6172088 100644
--- a/src/audioOutput.c
+++ b/src/audioOutput.c
@@ -205,14 +205,12 @@ static void convertAudioFormat(AudioOutput * audioOutput, char **chunkArgPtr,
audioOutput->convBufferLen = size;
}
- pcm_convertAudioFormat(&(audioOutput->inAudioFormat),
- *chunkArgPtr,
- *sizeArgPtr,
- &(audioOutput->outAudioFormat),
- audioOutput->convBuffer,
- &audioOutput->convState);
-
- *sizeArgPtr = size;
+ *sizeArgPtr = pcm_convertAudioFormat(&(audioOutput->inAudioFormat),
+ *chunkArgPtr, *sizeArgPtr,
+ &(audioOutput->outAudioFormat),
+ audioOutput->convBuffer,
+ &audioOutput->convState);
+
*chunkArgPtr = audioOutput->convBuffer;
}
diff --git a/src/outputBuffer.c b/src/outputBuffer.c
index d9cbcdc60..c7ff8b479 100644
--- a/src/outputBuffer.c
+++ b/src/outputBuffer.c
@@ -89,9 +89,9 @@ int sendDataToOutputBuffer(OutputBuffer * cb, InputStream * inStream,
convBufferLen = datalen;
}
data = convBuffer;
- pcm_convertAudioFormat(&(dc->audioFormat), dataIn, dataInLen,
- &(cb->audioFormat), data,
- &(cb->convState));
+ datalen = pcm_convertAudioFormat(&(dc->audioFormat), dataIn,
+ dataInLen, &(cb->audioFormat),
+ data, &(cb->convState));
}
if (replayGainInfo && (replayGainState != REPLAYGAIN_OFF))
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,
diff --git a/src/pcm_utils.h b/src/pcm_utils.h
index 800ac27f4..2c6610a75 100644
--- a/src/pcm_utils.h
+++ b/src/pcm_utils.h
@@ -48,9 +48,9 @@ void pcm_volumeChange(char *buffer, int bufferSize, AudioFormat * format,
void pcm_mix(char *buffer1, char *buffer2, size_t bufferSize1,
size_t bufferSize2, AudioFormat * format, float portion1);
-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);
size_t pcm_sizeOfConvBuffer(AudioFormat * inFormat, size_t inSize,
AudioFormat * outFormat);