aboutsummaryrefslogtreecommitdiffstats
path: root/src/inputPlugins/mp3_plugin.c
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2008-08-26 08:27:12 +0200
committerEric Wong <normalperson@yhbt.net>2008-08-30 19:30:23 -0700
commitfdad7dc9df25ba74d8a4c4d9fab7a25e3e0ef3ca (patch)
tree9d4f6cc405d60e250062935f67bcca305dcc9f32 /src/inputPlugins/mp3_plugin.c
parent173b3cc28d40f7555d0f7dbf1cc8823f81762fdb (diff)
downloadmpd-fdad7dc9df25ba74d8a4c4d9fab7a25e3e0ef3ca.tar.gz
mpd-fdad7dc9df25ba74d8a4c4d9fab7a25e3e0ef3ca.tar.xz
mpd-fdad7dc9df25ba74d8a4c4d9fab7a25e3e0ef3ca.zip
mp3: moved dropSamplesAtEnd check out of the loop
Simplifying loops for performance: why check dropSamplesAtEnd in every iteration, when we could modify the loop boundary? The (writable) variable samplesLeft can be eliminated; add a write-once variable pcm_length instead, which is used for the loop condition.
Diffstat (limited to 'src/inputPlugins/mp3_plugin.c')
-rw-r--r--src/inputPlugins/mp3_plugin.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/src/inputPlugins/mp3_plugin.c b/src/inputPlugins/mp3_plugin.c
index 8213dbc0b..9c4925dfa 100644
--- a/src/inputPlugins/mp3_plugin.c
+++ b/src/inputPlugins/mp3_plugin.c
@@ -861,7 +861,7 @@ static void mp3Read_seek(mp3DecodeData * data)
static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
{
- unsigned int samplesLeft;
+ unsigned int pcm_length;
unsigned int i;
int ret;
int skip;
@@ -942,32 +942,23 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
metadata_pipe_send(tag, data->elapsedTime);
}
- samplesLeft = (data->synth).pcm.length;
-
if (!data->decodedFirstFrame) {
- if (data->dropSamplesAtStart >= samplesLeft) {
- i = samplesLeft;
- samplesLeft = 0;
- } else {
- i = data->dropSamplesAtStart;
- samplesLeft -= data->dropSamplesAtStart;
- }
+ i = data->dropSamplesAtStart;
data->decodedFirstFrame = 1;
} else
i = 0;
- for (; i < (data->synth).pcm.length; i++) {
- unsigned int num_samples;
-
- samplesLeft--;
+ pcm_length = data->synth.pcm.length;
+ if (data->dropSamplesAtEnd &&
+ (data->currentFrame == data->maxFrames - data->dropFramesAtEnd)) {
+ if (data->dropSamplesAtEnd >= pcm_length)
+ pcm_length = 0;
+ else
+ pcm_length -= data->dropSamplesAtEnd;
+ }
- if (data->dropSamplesAtEnd &&
- (data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) &&
- (samplesLeft < data->dropSamplesAtEnd)) {
- /* stop decoding, effectively dropping
- * all remaining samples */
- return DECODE_BREAK;
- }
+ for (; i < pcm_length; i++) {
+ unsigned int num_samples;
num_samples = dither_buffer((mpd_sint16 *) data->outputPtr,
&data->synth, &data->dither,
@@ -996,6 +987,13 @@ static int mp3Read(mp3DecodeData * data, ReplayGainInfo ** replayGainInfo)
}
}
+ if (data->dropSamplesAtEnd &&
+ (data->currentFrame ==
+ (data->maxFrames - data->dropFramesAtEnd)))
+ /* stop decoding, effectively dropping
+ * all remaining samples */
+ return DECODE_BREAK;
+
if (dc_seek()) {
if (data->inStream->seekable)
mp3Read_seek(data);