Stop ADPCM decoder from running off into space. improves motogp audio.

This commit is contained in:
Henrik Rydgård 2012-12-26 09:07:52 +01:00
parent 1b35964445
commit 27e8e4c6fb
2 changed files with 10 additions and 7 deletions

View File

@ -27,11 +27,11 @@ static const double f[5][2] =
{ 98.0 / 64.0, -55.0 / 64.0 },
{ 122.0 / 64.0, -60.0 / 64.0 } };
void VagDecoder::Start(u8 *data, bool loopEnabled)
{
void VagDecoder::Start(u8 *data, int vagSize, bool loopEnabled) {
loopEnabled_ = loopEnabled;
loopAtNextBlock_ = false;
loopStartBlock_ = 0;
numBlocks_ = vagSize / 16;
end_ = false;
data_ = data;
read_ = data;
@ -41,8 +41,7 @@ void VagDecoder::Start(u8 *data, bool loopEnabled)
s_2 = 0.0;
}
bool VagDecoder::DecodeBlock()
{
bool VagDecoder::DecodeBlock() {
int predict_nr = GetByte();
int shift_factor = predict_nr & 0xf;
predict_nr >>= 4;
@ -71,6 +70,9 @@ bool VagDecoder::DecodeBlock()
}
curSample = 0;
curBlock_++;
if (curBlock_ == numBlocks_) {
end_ = true;
}
return true;
}
@ -307,7 +309,7 @@ void SasVoice::KeyOn() {
switch (type) {
case VOICETYPE_VAG:
if (Memory::IsValidAddress(vagAddr)) {
vag.Start(Memory::GetPointer(vagAddr), loop);
vag.Start(Memory::GetPointer(vagAddr), vagSize, loop);
} else {
ERROR_LOG(SAS, "Invalid VAG address %08x", vagAddr);
return;
@ -330,7 +332,7 @@ void SasVoice::ChangedParams(bool changedVag) {
if (!playing && on) {
playing = true;
if (changedVag)
vag.Start(Memory::GetPointer(vagAddr), loop);
vag.Start(Memory::GetPointer(vagAddr), vagSize, loop);
}
// TODO: restart VAG somehow
}

View File

@ -78,7 +78,7 @@ class VagDecoder
{
public:
VagDecoder() : data_(0), read_(0) {}
void Start(u8 *data, bool loopEnabled);
void Start(u8 *data, int vagSize, bool loopEnabled);
void GetSamples(s16 *outSamples, int numSamples);
@ -97,6 +97,7 @@ private:
u8 *read_;
int curBlock_;
int loopStartBlock_;
int numBlocks_;
// rolling state. start at 0, should probably reset to 0 on loops?
double s_1;