aboutsummaryrefslogtreecommitdiff
path: root/engines/tsage/sound.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'engines/tsage/sound.cpp')
-rw-r--r--engines/tsage/sound.cpp35
1 files changed, 12 insertions, 23 deletions
diff --git a/engines/tsage/sound.cpp b/engines/tsage/sound.cpp
index 0d3fb55dd3..044bd567d4 100644
--- a/engines/tsage/sound.cpp
+++ b/engines/tsage/sound.cpp
@@ -23,6 +23,7 @@
#include "audio/fmopl.h"
#include "audio/decoders/raw.h"
#include "common/config-manager.h"
+#include "common/timer.h"
#include "audio/audiostream.h"
#include "tsage/core.h"
#include "tsage/globals.h"
@@ -70,7 +71,7 @@ SoundManager::~SoundManager() {
}
sfTerminate();
-// g_system->getTimerManager()->removeTimerProc(_sfUpdateCallback);
+ g_system->getTimerManager()->removeTimerProc(&sfSoundServer);
}
// Free any allocated voice type structures
@@ -90,12 +91,7 @@ void SoundManager::postInit() {
g_saver->addLoadNotifier(&SoundManager::loadNotifier);
g_saver->addListener(this);
-
-// I originally separated the sound manager update method into a separate thread, since
-// it handles updates for both music and Fx. However, since Adlib updates also get done in a
-// thread, and doesn't get too far ahead, I've left it to the AdlibSoundDriver class to
-// call the update method, rather than having it be called separately
-// g_system->getTimerManager()->installTimerProc(_sfUpdateCallback, 1000000 / SOUND_FREQUENCY, NULL, "tsageSoundUpdate");
+ g_system->getTimerManager()->installTimerProc(&sfSoundServer, 1000000 / CALLBACKS_PER_SECOND, NULL, "tsageSoundUpdate");
_sndmgrReady = true;
}
}
@@ -147,10 +143,6 @@ void SoundManager::syncSounds() {
}
}
-void SoundManager::update() {
- sfSoundServer();
-}
-
Common::List<SoundDriverEntry> &SoundManager::buildDriverList(bool detectFlag) {
assert(_sndmgrReady);
_availableDrivers.clear();
@@ -382,7 +374,10 @@ void SoundManager::rethinkVoiceTypes() {
sfRethinkVoiceTypes();
}
-void SoundManager::sfSoundServer() {
+void SoundManager::sfSoundServer(void *) {
+ Common::StackLock slock1(SoundManager::sfManager()._serverDisabledMutex);
+ Common::StackLock slock2(SoundManager::sfManager()._serverSuspendedMutex);
+
if (sfManager()._needToRethink) {
sfRethinkVoiceTypes();
sfManager()._needToRethink = false;
@@ -544,10 +539,6 @@ void SoundManager::sfUpdateVoiceStructs2() {
}
}
-void SoundManager::sfUpdateCallback(void *ref) {
- ((SoundManager *)ref)->update();
-}
-
/*--------------------------------------------------------------------------*/
void SoundManager::saveNotifier(bool postFlag) {
@@ -1562,7 +1553,9 @@ void Sound::play(int soundNum) {
}
void Sound::stop() {
- g_globals->_soundManager.removeFromPlayList(this);
+ if (g_globals) {
+ g_globals->_soundManager.removeFromPlayList(this);
+ }
_unPrime();
}
@@ -2879,13 +2872,13 @@ void AdlibSoundDriver::setPitch(int channel, int pitchBlend) {
}
void AdlibSoundDriver::write(byte reg, byte value) {
+ Common::StackLock lock(_queueMutex);
_portContents[reg] = value;
_queue.push(RegisterValue(reg, value));
}
void AdlibSoundDriver::flush() {
- Common::StackLock slock(SoundManager::sfManager()._serverDisabledMutex);
-
+ Common::StackLock lock(_queueMutex);
while (!_queue.empty()) {
RegisterValue v = _queue.pop();
_opl->writeReg(v._regNum, v._value);
@@ -3013,10 +3006,6 @@ void AdlibSoundDriver::setFrequency(int channel) {
}
void AdlibSoundDriver::onTimer() {
- Common::StackLock slock1(SoundManager::sfManager()._serverDisabledMutex);
- Common::StackLock slock2(SoundManager::sfManager()._serverSuspendedMutex);
-
- SoundManager::sfUpdateCallback(NULL);
flush();
}