aboutsummaryrefslogtreecommitdiff
path: root/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
diff options
context:
space:
mode:
authorathrxx2019-11-10 15:24:41 +0100
committerathrxx2019-12-18 20:50:39 +0100
commit21b5f9262c14114f457120a0504a55fc3ca96489 (patch)
treecebb9eae8918ef1069cdbb2171021c71f4606ae9 /audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
parent1083b94cbfbf687b40d487ab2530be9fb1556b1a (diff)
downloadscummvm-rg350-21b5f9262c14114f457120a0504a55fc3ca96489.tar.gz
scummvm-rg350-21b5f9262c14114f457120a0504a55fc3ca96489.tar.bz2
scummvm-rg350-21b5f9262c14114f457120a0504a55fc3ca96489.zip
AUDIO: (FM-TOWNS/PC-98) - fix regression from 0e734722
My commit 0e734722 causes lockups in SCUMM (sometimes) and SCI (very often). I didn't like the way I had fixed this before, but in the end I now had to do it in a similar way.
Diffstat (limited to 'audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp')
-rw-r--r--audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp14
1 files changed, 10 insertions, 4 deletions
diff --git a/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp b/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
index 558c389ebd..db81485426 100644
--- a/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
+++ b/audio/softsynth/fmtowns_pc98/towns_pc98_fmsynth.cpp
@@ -963,7 +963,7 @@ TownsPC98_FmSynth::TownsPC98_FmSynth(Audio::Mixer *mixer, EmuType type) :
_samplesPerWaitCycle(type == kType26 ? 72 : 144),
#endif
_outputRate(mixer->getOutputRate()), _rateScale(type == kType26 ? 0 : 1),
- _volMaskA(0), _volMaskB(0), _volumeA(255), _volumeB(255), _ready(false) {
+ _volMaskA(0), _volMaskB(0), _volumeA(255), _volumeB(255), _mixerThreadLockCounter(0), _ready(false) {
memset(&_timers[0], 0, sizeof(ChipTimer));
memset(&_timers[1], 0, sizeof(ChipTimer));
@@ -1119,10 +1119,13 @@ uint8 TownsPC98_FmSynth::readReg(uint8 part, uint8 regAddress) {
}
int TownsPC98_FmSynth::readBuffer(int16 *buffer, const int numSamples) {
- Common::StackLock lock(_mutex);
- if (!_ready)
+ _mutex.lock();
+ if (!_ready) {
+ _mutex.unlock();
return 0;
-
+ }
+ _mixerThreadLockCounter++;
+
// This assumes that the numSamples parameter will be the same on most (if not on all) calls to readBuffer(),
// although I don't know whether this is true for all backends. There is no need to reallocate the temp
// buffer every time, unless its size needs to be increased.
@@ -1236,6 +1239,9 @@ int TownsPC98_FmSynth::readBuffer(int16 *buffer, const int numSamples) {
_numPending = render + _numPending - consumed;
}
+ _mutex.unlock();
+ _mixerThreadLockCounter--;
+
return numSamples;
}