Fix mono MP3 decoding causing choppy output

Fixes issue #5 about choppy audio on low bitrate, mono MP3s.

The number of 32-sample elements to generate per MP3 data frame was
set to 36 as that was what I saw on all my source files.  However, on
mono files only half the number of samples are to be generated and
you'd end up with the synthesizer bands running out of energy and
have periods of 0-samples between proper data.

Now simply check each decoded frame for the proper NSMAX value and
only generate that many.  Tested on force.mp3 in the issue referenced.
This commit is contained in:
Earle F. Philhower, III committed 2017-10-21 21:15:59 -07:00
1 parent 047fef2678
commit 2dac08ef4e
2 files changed
+4 -1

No files matched your search

+3 -1
View File
@@ -28,6 +28,7 @@ AudioGeneratorMP3::AudioGeneratorMP3()
output = NULL;
buffLen = 2048;
buff = NULL;
nsCountMax = 1152/32;
}
AudioGeneratorMP3::~AudioGeneratorMP3()
@@ -106,6 +107,7 @@ bool AudioGeneratorMP3::DecodeNextFrame()
ErrorToFlow(); // Always returns CONTINUE
continue;
}
nsCountMax = MAD_NSBSAMPLES(&frame.header);
return true;
}
inInnerDecode = false;
@@ -116,7 +118,7 @@ bool AudioGeneratorMP3::DecodeNextFrame()
bool AudioGeneratorMP3::GetOneSample(int16_t sample[2])
{
if ( (samplePtr >= synth.pcm.length) && (nsCount >= 1152/32) ) {
if ( (samplePtr >= synth.pcm.length) && (nsCount >= nsCountMax) ) {
if (!DecodeNextFrame()) return false;
samplePtr = 9999;
nsCount = 0;