From 1e23c91914cde7e9b9c47c9e727818d958e57e3f Mon Sep 17 00:00:00 2001 From: Colin Snover Date: Thu, 8 Dec 2016 14:38:45 -0600 Subject: MT32: Fix driver to be thread-safe --- audio/softsynth/mt32.cpp | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/audio/softsynth/mt32.cpp b/audio/softsynth/mt32.cpp index 6c4b845c87..8ad456e3a3 100644 --- a/audio/softsynth/mt32.cpp +++ b/audio/softsynth/mt32.cpp @@ -104,6 +104,7 @@ private: MT32Emu::ScummVMReportHandler *_reportHandler; byte *_controlData, *_pcmData; void deleteMuntStructures(); + Common::Mutex _mutex; int _outputRate; @@ -236,6 +237,7 @@ int MidiDriver_MT32::open() { } void MidiDriver_MT32::send(uint32 b) { + Common::StackLock lock(_mutex); _service->playMsg(b); } @@ -246,11 +248,13 @@ void MidiDriver_MT32::setPitchBendRange(byte channel, uint range) { warning("setPitchBendRange() called with range > 24: %d", range); } byte benderRangeSysex[4] = { 0, 0, 4, (uint8)range }; + Common::StackLock lock(_mutex); _service->writeSysex(channel, benderRangeSysex, 4); } void MidiDriver_MT32::sysEx(const byte *msg, uint16 length) { if (msg[0] == 0xf0) { + Common::StackLock lock(_mutex); _service->playSysex(msg, length); } else { enum { @@ -259,6 +263,7 @@ void MidiDriver_MT32::sysEx(const byte *msg, uint16 length) { }; if (msg[3] == SYSEX_CMD_DT1 || msg[3] == SYSEX_CMD_DAT) { + Common::StackLock lock(_mutex); _service->writeSysex(msg[1], msg + 4, length - 5); } else { warning("Unused sysEx command %d", msg[3]); @@ -276,11 +281,13 @@ void MidiDriver_MT32::close() { // Detach the mixer callback handler _mixer->stopHandle(_mixerSoundHandle); + Common::StackLock lock(_mutex); _service->closeSynth(); deleteMuntStructures(); } void MidiDriver_MT32::generateSamples(int16 *data, int len) { + Common::StackLock lock(_mutex); _service->renderBit16s(data, len); } -- cgit v1.2.3