[Scummvm-cvs-logs] SF.net SVN: scummvm:[44210] scummvm/trunk/engines/kyra/sound_towns.cpp

lordhoto at users.sourceforge.net lordhoto at users.sourceforge.net
Sun Sep 20 16:29:09 CEST 2009


Revision: 44210
          http://scummvm.svn.sourceforge.net/scummvm/?rev=44210&view=rev
Author:   lordhoto
Date:     2009-09-20 14:29:08 +0000 (Sun, 20 Sep 2009)

Log Message:
-----------
This hopefully fixes threading issues in PC98 sound driver.

Modified Paths:
--------------
    scummvm/trunk/engines/kyra/sound_towns.cpp

Modified: scummvm/trunk/engines/kyra/sound_towns.cpp
===================================================================
--- scummvm/trunk/engines/kyra/sound_towns.cpp	2009-09-20 14:16:31 UTC (rev 44209)
+++ scummvm/trunk/engines/kyra/sound_towns.cpp	2009-09-20 14:29:08 UTC (rev 44210)
@@ -1608,7 +1608,7 @@
 	void writeReg(uint8 part, uint8 regAddress, uint8 value);
 
 	// AudioStream interface
-	int inline readBuffer(int16 *buffer, const int numSamples);
+	int readBuffer(int16 *buffer, const int numSamples);
 	bool isStereo() const { return true; }
 	bool endOfData() const { return false; }
 	int getRate() const { return _mixer->getOutputRate(); }
@@ -1622,19 +1622,15 @@
 	virtual void timerCallbackA() = 0;
 	virtual void timerCallbackB() = 0;
 
-	void lock() { _mutex.lock(); }
-	void unlock() { _mutex.unlock(); }
-
 	const int _numChan;
 	const int _numSSG;
 	const bool _hasPercussion;
 
+	Common::Mutex _mutex;
 private:
 	void nextTick(int32 *buffer, uint32 bufferSize);
 	void generateOutput(int32 &leftSample, int32 &rightSample, int32 *del, int32 *feed);
 
-	Common::Mutex _mutex;
-
 	struct ChanInternal {
 		uint16 frqTemp;
 		bool enableLeft;
@@ -2941,6 +2937,7 @@
 }
 
 TownsPC98_OpnCore::~TownsPC98_OpnCore() {
+	Common::StackLock lock(_mutex);
 	_mixer->stopHandle(_soundHandle);
 	delete _ssg;
 	delete _prc;
@@ -3176,7 +3173,9 @@
 	}
 }
 
-int inline TownsPC98_OpnCore::readBuffer(int16 *buffer, const int numSamples) {
+int TownsPC98_OpnCore::readBuffer(int16 *buffer, const int numSamples) {
+	Common::StackLock lock(_mutex);
+
 	memset(buffer, 0, sizeof(int16) * numSamples);
 	int32 *tmp = new int32[numSamples];
 	int32 *tmpStart = tmp;
@@ -3184,7 +3183,6 @@
 	int32 samplesLeft = numSamples >> 1;
 
 	while (samplesLeft) {
-
 		int32 render = samplesLeft;
 
 		for (int i = 0; i < 2; i++) {
@@ -3509,8 +3507,7 @@
 
 	reset();
 
-	lock();
-
+	Common::StackLock lock(_mutex);
 	uint8 *src_a = _trackPtr = _musicBuffer = data;
 
 	for (uint8 i = 0; i < 3; i++) {
@@ -3539,8 +3536,6 @@
 	_finishedChannelsFlag = _finishedSSGFlag = _finishedRhythmFlag = 0;
 
 	_musicPlaying = (loadPaused ? false : true);
-
-	unlock();
 }
 
 void TownsPC98_OpnDriver::loadSoundEffectData(uint8 *data, uint8 trackNum) {
@@ -3559,18 +3554,16 @@
 		return;
 	}
 
-	lock();
+	Common::StackLock lock(_mutex);
 	_sfxData = _sfxBuffer = data;
 	_sfxOffsets[0] = READ_LE_UINT16(&_sfxData[(trackNum << 2)]);
 	_sfxOffsets[1] = READ_LE_UINT16(&_sfxData[(trackNum << 2) + 2]);
 	_sfxPlaying = true;
 	_finishedSfxFlag = 0;
-	unlock();
 }
 
 void TownsPC98_OpnDriver::reset() {
-	lock();
-
+	Common::StackLock lock(_mutex);
 	TownsPC98_OpnCore::reset();
 
 	for (int i = 0; i < _numChan; i++)
@@ -3594,16 +3587,13 @@
 	_looping = 0;
 	_musicTickCounter = 0;
 	_sfxData = 0;
-
-	unlock();
 }
 
 void TownsPC98_OpnDriver::fadeStep() {
 	if (!_musicPlaying)
 		return;
 
-	lock();
-
+	Common::StackLock lock(_mutex);
 	for (int j = 0; j < _numChan; j++) {
 		if (_updateChannelsFlag & _channels[j]->_idFlag)
 			_channels[j]->fadeStep();
@@ -3624,13 +3614,9 @@
 		if (!--_fading)
 			reset();
 	}
-
-	unlock();
 }
 
 void TownsPC98_OpnDriver::timerCallbackB() {
-	lock();
-
 	_sfxOffs = 0;
 
 	if (_musicPlaying) {
@@ -3659,13 +3645,9 @@
 
 	if (_finishedChannelsFlag == _updateChannelsFlag && _finishedSSGFlag == _updateSSGFlag && _finishedRhythmFlag == _updateRhythmFlag)
 		_musicPlaying = false;
-
-	unlock();
 }
 
 void TownsPC98_OpnDriver::timerCallbackA() {
-	lock();
-
 	if (_sfxChannels && _sfxPlaying) {
 		if (_sfxData)
 			startSoundEffect();
@@ -3685,8 +3667,6 @@
 
 	if (_finishedSfxFlag == _updateSfxFlag)
 		_sfxPlaying = false;
-
-	unlock();
 }
 
 void TownsPC98_OpnDriver::setMusicTempo(uint8 tempo) {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list