From d14e75cdc7507c041f4fcb5a588107ddc3fb7c53 Mon Sep 17 00:00:00 2001 From: Johannes Schickel Date: Sun, 11 Dec 2011 06:19:54 +0100 Subject: CINE: Make findNote behave like in the original. This also reverts 42fd6975447b99f4a66ec411a62def2b3b49c5d6, which was wrong, since I misread the assembly. Ooops. --- engines/cine/sound.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) (limited to 'engines/cine/sound.cpp') diff --git a/engines/cine/sound.cpp b/engines/cine/sound.cpp index 35c379baee..0328466e76 100644 --- a/engines/cine/sound.cpp +++ b/engines/cine/sound.cpp @@ -249,16 +249,30 @@ private: void PCSoundDriver::findNote(int freq, int *note, int *oct) const { - *note = _noteTableCount - 1; - // It might seem odd that we start with 1 here, but the original has the - // same behavior. - for (int i = 1; i < _noteTableCount; ++i) { - if (_noteTable[i] <= freq) { + if (freq > 0x777) + *oct = 0; + else if (freq > 0x3BB) + *oct = 1; + else if (freq > 0x1DD) + *oct = 2; + else if (freq > 0x0EE) + *oct = 3; + else if (freq > 0x077) + *oct = 4; + else if (freq > 0x03B) + *oct = 5; + else if (freq > 0x01D) + *oct = 6; + else + *oct = 7; + + *note = 11; + for (int i = 0; i < 12; ++i) { + if (_noteTable[*oct * 12 + i] <= freq) { *note = i; break; } } - *oct = *note / 12; } void PCSoundDriver::resetChannel(int channel) { @@ -475,12 +489,11 @@ void AdLibSoundDriverINS::setChannelFrequency(int channel, int frequency) { if (ins->mode == 0 || ins->channel == 6) { int freq, note, oct; findNote(frequency, ¬e, &oct); - if (channel == 6) { - note %= 12; - } + if (channel == 6) + oct = 0; freq = _freqTable[note % 12]; OPLWriteReg(_opl, 0xA0 | channel, freq); - freq = ((note / 12) << 2) | ((freq & 0x300) >> 8); + freq = (oct << 2) | ((freq & 0x300) >> 8); if (ins->mode == 0) { freq |= 0x20; } @@ -543,14 +556,16 @@ void AdLibSoundDriverADL::setChannelFrequency(int channel, int frequency) { findNote(frequency, ¬e, &oct); if (ins->amDepth) { note = ins->amDepth; + oct = note / 12; } if (note < 0) { note = 0; + oct = 0; } freq = _freqTable[note % 12]; OPLWriteReg(_opl, 0xA0 | channel, freq); - freq = ((note / 12) << 2) | ((freq & 0x300) >> 8); + freq = (oct << 2) | ((freq & 0x300) >> 8); if (ins->mode == 0) { freq |= 0x20; } -- cgit v1.2.3