diff options
-rw-r--r-- | engines/scumm/player_v1.cpp | 13 | ||||
-rw-r--r-- | engines/scumm/player_v2.cpp | 34 | ||||
-rw-r--r-- | engines/scumm/player_v2.h | 12 | ||||
-rw-r--r-- | engines/scumm/player_v2cms.cpp | 31 |
4 files changed, 30 insertions, 60 deletions
diff --git a/engines/scumm/player_v1.cpp b/engines/scumm/player_v1.cpp index 28cd37698c..f2487c0a57 100644 --- a/engines/scumm/player_v1.cpp +++ b/engines/scumm/player_v1.cpp @@ -68,11 +68,11 @@ void Player_V1::chainSound(int nr, byte *data) { } void Player_V1::startSound(int nr) { + Common::StackLock lock(_mutex); + byte *data = _vm->getResourceAddress(rtSound, nr); assert(data); - mutex_up(); - int offset = _pcjr ? READ_LE_UINT16(data+4) : 6; int cprio = _current_data ? *(_current_data) & 0x7f : 0; int prio = *(data + offset) & 0x7f; @@ -89,21 +89,21 @@ void Player_V1::startSound(int nr) { chainSound(nr, data + offset); } - mutex_down(); } void Player_V1::stopAllSounds() { - mutex_up(); + Common::StackLock lock(_mutex); + for (int i = 0; i < 4; i++) clear_channel(i); _repeat_chunk = _next_chunk = 0; _next_nr = _current_nr = 0; _next_data = _current_data = 0; - mutex_down(); } void Player_V1::stopSound(int nr) { - mutex_up(); + Common::StackLock lock(_mutex); + if (_next_nr == nr) { _next_nr = 0; _next_data = 0; @@ -117,7 +117,6 @@ void Player_V1::stopSound(int nr) { _current_data = 0; chainNextSound(); } - mutex_down(); } void Player_V1::clear_channel(int i) { diff --git a/engines/scumm/player_v2.cpp b/engines/scumm/player_v2.cpp index 764b7ae3fe..b307fe45ab 100644 --- a/engines/scumm/player_v2.cpp +++ b/engines/scumm/player_v2.cpp @@ -370,13 +370,13 @@ Player_V2::Player_V2(ScummEngine *scumm, Audio::Mixer *mixer, bool pcjr) { } Player_V2::~Player_V2() { - mutex_up(); + Common::StackLock lock(_mutex); _mixer->stopHandle(_soundHandle); - mutex_down(); } void Player_V2::set_pcjr(bool pcjr) { - mutex_up(); + Common::StackLock lock(_mutex); + _pcjr = pcjr; if (_pcjr) { @@ -396,12 +396,9 @@ void Player_V2::set_pcjr(bool pcjr) { for (i = 0; (_sampleRate << i) < 30000; i++) _decay = _decay * _decay / 65536; - _timer_output = 0; for (i = 0; i < 4; i++) _timer_count[i] = 0; - - mutex_down(); } void Player_V2::setMusicVolume (int vol) { @@ -452,17 +449,18 @@ void Player_V2::chainNextSound() { } void Player_V2::stopAllSounds() { - mutex_up(); + Common::StackLock lock(_mutex); + for (int i = 0; i < 4; i++) { clear_channel(i); } _next_nr = _current_nr = 0; _next_data = _current_data = 0; - mutex_down(); } void Player_V2::stopSound(int nr) { - mutex_up(); + Common::StackLock lock(_mutex); + if (_next_nr == nr) { _next_nr = 0; _next_data = 0; @@ -475,14 +473,13 @@ void Player_V2::stopSound(int nr) { _current_data = 0; chainNextSound(); } - mutex_down(); } void Player_V2::startSound(int nr) { byte *data = _vm->getResourceAddress(rtSound, nr); assert(data); - mutex_up(); + Common::StackLock lock(_mutex); int cprio = _current_data ? *(_current_data + _header_len) : 0; int prio = *(data + _header_len); @@ -516,8 +513,6 @@ void Player_V2::startSound(int nr) { _next_nr = nr; _next_data = data; } - - mutex_down(); } int Player_V2::getSoundStatus(int nr) const { @@ -787,7 +782,8 @@ void Player_V2::next_freqs(ChannelInfo *channel) { } void Player_V2::do_mix(int16 *data, uint len) { - mutex_up(); + Common::StackLock lock(_mutex); + uint step; do { @@ -806,8 +802,6 @@ void Player_V2::do_mix(int16 *data, uint len) { data += 2 * step; _next_tick -= step << FIXP_SHIFT; } while (len -= step); - - mutex_down(); } void Player_V2::nextTick() { @@ -957,12 +951,4 @@ void Player_V2::generatePCjrSamples(int16 *data, uint len) { lowPassFilter(data, len); } -void Player_V2::mutex_up() { - _mutex.lock(); -} - -void Player_V2::mutex_down() { - _mutex.unlock(); -} - } // End of namespace Scumm diff --git a/engines/scumm/player_v2.h b/engines/scumm/player_v2.h index 498cfdc1d7..2c3e784928 100644 --- a/engines/scumm/player_v2.h +++ b/engines/scumm/player_v2.h @@ -119,6 +119,8 @@ protected: byte *_next_data; byte *_retaddr; + Common::Mutex _mutex; + private: union ChannelInfo { channel_data d; @@ -131,13 +133,9 @@ private: const uint16 *_freqs_table; - Common::Mutex _mutex; ChannelInfo _channels[5]; protected: - void mutex_up(); - void mutex_down(); - virtual void nextTick(); virtual void clear_channel(int i); virtual void chainSound(int nr, byte *data); @@ -302,6 +300,8 @@ protected: byte *_next_data; byte *_retaddr; + Common::Mutex _mutex; + private: union ChannelInfo { channel_data d; @@ -312,13 +312,9 @@ private: int _music_timer_ctr; int _ticks_per_music_timer; - Common::Mutex _mutex; ChannelInfo _channels[5]; protected: - void mutex_up(); - void mutex_down(); - virtual void nextTick(); virtual void clear_channel(int i); virtual void chainSound(int nr, byte *data); diff --git a/engines/scumm/player_v2cms.cpp b/engines/scumm/player_v2cms.cpp index 7b3eb87c02..51552137d1 100644 --- a/engines/scumm/player_v2cms.cpp +++ b/engines/scumm/player_v2cms.cpp @@ -895,10 +895,10 @@ Player_V2CMS::Player_V2CMS(ScummEngine *scumm, Audio::Mixer *mixer) { } Player_V2CMS::~Player_V2CMS() { - mutex_up(); + Common::StackLock lock(_mutex); + _mixer->stopHandle(_soundHandle); delete g_cmsEmu; - mutex_down(); } void Player_V2CMS::setMusicVolume(int vol) { @@ -933,7 +933,8 @@ void Player_V2CMS::chainNextSound() { } void Player_V2CMS::stopAllSounds() { - mutex_up(); + Common::StackLock lock(_mutex); + for (int i = 0; i < 4; i++) { clear_channel(i); } @@ -943,11 +944,11 @@ void Player_V2CMS::stopAllSounds() { _midiSongBegin = 0; _midiDelay = 0; offAllChannels(); - mutex_down(); } void Player_V2CMS::stopSound(int nr) { - mutex_up(); + Common::StackLock lock(_mutex); + if (_next_nr == nr) { _next_nr = 0; _next_data = 0; @@ -966,20 +967,17 @@ void Player_V2CMS::stopSound(int nr) { _midiDelay = 0; offAllChannels(); } - mutex_down(); } void Player_V2CMS::startSound(int nr) { + Common::StackLock lock(_mutex); + byte *data = _vm->getResourceAddress(rtSound, nr); assert(data); if (data[6] == 0x80) { - mutex_up(); loadMidiData(data, nr); - mutex_down(); } else { - mutex_up(); - int cprio = _current_data ? *(_current_data + _header_len) : 0; int prio = *(data + _header_len); int nprio = _next_data ? *(_next_data + _header_len) : 0; @@ -1012,8 +1010,6 @@ void Player_V2CMS::startSound(int nr) { _next_nr = nr; _next_data = data; } - - mutex_down(); } } @@ -1413,7 +1409,8 @@ void Player_V2CMS::processMidiData(uint ticks) { } int Player_V2CMS::readBuffer(int16 *buffer, const int numSamples) { - mutex_up(); + Common::StackLock lock(_mutex); + uint step = 1; int len = numSamples/2; @@ -1450,7 +1447,6 @@ int Player_V2CMS::readBuffer(int16 *buffer, const int numSamples) { _next_tick -= step << FIXP_SHIFT; } while (len -= step); - mutex_down(); return numSamples; } @@ -1843,11 +1839,4 @@ void Player_V2CMS::playMusicChips(const MusicChip *table) { } while ((cmsPort & 2) == 0); } -void Player_V2CMS::mutex_up() { - _mutex.lock(); -} - -void Player_V2CMS::mutex_down() { - _mutex.unlock(); -} } // End of namespace Scumm |