aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-04-12 04:20:06 +0000
committerEric Wong <normalperson@yhbt.net>2008-04-12 04:20:06 +0000
commit0673c9a84dbbca60ed4627154e824dbfdeed269b (patch)
tree43edfa46f7d651143d6d6e826b539c91491c8862
parent51e9044098bf44a5d4578ce405468454be7a4c8e (diff)
downloadmpd-0673c9a84dbbca60ed4627154e824dbfdeed269b.tar.gz
mpd-0673c9a84dbbca60ed4627154e824dbfdeed269b.tar.xz
mpd-0673c9a84dbbca60ed4627154e824dbfdeed269b.zip
calculate bytes_per_channel, check for buffer flush once
Check for flushing the chunk buffer only once per sample, before iterating over channels and bytes. This saves another 5% CPU cycles. git-svn-id: https://svn.musicpd.org/mpd/trunk@7326 09075e82-0dd4-0310-85a5-a0d7c8717e4f
Diffstat (limited to '')
-rw-r--r--src/inputPlugins/flac_plugin.c25
1 files changed, 14 insertions, 11 deletions
diff --git a/src/inputPlugins/flac_plugin.c b/src/inputPlugins/flac_plugin.c
index fa6304980..16f63dda0 100644
--- a/src/inputPlugins/flac_plugin.c
+++ b/src/inputPlugins/flac_plugin.c
@@ -217,6 +217,8 @@ static FLAC__StreamDecoderWriteStatus flacWrite(const flac_decoder *dec,
unsigned char *uc;
unsigned int c_samp, c_chan;
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;
float timeChange;
FLAC__uint64 newPosition = 0;
@@ -238,22 +240,23 @@ 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_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++) {
- if (data->chunk_length >= 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;
- }
- }
data->chunk[data->chunk_length++] = *(uc++);
}
}