Skip to content

Commit

Permalink
SCI: Set default MT-32 reverb before each sound
Browse files Browse the repository at this point in the history
Set the default reverb configuration present in either the MT-32
patch data or MT32.DRV of SCI0 games before playing each sound, as
a previously played sound may have changed it.

Also, do not perform a general reverb init, since the start of a
sound will do that now.

Closes gh-1023.
  • Loading branch information
rklaver authored and csnover committed Oct 5, 2017
1 parent cedd9d3 commit 6843870
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 9 deletions.
22 changes: 13 additions & 9 deletions engines/sci/sound/drivers/midi.cpp
Expand Up @@ -158,6 +158,7 @@ class MidiPlayer_Midi : public MidiPlayer {
int getFirstChannel() const;
int getLastChannel() const;
void setVolume(byte volume);
virtual void onNewSound() override;
int getVolume();
void setReverb(int8 reverb);
void playSwitch(bool play);
Expand Down Expand Up @@ -204,6 +205,7 @@ class MidiPlayer_Midi : public MidiPlayer {
int _masterVolume;

byte _reverbConfig[kReverbConfigNr][3];
int8 _defaultReverb;
Channel _channels[16];
uint8 _percussionMap[128];
int8 _keyShift[128];
Expand All @@ -220,7 +222,7 @@ class MidiPlayer_Midi : public MidiPlayer {
byte _sysExBuf[kMaxSysExSize];
};

MidiPlayer_Midi::MidiPlayer_Midi(SciVersion version) : MidiPlayer(version), _playSwitch(true), _masterVolume(15), _mt32Type(kMt32TypeNone), _hasReverb(false), _useMT32Track(true) {
MidiPlayer_Midi::MidiPlayer_Midi(SciVersion version) : MidiPlayer(version), _playSwitch(true), _masterVolume(15), _mt32Type(kMt32TypeNone), _hasReverb(false), _defaultReverb(-1), _useMT32Track(true) {
MidiDriver::DeviceHandle dev = MidiDriver::detectDevice(MDT_MIDI);
_driver = MidiDriver::createMidi(dev);

Expand Down Expand Up @@ -477,6 +479,14 @@ int MidiPlayer_Midi::getVolume() {
return _masterVolume;
}

void MidiPlayer_Midi::onNewSound() {
if (_defaultReverb >= 0)
// SCI0 in combination with MT-32 requires a reset of the reverb to
// the default value that is present in either the MT-32 patch data
// or MT32.DRV itself.
setReverb(_defaultReverb);
}

void MidiPlayer_Midi::setReverb(int8 reverb) {
assert(reverb < kReverbConfigNr);

Expand Down Expand Up @@ -610,7 +620,7 @@ void MidiPlayer_Midi::readMt32Patch(const SciSpan<const byte> &data) {
setMt32Volume(volume);

// Reverb default only used in (roughly) SCI0/SCI01
byte reverb = stream.readByte();
_defaultReverb = stream.readSByte();

_hasReverb = true;

Expand Down Expand Up @@ -649,10 +659,6 @@ void MidiPlayer_Midi::readMt32Patch(const SciSpan<const byte> &data) {
sendMt32SysEx(0x100004, stream, 9);
}

// Reverb for SCI0
if (_version <= SCI_VERSION_0_LATE)
setReverb(reverb);

// Send after-SysEx text
stream.seek(0);
sendMt32SysEx(0x200000, stream, 20);
Expand Down Expand Up @@ -780,7 +786,7 @@ void MidiPlayer_Midi::readMt32DrvData() {

if (size == 2771) {
// MT32.DRV in LSL2 early contains more data, like a normal patch
byte reverb = f.readByte();
_defaultReverb = f.readByte();

_hasReverb = true;

Expand All @@ -800,8 +806,6 @@ void MidiPlayer_Midi::readMt32DrvData() {
sendMt32SysEx(0x50000, f, 256);
sendMt32SysEx(0x50200, f, 128);

setReverb(reverb);

// Send the after-SysEx text
f.seek(0x3d);
sendMt32SysEx(0x200000, f, 20);
Expand Down
2 changes: 2 additions & 0 deletions engines/sci/sound/drivers/mididriver.h
Expand Up @@ -106,6 +106,8 @@ class MidiPlayer : public MidiDriver_BASE {
return _driver ? _driver->property(MIDI_PROP_MASTER_VOLUME, 0xffff) : 0;
}

virtual void onNewSound() {}

// Returns the current reverb, or -1 when no reverb is active
int8 getReverb() const { return _reverb; }
// Sets the current reverb, used mainly in MT-32
Expand Down
2 changes: 2 additions & 0 deletions engines/sci/sound/midiparser_sci.cpp
Expand Up @@ -392,6 +392,8 @@ void MidiParser_SCI::sendInitCommands() {
// Set initial voice count
if (_pSnd) {
if (_soundVersion <= SCI_VERSION_0_LATE) {
static_cast<MidiPlayer *>(_driver)->onNewSound();

for (int i = 0; i < 15; ++i) {
byte voiceCount = 0;
if (_channelUsed[i]) {
Expand Down

0 comments on commit 6843870

Please sign in to comment.