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
This commit is contained in:
J. Alexander Treuman 2007-05-26 16:39:55 +00:00
parent b3726bcc93
commit 355d18a593
4 changed files with 31 additions and 30 deletions

View File

@ -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 = pcm_convertAudioFormat(&(audioOutput->inAudioFormat),
*chunkArgPtr, *sizeArgPtr,
&(audioOutput->outAudioFormat),
audioOutput->convBuffer,
&audioOutput->convState);
*sizeArgPtr = size;
*chunkArgPtr = audioOutput->convBuffer;
}

View File

@ -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))

View File

@ -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,

View File

@ -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);