special optimized case for 16bit stereo

Not having to loop for every sample byte (depending on a variable
unknown at compile time) saves a lot of CPU cycles.  We could consider
reimplementing this function with liboil...

git-svn-id: https://svn.musicpd.org/mpd/trunk@7330 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
Max Kellermann 2008-04-12 04:20:30 +00:00 committed by Eric Wong
parent 3db2b98718
commit 00fbd7bb4b

View File

@ -206,6 +206,18 @@ static void flacMetadata(const flac_decoder * dec,
flac_metadata_common_cb(block, (FlacData *) vdata);
}
static void flac_convert_stereo16(unsigned char *dest,
const FLAC__int32 * const buf[],
unsigned int position, unsigned int end)
{
for (; position < end; ++position) {
*(uint16_t*)dest = buf[0][position];
dest += 2;
*(uint16_t*)dest = buf[1][position];
dest += 2;
}
}
static void flac_convert(unsigned char *dest,
unsigned int num_channels,
unsigned int bytes_per_sample,
@ -266,9 +278,14 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
if (num_samples > max_samples)
num_samples = max_samples;
flac_convert(data->chunk + data->chunk_length,
num_channels, bytes_per_sample, buf,
c_samp, c_samp + num_samples);
if (bytes_per_sample == 2)
flac_convert_stereo16(data->chunk + data->chunk_length,
buf, c_samp,
c_samp + num_samples);
else
flac_convert(data->chunk + data->chunk_length,
num_channels, bytes_per_sample, buf,
c_samp, c_samp + num_samples);
data->chunk_length = num_samples;
if (flacSendChunk(data) < 0) {