From d1c6950ec6e4f045410f6ddd1dd961522f368b62 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Tue, 19 Apr 2022 23:56:17 -0700 Subject: [PATCH] MAD Input: Further gapless decoding and seek fixes This time, a two-fer. First, ensure that file start seeking still skips over the Xing/LAME header packet properly. Then, ensure that decoding the last desired packet of the file does not indicate having decoded more sample data than desired, which may have caused errors when resuming playback position on restart and then smoothly transitioning to the next track. Signed-off-by: Christopher Snowhill --- Plugins/MAD/MADDecoder.m | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/Plugins/MAD/MADDecoder.m b/Plugins/MAD/MADDecoder.m index db5418c6f..69e2e7d48 100644 --- a/Plugins/MAD/MADDecoder.m +++ b/Plugins/MAD/MADDecoder.m @@ -455,7 +455,7 @@ // DLog(@"Revised: %i, %i", startingSample, sampleCount); - _framesDecoded += _synth.pcm.length; + _framesDecoded += sampleCount; if(_outputFrames > 0) { DLog(@"LOSING FRAMES!"); @@ -541,11 +541,13 @@ } } - signed long frameDuration = mad_timer_count(_frame.header.duration, sampleRate); - if((framesToSkip - 1152 * 4) >= frameDuration) { - framesToSkip -= frameDuration; - _framesDecoded += frameDuration; - return 0; + if(!_firstFrame || !_foundXingHeader) { + signed long frameDuration = mad_timer_count(_frame.header.duration, sampleRate); + if((framesToSkip - 1152 * 4) >= frameDuration) { + framesToSkip -= frameDuration; + _framesDecoded += frameDuration; + return 0; + } } // DLog(@"Decoded buffer.");