Skip to content

Commit

Permalink
SCUMM: Fix Sam & Max OPL3 pitch bend
Browse files Browse the repository at this point in the history
The pitch bend in Sam & Max was exaggerated when using the OPL3 driver. The
OPL3 functionality was apparently implemented by examining just the original
driver code and not the MIDI processing code in the interpreter. The pitch bend
values sent to the driver are not standard MIDI pitch bend values, but have
been processed by the interpreter, so the driver logic cannot be directly
applied to the pitch bend values from the MIDI data.

This commit fixes the pitch bend calculations to produce the same results as
the original interpreter. It also restores the pitch bend range functionality.
This was disabled for OPL3, probably because it is implemented in the
interpreter instead of the driver. It is used in several Sam & Max MIDI tracks.
  • Loading branch information
NMIError committed Oct 30, 2021
1 parent 8cfc81f commit 952de88
Showing 1 changed file with 21 additions and 19 deletions.
40 changes: 21 additions & 19 deletions audio/adlib.cpp
Expand Up @@ -1095,7 +1095,7 @@ void AdLibPart::pitchBend(int16 bend) {
(_pitchBend * _pitchBendFactor >> 6) + _detuneEff);
#ifdef ENABLE_OPL3
} else {
_owner->adlibNoteOn(voice->_channel, voice->_note, _pitchBend >> 1);
_owner->adlibNoteOn(voice->_channel, voice->_note, (_pitchBend * _pitchBendFactor) >> 5);
}
#endif
}
Expand Down Expand Up @@ -1196,19 +1196,20 @@ void AdLibPart::panPosition(byte value) {
}

void AdLibPart::pitchBendFactor(byte value) {
#ifdef ENABLE_OPL3
// Not supported in OPL3 mode.
if (_owner->_opl3Mode) {
return;
}
#endif

AdLibVoice *voice;

_pitchBendFactor = value;
for (voice = _voice; voice; voice = voice->_next) {
_owner->adlibNoteOn(voice->_channel, voice->_note/* + _transposeEff*/,
#ifdef ENABLE_OPL3
if (!_owner->_opl3Mode) {
#endif
_owner->adlibNoteOn(voice->_channel, voice->_note /* + _transposeEff*/,
(_pitchBend * _pitchBendFactor >> 6) + _detuneEff);
#ifdef ENABLE_OPL3
} else {
_owner->adlibNoteOn(voice->_channel, voice->_note, (_pitchBend * _pitchBendFactor) >> 5);
}
#endif
}
}

Expand Down Expand Up @@ -1558,20 +1559,21 @@ uint32 MidiDriver_ADLIB::property(int prop, uint32 param) {
}

void MidiDriver_ADLIB::setPitchBendRange(byte channel, uint range) {
#ifdef ENABLE_OPL3
// Not supported in OPL3 mode.
if (_opl3Mode) {
return;
}
#endif

AdLibVoice *voice;
AdLibPart *part = &_parts[channel];

part->_pitchBendFactor = range;
for (voice = part->_voice; voice; voice = voice->_next) {
adlibNoteOn(voice->_channel, voice->_note/* + part->_transposeEff*/,
(part->_pitchBend * part->_pitchBendFactor >> 6) + part->_detuneEff);
#ifdef ENABLE_OPL3
if (!_opl3Mode) {
#endif
adlibNoteOn(voice->_channel, voice->_note/* + part->_transposeEff*/,
(part->_pitchBend * part->_pitchBendFactor >> 6) + part->_detuneEff);
#ifdef ENABLE_OPL3
} else {
adlibNoteOn(voice->_channel, voice->_note, (part->_pitchBend * part->_pitchBendFactor) >> 5);
}
#endif
}
}

Expand Down Expand Up @@ -2091,7 +2093,7 @@ void MidiDriver_ADLIB::mcKeyOn(AdLibVoice *voice, const AdLibInstrument *instr,
#ifdef ENABLE_OPL3
} else {
adlibSetupChannelSecondary(voice->_channel, second, secVol1, secVol2, pan);
adlibNoteOnEx(voice->_channel, note, part->_pitchBend >> 1);
adlibNoteOnEx(voice->_channel, note, (part->_pitchBend * part->_pitchBendFactor) >> 5);
}
#endif
}
Expand Down

0 comments on commit 952de88

Please sign in to comment.