diff --git a/src/AudioGeneratorMP3.cpp b/src/AudioGeneratorMP3.cpp index 0636940..bca1795 100644 --- a/src/AudioGeneratorMP3.cpp +++ b/src/AudioGeneratorMP3.cpp @@ -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; diff --git a/src/AudioGeneratorMP3.h b/src/AudioGeneratorMP3.h index be32f46..f7ff464 100644 --- a/src/AudioGeneratorMP3.h +++ b/src/AudioGeneratorMP3.h @@ -49,6 +49,7 @@ class AudioGeneratorMP3 : AudioGenerator struct mad_synth synth; int samplePtr; int nsCount; + int nsCountMax; bool inInnerDecode; // The internal helpers