diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index 0049c2b65c..ed17365368 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -41,14 +41,14 @@ void VagDecoder::Start(u8 *data, int vagSize, bool loopEnabled) { s_2 = 0.0; } -bool VagDecoder::DecodeBlock() { +void VagDecoder::DecodeBlock() { int predict_nr = GetByte(); int shift_factor = predict_nr & 0xf; predict_nr >>= 4; int flags = GetByte(); if (flags == 7) { end_ = true; - return false; + return; } else if (flags == 6) { loopStartBlock_ = curBlock_; @@ -73,7 +73,6 @@ bool VagDecoder::DecodeBlock() { if (curBlock_ == numBlocks_) { end_ = true; } - return true; } void VagDecoder::GetSamples(s16 *outSamples, int numSamples) { @@ -90,6 +89,11 @@ void VagDecoder::GetSamples(s16 *outSamples, int numSamples) { s_2 = 0.0; } DecodeBlock(); + if (end_) { + // Clear the rest of the buffer and return. + memset(&outSamples[i], 0, (numSamples - i) * sizeof(s16)); + return; + } } outSamples[i] = end_ ? 0 : samples[curSample++]; } diff --git a/Core/HW/SasAudio.h b/Core/HW/SasAudio.h index 410a0df2e4..b32ba7d347 100644 --- a/Core/HW/SasAudio.h +++ b/Core/HW/SasAudio.h @@ -74,15 +74,14 @@ enum VoiceType { // It compresses 28 16-bit samples into a block of 16 bytes. // TODO: Get rid of the doubles, making sure it does not impact sound quality. // Doubles are pretty fast on Android devices these days though. -class VagDecoder -{ +class VagDecoder { public: VagDecoder() : data_(0), read_(0) {} void Start(u8 *data, int vagSize, bool loopEnabled); void GetSamples(s16 *outSamples, int numSamples); - bool DecodeBlock(); + void DecodeBlock(); bool End() const { return end_; } u8 GetByte() {