From 4b4c0f9bda1af38297253aeb2aeab28a5cc7ca0e Mon Sep 17 00:00:00 2001 From: "Unknown W. Brackets" Date: Sun, 28 Apr 2019 11:57:59 -0700 Subject: [PATCH] Mp3: Always output data in decode, except at end. Turns out this doesn't return 0 until the end, even if there's no data available to decode. It just writes zeros in that case. --- Core/HW/SimpleAudioDec.cpp | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/Core/HW/SimpleAudioDec.cpp b/Core/HW/SimpleAudioDec.cpp index 472011f224..29124871da 100644 --- a/Core/HW/SimpleAudioDec.cpp +++ b/Core/HW/SimpleAudioDec.cpp @@ -332,7 +332,6 @@ u32 AuCtx::AuDecode(u32 pcmAddr) { } auto outbuf = Memory::GetPointer(PCMBuf); - memset(outbuf, 0, PCMBufSize); // important! empty outbuf to avoid noise int outpcmbufsize = 0; // Decode a single frame in sourcebuff and output into PCMBuf. @@ -342,7 +341,7 @@ u32 AuCtx::AuDecode(u32 pcmAddr) { decoder->Decode(&sourcebuff[nextSync], (int)sourcebuff.size() - nextSync, outbuf, &outpcmbufsize); if (outpcmbufsize == 0) { - // no output pcm, we are at the end of the stream + // Nothing was output, hopefully we're at the end of the stream. AuBufAvailable = 0; sourcebuff.clear(); } else { @@ -359,7 +358,8 @@ u32 AuCtx::AuDecode(u32 pcmAddr) { } } - if (sourcebuff.empty() && LoopNum != 0) { + bool end = readPos - AuBufAvailable >= (int64_t)endPos; + if (end && LoopNum != 0) { // When looping, start the sum back off at zero and reset readPos to the start. SumDecodedSamples = 0; readPos = startPos; @@ -367,6 +367,14 @@ u32 AuCtx::AuDecode(u32 pcmAddr) { LoopNum--; } + if (outpcmbufsize == 0 && !end) { + outpcmbufsize = MaxOutputSample * 4; + memset(outbuf, 0, PCMBufSize); + } else if ((u32)outpcmbufsize < PCMBufSize) { + // TODO: We probably should use a rolling buffer instead. + memset(outbuf + outpcmbufsize, 0, PCMBufSize - outpcmbufsize); + } + Memory::Write_U32(PCMBuf, pcmAddr); return outpcmbufsize; }