From a4c78888c03631364eebf6f3769cf11d41bf7673 Mon Sep 17 00:00:00 2001 From: raven02 Date: Thu, 31 Jan 2013 22:16:15 +0800 Subject: [PATCH] Set predict_nr = 0 when predict_nr greater than VAG array length --- Core/HW/SasAudio.cpp | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Core/HW/SasAudio.cpp b/Core/HW/SasAudio.cpp index ea43814e50..e5dc819007 100644 --- a/Core/HW/SasAudio.cpp +++ b/Core/HW/SasAudio.cpp @@ -39,14 +39,17 @@ void VagDecoder::Start(u32 data, int vagSize, bool loopEnabled) { read_ = data; curSample = 28; curBlock_ = -1; - s_1 = 0.0; // per block? - s_2 = 0.0; + s_1 = 0; // per block? + s_2 = 0; } void VagDecoder::DecodeBlock(u8 *&readp) { int predict_nr = *readp++; int shift_factor = predict_nr & 0xf; predict_nr >>= 4; + if (predict_nr >= sizeof(f) / sizeof(s8)) { + predict_nr = 0; + } int flags = *readp++; if (flags == 7) { end_ = true; @@ -55,8 +58,10 @@ void VagDecoder::DecodeBlock(u8 *&readp) { else if (flags == 6) { loopStartBlock_ = curBlock_; } - else if (flags == 3 && loopEnabled_) { - loopAtNextBlock_ = true; + else if (flags == 3) { + if (loopEnabled_) { + loopAtNextBlock_ = true; + } } for (int i = 0; i < 28; i += 2) { int d = *readp++; @@ -66,7 +71,7 @@ void VagDecoder::DecodeBlock(u8 *&readp) { samples[i + 1] = s >> shift_factor; } for (int i = 0; i < 28; i++) { - samples[i] = samples[i] + ((s_1 * f[predict_nr][0] + s_2 * f[predict_nr][1]) >> 6); + samples[i] = (int) (samples[i] + ((s_1 * f[predict_nr][0] + s_2 * f[predict_nr][1]) >> 6)); s_2 = s_1; s_1 = samples[i]; }