From 70e62a757b6c760b2e9e8352076db377c34fa4eb Mon Sep 17 00:00:00 2001 From: athrxx Date: Sat, 25 Jan 2020 16:42:06 +0100 Subject: [PATCH] KYRA: (HOF) - fix bug #6314 (Wrong MIDI notes sometimes heard at beginning of new s) This is an attempt to fix that bug. It works for me, but it should see more testing. I have tested the Windows "Microsoft GS Wavetable Synth" and our builtin MT-32 emulation. Both work fine with it. I presume the same will be true for all relevant hardware devices. I haven't fully analyzed how the original driver silences the device (and I won't if I don't have to). My impression is that it does not send CC 0x78 (like I do). It seems to send only the CCs we have implemented (0x40, 0x60, 0x7B...). Maybe this whole bug is simply a race condition issue that the original didn't have... --- engines/kyra/sound/drivers/midi.cpp | 7 +++++++ engines/kyra/sound/drivers/midi.h | 1 + engines/kyra/sound/sound_midi.cpp | 7 ++++++- 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/engines/kyra/sound/drivers/midi.cpp b/engines/kyra/sound/drivers/midi.cpp index 5e8460aa970..2ca184430ea 100644 --- a/engines/kyra/sound/drivers/midi.cpp +++ b/engines/kyra/sound/drivers/midi.cpp @@ -352,4 +352,11 @@ void MidiOutput::stopNotesOnChannel(int channel) { } } +void MidiOutput::allSoundsOff() { + for (int i = 0; i < 16; ++i) { + stopNotesOnChannel(i); + sendIntern(0xB0, i, 0x78, 0); + } +} + } // End of namespace Kyra diff --git a/engines/kyra/sound/drivers/midi.h b/engines/kyra/sound/drivers/midi.h index 9e56c7358ae..565c9e8ac68 100644 --- a/engines/kyra/sound/drivers/midi.h +++ b/engines/kyra/sound/drivers/midi.h @@ -37,6 +37,7 @@ public: void initSource(int source); void deinitSource(int source); void stopNotesOnChannel(int channel); + void allSoundsOff(); void setSoundSource(int source) { _curSource = source; } diff --git a/engines/kyra/sound/sound_midi.cpp b/engines/kyra/sound/sound_midi.cpp index 2390b759830..b1a681dba7a 100644 --- a/engines/kyra/sound/sound_midi.cpp +++ b/engines/kyra/sound/sound_midi.cpp @@ -281,9 +281,14 @@ void SoundMidiPC::playTrack(uint8 track) { haltTrack(); - Common::StackLock lock(_mutex); + // The following two lines are meant as a fix for bug #6314. + // It is on purpose that they are outside the mutex lock. + _output->allSoundsOff(); + _vm->delay(250); + Common::StackLock lock(_mutex); _fadeMusicOut = false; + _output->setSourceVolume(0, _musicVolume, true); _output->initSource(0);