aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:20:13 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:20:13 +0000
commitca1090f93b10c87a5ae3d7234688699569af5b01 (patch)
treef5ceb0319e3393acf606ebd53c1410cdf3f03236 /src
parent0673c9a84dbbca60ed4627154e824dbfdeed269b (diff)
downloadmpd-ca1090f93b10c87a5ae3d7234688699569af5b01.tar.gz
mpd-ca1090f93b10c87a5ae3d7234688699569af5b01.tar.xz
mpd-ca1090f93b10c87a5ae3d7234688699569af5b01.zip
convert blocks until the buffer is full
Move the inner loop which converts samples to flac_convert(). There it is isolated and easier to optimize. This function does not have to worry about buffer boundaries; the caller (i.e. flacWrite()) calculates how much is left and is responsible for flushing. That saves a lot of superfluous range checks within the loop. git-svn-id: https://svn.musicpd.org/mpd/trunk@7327 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/flac_plugin.c66
1 files changed, 43 insertions, 23 deletions
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index 16f63dda0..8e2dbf6be 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -206,6 +206,27 @@ static void flacMetadata(const flac_decoder * dec,
flac_metadata_common_cb(block, (FlacData *) vdata);
}
+static void flac_convert(unsigned char *dest,
+ const FLAC__Frame * frame,
+ unsigned int bytes_per_sample,
+ const FLAC__int32 * const buf[],
+ unsigned int position, unsigned int end)
+{
+ unsigned int c_chan, i;
+ FLAC__uint16 u16;
+ unsigned char *uc;
+
+ for (; position < end; ++position) {
+ for (c_chan = 0; c_chan < frame->header.channels; c_chan++) {
+ u16 = buf[c_chan][position];
+ uc = (unsigned char *)&u16;
+ for (i = 0; i < bytes_per_sample; i++) {
+ *dest++ = *uc++;
+ }
+ }
+ }
+}
+
static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
const FLAC__Frame * frame,
const FLAC__int32 * const buf[],
@@ -213,13 +234,11 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
{
FlacData *data = (FlacData *) vdata;
FLAC__uint32 samples = frame->header.blocksize;
- FLAC__uint16 u16;
- unsigned char *uc;
- unsigned int c_samp, c_chan;
+ unsigned int c_samp;
const unsigned int bytes_per_sample = (data->dc->audioFormat.bits / 8);
const unsigned int bytes_per_channel =
bytes_per_sample * frame->header.channels;
- unsigned int i;
+ unsigned int num_samples, max_samples;
float timeChange;
FLAC__uint64 newPosition = 0;
@@ -239,26 +258,27 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
}
data->position = newPosition;
- for (c_samp = 0; c_samp < frame->header.blocksize; c_samp++) {
- if (data->chunk_length + bytes_per_channel >= FLAC_CHUNK_SIZE) {
- if (flacSendChunk(data) < 0) {
- return
- FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
- }
- data->chunk_length = 0;
- if (data->dc->seek) {
- return
- FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
- }
+ for (c_samp = 0; c_samp < frame->header.blocksize;
+ c_samp += num_samples) {
+ num_samples = frame->header.blocksize - c_samp;
+ max_samples = (FLAC_CHUNK_SIZE - data->chunk_length) /
+ bytes_per_channel;
+ if (num_samples > max_samples)
+ num_samples = max_samples;
+
+ flac_convert(data->chunk + data->chunk_length,
+ frame, bytes_per_sample, buf,
+ c_samp, c_samp + num_samples);
+ data->chunk_length += num_samples;
+
+ if (flacSendChunk(data) < 0) {
+ return
+ FLAC__STREAM_DECODER_WRITE_STATUS_ABORT;
}
-
- for (c_chan = 0; c_chan < frame->header.channels;
- c_chan++) {
- u16 = buf[c_chan][c_samp];
- uc = (unsigned char *)&u16;
- for (i = 0; i < bytes_per_sample; i++) {
- data->chunk[data->chunk_length++] = *(uc++);
- }
+ data->chunk_length = 0;
+ if (data->dc->seek) {
+ return
+ FLAC__STREAM_DECODER_WRITE_STATUS_CONTINUE;
}
}