aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorJohannes Schickel2006-07-26 22:24:33 +0000
committerJohannes Schickel2006-07-26 22:24:33 +0000
commitbcc892ec81a5af68874f89135e2f5659271649e2 (patch)
treeb28865cc737b708827133c5eae7717e32255638c /engines
parenteb7cda50aa5db1561d3285410e20408f2cd5b097 (diff)
downloadscummvm-rg350-bcc892ec81a5af68874f89135e2f5659271649e2.tar.gz
scummvm-rg350-bcc892ec81a5af68874f89135e2f5659271649e2.tar.bz2
scummvm-rg350-bcc892ec81a5af68874f89135e2f5659271649e2.zip
Make the midi player threadsafe (this should fix bug #1506583 "KYRA1: Crash on exceeded polyphony").
svn-id: r23605
Diffstat (limited to 'engines')
-rw-r--r--engines/kyra/sound.cpp14
-rw-r--r--engines/kyra/sound.h5
2 files changed, 19 insertions, 0 deletions
diff --git a/engines/kyra/sound.cpp b/engines/kyra/sound.cpp
index ffe7ee1ac3..a279cb9499 100644
--- a/engines/kyra/sound.cpp
+++ b/engines/kyra/sound.cpp
@@ -118,6 +118,11 @@ SoundMidiPC::SoundMidiPC(MidiDriver *driver, Audio::Mixer *mixer, KyraEngine *en
}
SoundMidiPC::~SoundMidiPC() {
+ stopMusic();
+ stopSoundEffect();
+
+ Common::StackLock lock(_mutex);
+
_driver->setTimerCallback(NULL, NULL);
close();
}
@@ -243,6 +248,8 @@ void SoundMidiPC::loadMusicFile(const char *file) {
void SoundMidiPC::playMusic(uint8 *data, uint32 size) {
stopMusic();
+ Common::StackLock lock(_mutex);
+
_parserSource = data;
_parser = MidiParser::createParser_XMIDI();
assert(_parser);
@@ -278,6 +285,8 @@ void SoundMidiPC::loadSoundEffectFile(const char *file) {
void SoundMidiPC::loadSoundEffectFile(uint8 *data, uint32 size) {
stopSoundEffect();
+ Common::StackLock lock(_mutex);
+
_soundEffectSource = data;
_soundEffect = MidiParser::createParser_XMIDI();
assert(_soundEffect);
@@ -296,6 +305,8 @@ void SoundMidiPC::loadSoundEffectFile(uint8 *data, uint32 size) {
}
void SoundMidiPC::stopMusic() {
+ Common::StackLock lock(_mutex);
+
_isPlaying = false;
if (_parser) {
_parser->unloadMusic();
@@ -311,6 +322,8 @@ void SoundMidiPC::stopMusic() {
}
void SoundMidiPC::stopSoundEffect() {
+ Common::StackLock lock(_mutex);
+
_sfxIsPlaying = false;
if (_soundEffect) {
_soundEffect->unloadMusic();
@@ -323,6 +336,7 @@ void SoundMidiPC::stopSoundEffect() {
void SoundMidiPC::onTimer(void *refCon) {
SoundMidiPC *music = (SoundMidiPC *)refCon;
+ Common::StackLock lock(music->_mutex);
// this should be set to the fadeToBlack value
static const uint32 musicFadeTime = 2 * 1000;
diff --git a/engines/kyra/sound.h b/engines/kyra/sound.h
index a7de851349..0d932ae772 100644
--- a/engines/kyra/sound.h
+++ b/engines/kyra/sound.h
@@ -26,9 +26,12 @@
#include "common/stdafx.h"
#include "common/scummsys.h"
#include "common/file.h"
+#include "common/mutex.h"
+
#include "sound/mididrv.h"
#include "sound/midiparser.h"
#include "sound/mixer.h"
+
#include "kyra/kyra.h"
namespace Audio {
@@ -200,6 +203,8 @@ private:
byte *_parserSource;
MidiParser *_soundEffect;
byte *_soundEffectSource;
+
+ Common::Mutex _mutex;
};
class MixedSoundDriver : public Sound {