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.
This commit is contained in:
parent
e4c6c01903
commit
e99536e8eb
@ -839,7 +839,7 @@ static int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data,
|
|||||||
static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
|
static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
|
||||||
ReplayGainInfo ** replayGainInfo)
|
ReplayGainInfo ** replayGainInfo)
|
||||||
{
|
{
|
||||||
unsigned int samplesLeft;
|
unsigned int pcm_length;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
int ret;
|
int ret;
|
||||||
int skip;
|
int skip;
|
||||||
@ -917,33 +917,24 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
|
|||||||
freeMpdTag(tag);
|
freeMpdTag(tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
samplesLeft = (data->synth).pcm.length;
|
|
||||||
|
|
||||||
if (!data->decodedFirstFrame) {
|
if (!data->decodedFirstFrame) {
|
||||||
if (data->dropSamplesAtStart >= samplesLeft) {
|
i = data->dropSamplesAtStart;
|
||||||
i = samplesLeft;
|
|
||||||
samplesLeft = 0;
|
|
||||||
} else {
|
|
||||||
i = data->dropSamplesAtStart;
|
|
||||||
samplesLeft -= data->dropSamplesAtStart;
|
|
||||||
}
|
|
||||||
data->decodedFirstFrame = 1;
|
data->decodedFirstFrame = 1;
|
||||||
} else
|
} else
|
||||||
i = 0;
|
i = 0;
|
||||||
|
|
||||||
for (; i < (data->synth).pcm.length; i++) {
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (; i < pcm_length; i++) {
|
||||||
unsigned int num_samples;
|
unsigned int num_samples;
|
||||||
|
|
||||||
samplesLeft--;
|
|
||||||
|
|
||||||
if (data->dropSamplesAtEnd &&
|
|
||||||
(data->currentFrame == (data->maxFrames - data->dropFramesAtEnd)) &&
|
|
||||||
(samplesLeft < data->dropSamplesAtEnd)) {
|
|
||||||
/* stop decoding, effectively dropping
|
|
||||||
* all remaining samples */
|
|
||||||
return DECODE_BREAK;
|
|
||||||
}
|
|
||||||
|
|
||||||
num_samples = dither_buffer((mpd_sint16 *) data->outputPtr,
|
num_samples = dither_buffer((mpd_sint16 *) data->outputPtr,
|
||||||
&data->synth, &data->dither,
|
&data->synth, &data->dither,
|
||||||
i, i + 1,
|
i, i + 1,
|
||||||
@ -968,6 +959,12 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (data->dropSamplesAtEnd &&
|
||||||
|
(data->currentFrame == data->maxFrames - data->dropFramesAtEnd))
|
||||||
|
/* stop decoding, effectively dropping
|
||||||
|
* all remaining samples */
|
||||||
|
return DECODE_BREAK;
|
||||||
|
|
||||||
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
|
if (decoder_get_command(decoder) == DECODE_COMMAND_SEEK &&
|
||||||
data->inStream->seekable) {
|
data->inStream->seekable) {
|
||||||
unsigned long j = 0;
|
unsigned long j = 0;
|
||||||
|
Loading…
Reference in New Issue
Block a user