diff options
author | Max Kellermann <max@duempel.org> | 2008-09-23 23:59:55 +0200 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2008-09-23 23:59:55 +0200 |
commit | eeb30110708b507d254827d0c6a0577ddafa3b74 (patch) | |
tree | 1568124e8159ed311792768833314cf5ebf84ebf /src | |
parent | 19971be307d5c9ca07fd6d8067134368b1e77b32 (diff) | |
download | mpd-eeb30110708b507d254827d0c6a0577ddafa3b74.tar.gz mpd-eeb30110708b507d254827d0c6a0577ddafa3b74.tar.xz mpd-eeb30110708b507d254827d0c6a0577ddafa3b74.zip |
flac: removed generic sample size support
Support for bit rates except 16 bits (and 8 bits on little endian) has
always been broken. Since we added optimized functions for 8, 16,
24/32 bits, we can remove the generic flac_convert() function.
Instead of removing it, convert it to a wrapper function for
flac_convert_*().
Diffstat (limited to 'src')
-rw-r--r-- | src/inputPlugins/_flac_common.c | 58 |
1 files changed, 26 insertions, 32 deletions
diff --git a/src/inputPlugins/_flac_common.c b/src/inputPlugins/_flac_common.c index 19d7f0a26..508a68b8f 100644 --- a/src/inputPlugins/_flac_common.c +++ b/src/inputPlugins/_flac_common.c @@ -267,18 +267,25 @@ static void flac_convert(unsigned char *dest, const FLAC__int32 * const buf[], unsigned int position, unsigned int end) { - unsigned int c_chan, i; - FLAC__uint16 u16; - unsigned char *uc; + switch (bytes_per_sample) { + case 2: + if (num_channels == 2) + flac_convert_stereo16((int16_t*)dest, buf, + position, end); + else + flac_convert_16((int16_t*)dest, num_channels, buf, + position, end); + break; - for (; position < end; ++position) { - for (c_chan = 0; c_chan < num_channels; c_chan++) { - u16 = buf[c_chan][position]; - uc = (unsigned char *)&u16; - for (i = 0; i < bytes_per_sample; i++) { - *dest++ = *uc++; - } - } + case 4: + flac_convert_32((int32_t*)dest, num_channels, buf, + position, end); + break; + + case 1: + flac_convert_8((int8_t*)dest, num_channels, buf, + position, end); + break; } } @@ -295,7 +302,10 @@ flac_common_write(FlacData *data, const FLAC__Frame * frame, const unsigned int max_samples = FLAC_CHUNK_SIZE / bytes_per_channel; unsigned int num_samples; - assert(data->audio_format.bits > 0); + if (bytes_per_sample != 1 && bytes_per_sample != 2 && + bytes_per_sample != 4) + /* exotic unsupported bit rate */ + return FLAC__STREAM_DECODER_WRITE_STATUS_ABORT; for (c_samp = 0; c_samp < frame->header.blocksize; c_samp += num_samples) { @@ -303,26 +313,10 @@ flac_common_write(FlacData *data, const FLAC__Frame * frame, if (num_samples > max_samples) num_samples = max_samples; - if (num_channels == 2 && bytes_per_sample == 2) - flac_convert_stereo16((int16_t*)data->chunk, - buf, c_samp, - c_samp + num_samples); - else if (bytes_per_sample == 2) - flac_convert_16((int16_t*)data->chunk, - num_channels, buf, c_samp, - c_samp + num_samples); - else if (bytes_per_sample == 4) - flac_convert_32((int32_t*)data->chunk, - num_channels, buf, c_samp, - c_samp + num_samples); - else if (bytes_per_sample == 1) - flac_convert_8((int8_t*)data->chunk, - num_channels, buf, c_samp, - c_samp + num_samples); - else - flac_convert(data->chunk, - num_channels, bytes_per_sample, buf, - c_samp, c_samp + num_samples); + flac_convert(data->chunk, + num_channels, bytes_per_sample, buf, + c_samp, c_samp + num_samples); + data->chunk_length = num_samples * bytes_per_channel; if (flacSendChunk(data) < 0) { |