aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:20:30 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:20:30 +0000
commit00fbd7bb4b64d6078b79c1e35d5b1d3bb325a405 (patch)
tree29c1994070ed34076dd4db29f071927f2716d7ae /src/inputPlugins
parent3db2b987183d0c325825ce70f0f1c343d22839d4 (diff)
downloadmpd-00fbd7bb4b64d6078b79c1e35d5b1d3bb325a405.tar.gz
mpd-00fbd7bb4b64d6078b79c1e35d5b1d3bb325a405.tar.xz
mpd-00fbd7bb4b64d6078b79c1e35d5b1d3bb325a405.zip
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
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/flac_plugin.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 8f4c96884..b52704959 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -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) {