From 361c3b95d52babd23b78864e6679334ed1c9e316 Mon Sep 17 00:00:00 2001 From: Max Horn Date: Sun, 7 Sep 2003 17:14:56 +0000 Subject: some cleanup; clarified isSoundInUse semantics and the difference between IMuse::get_sound_active and IMuse::getSoundStatus; added lots of const qualifiers to IMuse; rewrote IMuseInternal::getSoundStatus (hopefully not breaking it); added MusicEngine::getSoundStatus svn-id: r10069 --- scumm/imuse.cpp | 38 +++++++++++------------ scumm/imuse.h | 10 +++--- scumm/imuse_digi.cpp | 6 ++-- scumm/imuse_digi.h | 2 +- scumm/imuse_internal.h | 30 +++++++++--------- scumm/imuse_player.cpp | 2 +- scumm/music.h | 2 +- scumm/player_v1.h | 2 +- scumm/player_v2.cpp | 2 +- scumm/player_v2.h | 2 +- scumm/player_v3a.cpp | 8 ++--- scumm/player_v3a.h | 2 +- scumm/resource.cpp | 2 +- scumm/sound.cpp | 83 +++++++++++++++++++++++++------------------------- scumm/sound.h | 2 +- 15 files changed, 95 insertions(+), 98 deletions(-) diff --git a/scumm/imuse.cpp b/scumm/imuse.cpp index 4ba22fa2b0..5d436d24ff 100644 --- a/scumm/imuse.cpp +++ b/scumm/imuse.cpp @@ -424,25 +424,23 @@ Part *IMuseInternal::allocate_part(byte pri, MidiDriver *midi) { return best; } -int IMuseInternal::getSoundStatus(int sound, bool ignoreFadeouts) { - Player *player; - if (sound == -1) { - player = _players; - for (int i = ARRAYSIZE(_players); i; --i, ++player) { - if (player->isActive() &&(!ignoreFadeouts || !player->isFadingOut())) +int IMuseInternal::getSoundStatus(int sound, bool ignoreFadeouts) const { + int i; + const Player *player = _players; + + for (i = ARRAYSIZE(_players); i != 0; i--, player++) { + if (player->isActive() && (!ignoreFadeouts || !player->isFadingOut())) { + if (sound == -1) return player->getID(); + else if (player->getID() == (uint16)sound) + return 1; } - return 0; } - - player = findActivePlayer(sound); - if (player &&(!ignoreFadeouts || !player->isFadingOut())) - return 1; - return get_queue_sound_status(sound); + return (sound == -1) ? 0 : get_queue_sound_status(sound); } -int IMuseInternal::get_queue_sound_status(int sound) { - uint16 *a; +int IMuseInternal::get_queue_sound_status(int sound) const { + const uint16 *a; int i, j; j = _queue_pos; @@ -1049,9 +1047,9 @@ int HookDatas::set(byte cls, byte value, byte chan) { Player *IMuseInternal::findActivePlayer(int id) { int i; - Player *player; + Player *player = _players; - for (i = ARRAYSIZE(_players), player = _players; i != 0; i--, player++) { + for (i = ARRAYSIZE(_players); i != 0; i--, player++) { if (player->isActive() && player->getID() == (uint16)id) return player; } @@ -1746,8 +1744,8 @@ void IMuseInternal::copyGlobalAdlibInstrument(byte slot, Instrument *dest) { IMuse::IMuse(OSystem *system, IMuseInternal *target) : _system(system), _target(target) { _mutex = system->create_mutex(); } IMuse::~IMuse() { if (_mutex) _system->delete_mutex(_mutex); if (_target) delete _target; } -inline void IMuse::in() { _system->lock_mutex(_mutex); } -inline void IMuse::out() { _system->unlock_mutex(_mutex); } +inline void IMuse::in() const { _system->lock_mutex(_mutex); } +inline void IMuse::out() const { _system->unlock_mutex(_mutex); } void IMuse::on_timer(MidiDriver *midi) { in(); _target->on_timer(midi); out(); } void IMuse::pause(bool paused) { in(); _target->pause(paused); out(); } @@ -1759,8 +1757,8 @@ int IMuse::get_master_volume() { in(); int ret = _target->get_master_volume(); o void IMuse::startSound(int sound) { in(); _target->startSound(sound); out(); } void IMuse::stopSound(int sound) { in(); _target->stopSound(sound); out(); } int IMuse::stopAllSounds() { in(); int ret = _target->stopAllSounds(); out(); return ret; } -int IMuse::getSoundStatus(int sound) { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; } -bool IMuse::get_sound_active(int sound) { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; } +int IMuse::getSoundStatus(int sound) const { in(); int ret = _target->getSoundStatus(sound, true); out(); return ret; } +bool IMuse::get_sound_active(int sound) const { in(); bool ret = _target->getSoundStatus(sound, false) ? 1 : 0; out(); return ret; } int IMuse::getMusicTimer() { in(); int ret = _target->getMusicTimer(); out(); return ret; } int32 IMuse::doCommand (int a, int b, int c, int d, int e, int f, int g, int h) { in(); int32 ret = _target->doCommand(a,b,c,d,e,f,g,h); out(); return ret; } int32 IMuse::doCommand (int numargs, int args[]) { in(); int32 ret = _target->doCommand (numargs, args); out(); return ret; } diff --git a/scumm/imuse.h b/scumm/imuse.h index 6cef659dda..78b75829dc 100644 --- a/scumm/imuse.h +++ b/scumm/imuse.h @@ -38,11 +38,11 @@ class IMuse : public MusicEngine { private: OSystem *_system; IMuseInternal *_target; - OSystem::MutexRef _mutex; + mutable OSystem::MutexRef _mutex; IMuse(OSystem *system, IMuseInternal *target); - void in(); - void out(); + void in() const; + void out() const; public: ~IMuse(); @@ -66,8 +66,8 @@ public: void startSound(int sound); void stopSound(int sound); int stopAllSounds(); - int getSoundStatus(int sound); - bool get_sound_active(int sound); + int getSoundStatus(int sound) const; + bool get_sound_active(int sound) const; int getMusicTimer(); int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h); int32 doCommand (int numargs, int args[]); diff --git a/scumm/imuse_digi.cpp b/scumm/imuse_digi.cpp index f3a8cf9e29..2603b2acda 100644 --- a/scumm/imuse_digi.cpp +++ b/scumm/imuse_digi.cpp @@ -1164,15 +1164,15 @@ int32 IMuseDigital::doCommand(int a, int b, int c, int d, int e, int f, int g, i } } -bool IMuseDigital::getSoundStatus(int sound) { +int IMuseDigital::getSoundStatus(int sound) const { debug(5, "IMuseDigital::getSoundStatus(%d)", sound); for (int l = 0; l < MAX_DIGITAL_CHANNELS; l++) { if ((_channel[l]._idSound == sound) && _channel[l]._used) { - return true; + return 1; } } - return false; + return 0; } diff --git a/scumm/imuse_digi.h b/scumm/imuse_digi.h index e5774444bb..7756be415f 100644 --- a/scumm/imuse_digi.h +++ b/scumm/imuse_digi.h @@ -72,7 +72,7 @@ public: void stopAll(); void pause(bool pause); int32 doCommand(int a, int b, int c, int d, int e, int f, int g, int h); - bool getSoundStatus(int sound); + int getSoundStatus(int sound) const; }; #endif diff --git a/scumm/imuse_internal.h b/scumm/imuse_internal.h index b88ea0b7dd..512e701ab2 100644 --- a/scumm/imuse_internal.h +++ b/scumm/imuse_internal.h @@ -232,21 +232,21 @@ public: void fixAfterLoad(); Part * getActivePart(uint8 part); uint getBeatIndex(); - int8 getDetune() { return _detune; } - byte getEffectiveVolume() { return _vol_eff; } - int getID() { return _id; } - MidiDriver *getMidiDriver() { return _midi; } + int8 getDetune() const { return _detune; } + byte getEffectiveVolume() const { return _vol_eff; } + int getID() const { return _id; } + MidiDriver *getMidiDriver() const { return _midi; } int getParam(int param, byte chan); - int8 getPan() { return _pan; } + int8 getPan() const { return _pan; } Part * getPart(uint8 part); - byte getPriority() { return _priority; } - uint getTicksPerBeat() { return TICKS_PER_BEAT; } - int8 getTranspose() { return _transpose; } - byte getVolume() { return _volume; } - bool isActive() { return _active; } - bool isFadingOut(); - bool isGM() { return _isGM; } - bool isMT32() { return _isMT32; } + byte getPriority() const { return _priority; } + uint getTicksPerBeat() const { return TICKS_PER_BEAT; } + int8 getTranspose() const { return _transpose; } + byte getVolume() const { return _volume; } + bool isActive() const { return _active; } + bool isFadingOut() const; + bool isGM() const { return _isGM; } + bool isMT32() const { return _isMT32; } bool jump(uint track, uint beat, uint tick); void onTimer(); void removePart(Part *part); @@ -397,7 +397,7 @@ protected: byte *findStartOfSound(int sound); bool isMT32(int sound); bool isGM(int sound); - int get_queue_sound_status(int sound); + int get_queue_sound_status(int sound) const; void handle_marker(uint id, byte data); int get_channel_volume(uint a); void initMidiDriver(MidiDriver *midi); @@ -462,7 +462,7 @@ public: bool startSound(int sound); int stopSound(int sound); int stopAllSounds(); - int getSoundStatus(int sound, bool ignoreFadeouts = true); + int getSoundStatus(int sound, bool ignoreFadeouts = true) const; int getMusicTimer(); int32 doCommand (int a, int b, int c, int d, int e, int f, int g, int h); int32 doCommand (int numargs, int args[]); diff --git a/scumm/imuse_player.cpp b/scumm/imuse_player.cpp index 3b42d2f74c..51315e0a6c 100644 --- a/scumm/imuse_player.cpp +++ b/scumm/imuse_player.cpp @@ -132,7 +132,7 @@ int Player::getMusicTimer() { return _parser ? (_parser->getTick() * 2 / _parser->getPPQN()) : 0; } -bool Player::isFadingOut() { +bool Player::isFadingOut() const { int i; for (i = 0; i < ARRAYSIZE(_parameterFaders); ++i) { if (_parameterFaders[i].param == ParameterFader::pfVolume && diff --git a/scumm/music.h b/scumm/music.h index 8529959ec8..5f6b124f3d 100644 --- a/scumm/music.h +++ b/scumm/music.h @@ -33,7 +33,7 @@ public: virtual void startSound(int sound) = 0; virtual void stopSound(int sound) = 0; // virtual void stopAllSounds() = 0; -// virtual bool getSoundStatus(int sound) const = 0; + virtual int getSoundStatus(int sound) const = 0; }; #endif diff --git a/scumm/player_v1.h b/scumm/player_v1.h index ad10f09d61..9adada0097 100644 --- a/scumm/player_v1.h +++ b/scumm/player_v1.h @@ -58,7 +58,7 @@ protected: void clear_channel(int i); void chainSound(int nr, byte *data); - void do_mix (int16 *buf, uint len); + void do_mix(int16 *buf, uint len); void set_mplex(uint mplex); void parseSpeakerChunk(); diff --git a/scumm/player_v2.cpp b/scumm/player_v2.cpp index 5543d57fdf..0538631a87 100644 --- a/scumm/player_v2.cpp +++ b/scumm/player_v2.cpp @@ -522,7 +522,7 @@ void Player_V2::startSound(int nr) { mutex_down(); } -bool Player_V2::getSoundStatus(int nr) const { +int Player_V2::getSoundStatus(int nr) const { return _current_nr == nr || _next_nr == nr; } diff --git a/scumm/player_v2.h b/scumm/player_v2.h index 04ab1e84ed..54b98e426b 100644 --- a/scumm/player_v2.h +++ b/scumm/player_v2.h @@ -81,7 +81,7 @@ public: virtual void startSound(int nr); virtual void stopSound(int nr); virtual void stopAllSounds(); - virtual bool getSoundStatus(int nr) const; + virtual int getSoundStatus(int nr) const; virtual int getMusicTimer() const; protected: diff --git a/scumm/player_v3a.cpp b/scumm/player_v3a.cpp index 387f74eddc..78c9391f27 100644 --- a/scumm/player_v3a.cpp +++ b/scumm/player_v3a.cpp @@ -294,11 +294,11 @@ int Player_V3A::getMusicTimer() const { return _music_timer / 30; } -bool Player_V3A::getSoundStatus(int nr) const { +int Player_V3A::getSoundStatus(int nr) const { if (nr == _curSong) - return true; + return 1; for (int i = 0; i < V3A_MAXCHANS; i++) if (_soundID[i] == nr) - return true; - return false; + return 1; + return 0; } diff --git a/scumm/player_v3a.h b/scumm/player_v3a.h index 9ba7348395..57f17a8c36 100644 --- a/scumm/player_v3a.h +++ b/scumm/player_v3a.h @@ -45,7 +45,7 @@ public: virtual int getMusicTimer() const; virtual void playMusic(); - virtual bool getSoundStatus(int nr) const; + virtual int getSoundStatus(int nr) const; protected: SoundMixer *_mixer; diff --git a/scumm/resource.cpp b/scumm/resource.cpp index da896700b9..fb3aadfe83 100644 --- a/scumm/resource.cpp +++ b/scumm/resource.cpp @@ -1760,7 +1760,7 @@ bool Scumm::isResourceInUse(int type, int i) const { case rtCostume: return isCostumeInUse(i); case rtSound: - return _sound->isSoundActive(i); + return _sound->isSoundInUse(i); default: return false; } diff --git a/scumm/sound.cpp b/scumm/sound.cpp index 740bcea770..4bedd38202 100644 --- a/scumm/sound.cpp +++ b/scumm/sound.cpp @@ -179,20 +179,30 @@ void Sound::playSound(int soundID) { debug(3, "playSound #%d (room %d)", soundID, _scumm->getResourceRoomNr(rtSound, soundID)); ptr = _scumm->getResourceAddress(rtSound, soundID); if (!ptr) { - // FIXME: Should we replace this by an assert, and/or print an error message? return; } if (READ_UINT32(ptr) == MKID('iMUS')){ - assert(_scumm->_imuseDigital); - _scumm->_imuseDigital->startSound(soundID); + assert(_scumm->_musicEngine); + _scumm->_musicEngine->startSound(soundID); return; } else if (READ_UINT32(ptr) == MKID('Crea')) { - assert(_scumm->_imuseDigital); - _scumm->_imuseDigital->startSound(soundID); + assert(_scumm->_musicEngine); + _scumm->_musicEngine->startSound(soundID); return; } +/* + // XMIDI + else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) { + // Pass XMIDI on to IMuse unprocessed. + // IMuse can handle XMIDI resources now. + } + else if (READ_UINT32(ptr) == MKID('ADL ')) { + // played as MIDI, just to make perhaps the later use + // of WA possible (see "else if" with GF_OLD256 below) + } +*/ else if (READ_UINT32(ptr) == MKID('SOUN')) { ptr += 24; int track = ptr[0]; @@ -258,17 +268,6 @@ void Sound::playSound(int soundID) { return; } -/* - // XMIDI - else if ((READ_UINT32(ptr) == MKID('MIDI')) && (_scumm->_features & GF_HUMONGOUS)) { - // Pass XMIDI on to IMuse unprocessed. - // IMuse can handle XMIDI resources now. - } - else if (READ_UINT32(ptr) == MKID('ADL ')) { - // played as MIDI, just to make perhaps the later use - // of WA possible (see "else if" with GF_OLD256 below) - } -*/ // Support for sampled sound effects in Monkey Island 1 and 2 else if (READ_UINT32(ptr) == MKID('SBL ')) { debug(2, "Using SBL sound effect"); @@ -645,7 +644,6 @@ bool Sound::isMouthSyncOff(uint pos) { int Sound::isSoundRunning(int sound) const { - int i; if (sound == _currentCDSound) return pollCD(); @@ -661,12 +659,6 @@ int Sound::isSoundRunning(int sound) const { } } - i = _soundQue2Pos; - while (i--) { - if (_soundQue2[i] == sound) - return 1; - } - if (isSoundInQueue(sound)) return 1; @@ -688,41 +680,48 @@ int Sound::isSoundRunning(int sound) const { return 0; } -// This is exactly the same as isSoundRunning except that it -// calls IMuse::get_sound_active() instead of IMuse::getSoundStatus(). -// This is necessary when determining what resources to -// expire from memory. -bool Sound::isSoundActive(int sound) const { - int i; +/** + * Check whether the sound resource with the specified ID is still + * used. This is invoked by Scumm::isResourceInUse, to determine + * which resources can be expired from memory. + * Technically, this works very similar to isSoundRunning, however it + * calls IMuse::get_sound_active() instead of IMuse::getSoundStatus(). + * The difference between those two is in how they treat sounds which + * are being faded out: get_sound_active() returns true even when the + * sound is being faded out, while getSoundStatus() returns false in + * that case. + */ +bool Sound::isSoundInUse(int sound) const { if (sound == _currentCDSound) return pollCD() != 0; - i = _soundQue2Pos; - while (i--) { - if (_soundQue2[i] == sound) - return true; - } - if (isSoundInQueue(sound)) return true; if (!_scumm->isResourceLoaded(rtSound, sound)) return false; - if (_scumm->_imuseDigital) { - return _scumm->_imuseDigital->getSoundStatus(sound) != 0; - } + if (_scumm->_imuseDigital) + return _scumm->_imuseDigital->getSoundStatus(sound); - if (!_scumm->_imuse) - return false; - return _scumm->_imuse->get_sound_active(sound); + if (_scumm->_imuse) + return _scumm->_imuse->get_sound_active(sound); + + return false; } bool Sound::isSoundInQueue(int sound) const { - int i = 0, j, num; + int i, j, num; int16 table[16]; + i = _soundQue2Pos; + while (i--) { + if (_soundQue2[i] == sound) + return 1; + } + + i = 0; while (i < _soundQuePos) { num = _soundQue[i++]; diff --git a/scumm/sound.h b/scumm/sound.h index 7bd54ed6cd..9e82d2a6a0 100644 --- a/scumm/sound.h +++ b/scumm/sound.h @@ -125,7 +125,7 @@ public: void stopTalkSound(); bool isMouthSyncOff(uint pos); int isSoundRunning(int sound) const; - bool isSoundActive(int sound) const; + bool isSoundInUse(int sound) const; bool isSoundInQueue(int sound) const; void stopSound(int a); void stopAllSounds(); -- cgit v1.2.3