Commit 2a960853 authored by Max Kellermann's avatar Max Kellermann

mp3: moved num_samples calculation out of the loop

The previous patch removed all loop specific dependencies from the num_samples formula; we can now calculate it before entering the loop.
parent 3f55b5a1
...@@ -830,7 +830,7 @@ static int openMp3FromInputStream(InputStream * inStream, mp3DecodeData * data, ...@@ -830,7 +830,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 pcm_length; unsigned int pcm_length, max_samples;
unsigned int i; unsigned int i;
int ret; int ret;
int skip; int skip;
...@@ -922,12 +922,14 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder, ...@@ -922,12 +922,14 @@ static int mp3Read(mp3DecodeData * data, struct decoder *decoder,
pcm_length -= data->dropSamplesAtEnd; pcm_length -= data->dropSamplesAtEnd;
} }
max_samples = sizeof(data->outputBuffer) /
(2 * MAD_NCHANNELS(&(data->frame).header));
while (i < pcm_length) { while (i < pcm_length) {
enum decoder_command cmd; enum decoder_command cmd;
unsigned int num_samples = sizeof(data->outputBuffer) / unsigned int num_samples = pcm_length - i;
(2 * MAD_NCHANNELS(&(data->frame).header)); if (num_samples > max_samples)
if (num_samples > pcm_length - i) num_samples = max_samples;
num_samples = pcm_length - i;
i += num_samples; i += num_samples;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment