aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFilippos Karapetis2009-12-26 11:54:57 +0000
committerFilippos Karapetis2009-12-26 11:54:57 +0000
commitc6a8d0e97399dc01f1d4263d752adcb73d7a95d2 (patch)
tree1840f782c2554ab98b69a41ca73f490edbc6dcc3
parent8940a1f537af66953bb8d4d32b7a2250744afc19 (diff)
downloadscummvm-rg350-c6a8d0e97399dc01f1d4263d752adcb73d7a95d2.tar.gz
scummvm-rg350-c6a8d0e97399dc01f1d4263d752adcb73d7a95d2.tar.bz2
scummvm-rg350-c6a8d0e97399dc01f1d4263d752adcb73d7a95d2.zip
- Made the music playlist private
- Removed some leaks - Fixed the destruction of the music playlist - Made mutexes more sane - Removed some dead code - Cleanup svn-id: r46578
-rw-r--r--engines/sci/engine/savegame.cpp20
-rw-r--r--engines/sci/sfx/music.cpp47
-rw-r--r--engines/sci/sfx/music.h28
-rw-r--r--engines/sci/sfx/soundcmd.cpp65
4 files changed, 79 insertions, 81 deletions
diff --git a/engines/sci/engine/savegame.cpp b/engines/sci/engine/savegame.cpp
index 9f43957eaf..da116edecf 100644
--- a/engines/sci/engine/savegame.cpp
+++ b/engines/sci/engine/savegame.cpp
@@ -623,21 +623,21 @@ static void sync_songlib(Common::Serializer &s, SciMusic *music) {
// afterwards in gamestate_restore()
int songcount = 0;
if (s.isSaving())
- songcount = music->_playList.size();
+ songcount = music->listSize();
s.syncAsUint32LE(songcount);
if (s.isLoading()) {
music->stopAll();
- music->_playList.resize(songcount);
+ music->resizeList(songcount);
for (int i = 0; i < songcount; i++) {
MusicEntry *curSong = new MusicEntry();
syncSong(s, curSong);
- music->_playList[i] = curSong;
+ music->setSlot(i, curSong);
}
} else {
for (int i = 0; i < songcount; i++) {
- syncSong(s, music->_playList[i]);
+ syncSong(s, music->getSlot(i));
}
}
}
@@ -954,18 +954,18 @@ EngineState *gamestate_restore(EngineState *s, Common::SeekableReadStream *fh) {
#else
// Reconstruct sounds
SciMusic *music = retval->_soundCmd->_music;
- for (uint32 i = 0; i < music->_playList.size(); i++) {
+ for (uint32 i = 0; i < music->listSize(); i++) {
if (meta.savegame_version < 14) {
if (retval->detectDoSoundType() >= SCI_VERSION_1_EARLY) {
- music->_playList[i]->dataInc = GET_SEL32V(retval->_segMan, music->_playList[i]->soundObj, dataInc);
- music->_playList[i]->volume = GET_SEL32V(retval->_segMan, music->_playList[i]->soundObj, vol);
+ music->getSlot(i)->dataInc = GET_SEL32V(retval->_segMan, music->getSlot(i)->soundObj, dataInc);
+ music->getSlot(i)->volume = GET_SEL32V(retval->_segMan, music->getSlot(i)->soundObj, vol);
} else {
- music->_playList[i]->volume = 100;
+ music->getSlot(i)->volume = 100;
}
}
- music->_playList[i]->soundRes = new SoundResource(music->_playList[i]->resnum, retval->resMan, retval->detectDoSoundType());
- music->soundInitSnd(music->_playList[i]);
+ music->getSlot(i)->soundRes = new SoundResource(music->getSlot(i)->resnum, retval->resMan, retval->detectDoSoundType());
+ music->soundInitSnd(music->getSlot(i));
}
#endif
diff --git a/engines/sci/sfx/music.cpp b/engines/sci/sfx/music.cpp
index 63fdc114aa..ebe1d6616e 100644
--- a/engines/sci/sfx/music.cpp
+++ b/engines/sci/sfx/music.cpp
@@ -128,15 +128,12 @@ bool SciMusic::restoreState(Common::InSaveFile *pFile){
}
//----------------------------------------
void SciMusic::stopAll() {
- _mutex.lock();
_pMixer->stopAll();
- for (uint i = 0; i < _playList.size(); i++){
- soundStop(_playList[i]);
- soundKill(_playList[i]);
+ while (!_playList.empty()) {
+ soundStop(_playList[0]);
+ soundKill(_playList[0]);
}
-
- _mutex.unlock();
}
//----------------------------------------
void SciMusic::miditimerCallback(void *p) {
@@ -285,7 +282,6 @@ void SciMusic::loadPatchMT32() {
//----------------------------------------
void SciMusic::soundInitSnd(MusicEntry *pSnd) {
- _mutex.lock();
SoundResource::Track *track = NULL;
int channelFilterMask = 0;
@@ -340,8 +336,6 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
pSnd->pMidiParser->loadMusic(track, pSnd, channelFilterMask, _soundVersion);
}
}
-
- _mutex.unlock();
}
//----------------------------------------
void SciMusic::onTimer() {
@@ -376,8 +370,6 @@ void SciMusic::onTimer() {
}
//---------------------------------------------
void SciMusic::doFade(MusicEntry *pSnd) {
- _mutex.lock();
-
if (pSnd->fadeTicker)
pSnd->fadeTicker--;
else {
@@ -389,21 +381,20 @@ void SciMusic::doFade(MusicEntry *pSnd) {
pSnd->volume += pSnd->fadeStep;
pSnd->pMidiParser->setVolume(pSnd->volume);
}
-
- _mutex.unlock();
}
//---------------------------------------------
void SciMusic::soundPlay(MusicEntry *pSnd) {
- _mutex.lock();
uint sz = _playList.size(), i;
// searching if sound is already in _playList
for (i = 0; i < sz && _playList[i] != pSnd; i++)
;
if (i == sz) {// not found
+ _mutex.lock();
_playList.push_back(pSnd);
sortPlayList();
+ _mutex.unlock();
}
if (pSnd->pStreamAud && !_pMixer->isSoundHandleActive(pSnd->hCurrentAud)) {
@@ -415,31 +406,21 @@ void SciMusic::soundPlay(MusicEntry *pSnd) {
pSnd->pMidiParser->jumpToTick(0);
}
pSnd->status = kSndStatusPlaying;
-
- _mutex.unlock();
}
//---------------------------------------------
void SciMusic::soundStop(MusicEntry *pSnd) {
- _mutex.lock();
-
pSnd->status = kSndStatusStopped;
if (pSnd->pStreamAud)
_pMixer->stopHandle(pSnd->hCurrentAud);
if (pSnd->pMidiParser)
pSnd->pMidiParser->stop();
-
- _mutex.unlock();
}
//---------------------------------------------
void SciMusic::soundSetVolume(MusicEntry *pSnd, byte volume) {
- _mutex.lock();
-
if (pSnd->pStreamAud)
_pMixer->setChannelVolume(pSnd->hCurrentAud, volume);
else if (pSnd->pMidiParser)
pSnd->pMidiParser->setVolume(volume);
-
- _mutex.unlock();
}
//---------------------------------------------
void SciMusic::soundSetPriority(MusicEntry *pSnd, byte prio) {
@@ -453,7 +434,7 @@ void SciMusic::soundSetPriority(MusicEntry *pSnd, byte prio) {
//---------------------------------------------
void SciMusic::soundKill(MusicEntry *pSnd) {
- // For some reason, adding a mutex here freezes some games (e.g. LSL5)
+ _mutex.lock();
pSnd->status = kSndStatusStopped;
if (pSnd->pMidiParser) {
@@ -471,24 +452,22 @@ void SciMusic::soundKill(MusicEntry *pSnd) {
for (i = 0; i < sz; i++) {
if (_playList[i] == pSnd) {
delete _playList[i]->soundRes;
- _playList[i]->soundRes = 0;
+ delete _playList[i];
_playList.remove_at(i);
break;
}
}
+ _mutex.unlock();
+
}
//---------------------------------------------
void SciMusic::soundPause(MusicEntry *pSnd) {
- _mutex.lock();
-
pSnd->status = kSndStatusPaused;
if (pSnd->pStreamAud)
_pMixer->pauseHandle(pSnd->hCurrentAud, true);
else if (pSnd->pMidiParser)
pSnd->pMidiParser->pause();
-
- _mutex.unlock();
}
//---------------------------------------------
@@ -498,16 +477,12 @@ uint16 SciMusic::soundGetMasterVolume() {
}
//---------------------------------------------
void SciMusic::soundSetMasterVolume(uint16 vol) {
- _mutex.lock();
-
vol = vol & 0xF; // 0..15
vol = vol * Audio::Mixer::kMaxMixerVolume / 0xF;
_pMixer->setVolumeForSoundType(Audio::Mixer::kMusicSoundType, vol);
_pMixer->setVolumeForSoundType(Audio::Mixer::kSFXSoundType, vol);
_pMixer->setVolumeForSoundType(Audio::Mixer::kSpeechSoundType, vol);
_pMixer->setVolumeForSoundType(Audio::Mixer::kPlainSoundType, vol);
-
- _mutex.unlock();
}
//---------------------------------------------
@@ -568,7 +543,7 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
if (_signalSet) {
_signalSet = false;
PUT_SEL32V(segMan, _pSnd->soundObj, signal, _signalToSet);
- warning("signal %04x", _signalToSet);
+ debugC(2, kDebugLevelSound, "signal %04x", _signalToSet);
}
info.start = _position._play_pos;
@@ -685,7 +660,7 @@ void MidiParser_SCI::parseNextEvent(EventInfo &info) {
} else {
_pSnd->status = kSndStatusStopped;
PUT_SEL32V(segMan, _pSnd->soundObj, signal, 0xFFFF);
- warning("signal EOT");
+ debugC(2, kDebugLevelSound, "signal EOT");
}
}
break;
diff --git a/engines/sci/sfx/music.h b/engines/sci/sfx/music.h
index 3ea363baa2..f7066743f4 100644
--- a/engines/sci/sfx/music.h
+++ b/engines/sci/sfx/music.h
@@ -110,9 +110,7 @@ public:
bool saveState(Common::OutSaveFile *pFile);
bool restoreState(Common::InSaveFile *pFile);
void stopAll();
- void clearPlaylist() {
- _playList.clear();
- }
+
// sound and midi functions
void soundInitSnd(MusicEntry *pSnd);
void soundPlay(MusicEntry *pSnd);
@@ -136,8 +134,28 @@ public:
return -1;
}
+ MusicEntry *getSlot(int slot) { return _playList[slot]; }
+ void setSlot(uint32 slot, MusicEntry *slotEntry) {
+ _mutex.lock();
+ _playList[slot] = slotEntry;
+ _mutex.unlock();
+ }
+
+ void pushBackSlot(MusicEntry *slotEntry) {
+ _mutex.lock();
+ _playList.push_back(slotEntry);
+ _mutex.unlock();
+ }
+
+ uint32 listSize() { return _playList.size(); }
+
+ void resizeList(uint32 newSize) {
+ _mutex.lock();
+ _playList.resize(newSize);
+ _mutex.unlock();
+ }
+
uint16 _savelen;
- MusicList _playList;
protected:
byte findAudEntry(uint16 nAud, byte&oVolume, uint32& oOffset, uint32&oSize);
@@ -161,6 +179,8 @@ protected:
bool _bMultiMidi; // use adlib's digital track if midi track don't have one
private:
static void miditimerCallback(void *p);
+
+ MusicList _playList;
};
class MidiParser_SCI : public MidiParser {
diff --git a/engines/sci/sfx/soundcmd.cpp b/engines/sci/sfx/soundcmd.cpp
index 0913f627f8..5723ad632b 100644
--- a/engines/sci/sfx/soundcmd.cpp
+++ b/engines/sci/sfx/soundcmd.cpp
@@ -275,7 +275,7 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
// Check if a track with the same sound object is already playing
int prevTrack = _music->findListSlot(obj);
if (prevTrack > -1)
- _music->soundKill(_music->_playList[prevTrack]);
+ _music->soundKill(_music->getSlot(prevTrack));
MusicEntry *newSound = new MusicEntry();
newSound->soundRes = 0;
@@ -295,7 +295,7 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
newSound->fadeTicker = 0;
newSound->fadeTickerStep = 0;
newSound->status = kSndStatusStopped;
- _music->_playList.push_back(newSound);
+ _music->pushBackSlot(newSound);
// In SCI1.1 games, sound effects are started from here. If we can find
// a relevant audio resource, play it, otherwise switch to synthesized
@@ -394,7 +394,7 @@ void SoundCommandParser::cmdPlayHandle(reg_t obj, int16 value) {
int number = obj.segment ? GET_SEL32V(_segMan, obj, number) : -1;
- if (_music->_playList[slot]->resnum != number) { // another sound loaded into struct
+ if (_music->getSlot(slot)->resnum != number) { // another sound loaded into struct
cmdDisposeHandle(obj, value);
cmdInitHandle(obj, value);
// Find slot again :)
@@ -410,14 +410,15 @@ void SoundCommandParser::cmdPlayHandle(reg_t obj, int16 value) {
PUT_SEL32V(_segMan, obj, state, kSndStatusPlaying);
}
- _music->_playList[slot]->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
- _music->_playList[slot]->prio = GET_SEL32V(_segMan, obj, priority);
+ MusicEntry *musicSlot = _music->getSlot(slot);
+ musicSlot->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
+ musicSlot->prio = GET_SEL32V(_segMan, obj, priority);
// vol selector doesnt get used before sci1late
if (_soundVersion < SCI_VERSION_1_LATE)
- _music->_playList[slot]->volume = 100;
+ musicSlot->volume = 100;
else
- _music->_playList[slot]->volume = GET_SEL32V(_segMan, obj, vol);
- _music->soundPlay(_music->_playList[slot]);
+ musicSlot->volume = GET_SEL32V(_segMan, obj, vol);
+ _music->soundPlay(musicSlot);
#endif
@@ -463,7 +464,7 @@ void SoundCommandParser::cmdDisposeHandle(reg_t obj, int16 value) {
cmdStopHandle(obj, value);
- _music->soundKill(_music->_playList[slot]);
+ _music->soundKill(_music->getSlot(slot));
if (_hasNodePtr)
PUT_SEL32(_segMan, obj, nodePtr, NULL_REG);
else
@@ -493,8 +494,8 @@ void SoundCommandParser::cmdStopHandle(reg_t obj, int16 value) {
else
PUT_SEL32V(_segMan, obj, signal, SIGNAL_OFFSET);
- _music->_playList[slot]->dataInc = 0;
- _music->soundStop(_music->_playList[slot]);
+ _music->getSlot(slot)->dataInc = 0;
+ _music->soundStop(_music->getSlot(slot));
#endif
}
@@ -516,12 +517,12 @@ void SoundCommandParser::cmdPauseHandle(reg_t obj, int16 value) {
if (!_hasNodePtr) {
PUT_SEL32V(_segMan, obj, state, kSndStatusPaused);
- _music->soundPause(_music->_playList[slot]);
+ _music->soundPause(_music->getSlot(slot));
} else {
if (value)
- _music->soundPause(_music->_playList[slot]);
+ _music->soundPause(_music->getSlot(slot));
else
- _music->soundPlay(_music->_playList[slot]);
+ _music->soundPlay(_music->getSlot(slot));
}
#endif
}
@@ -542,7 +543,7 @@ void SoundCommandParser::cmdResumeHandle(reg_t obj, int16 value) {
}
PUT_SEL32V(_segMan, obj, state, kSndStatusPlaying);
- _music->soundPlay(_music->_playList[slot]);
+ _music->soundPlay(_music->getSlot(slot));
#endif
}
@@ -619,10 +620,11 @@ void SoundCommandParser::cmdFadeHandle(reg_t obj, int16 value) {
}
int volume = GET_SEL32V(_segMan, obj, vol);
- _music->_playList[slot]->fadeTo = _argv[2].toUint16();
- _music->_playList[slot]->fadeStep = volume > _argv[2].toUint16() ? -_argv[4].toUint16() : _argv[4].toUint16();
- _music->_playList[slot]->fadeTickerStep = _argv[3].toUint16() * 16667 / _music->soundGetTempo();
- _music->_playList[slot]->fadeTicker = 0;
+ MusicEntry *musicSlot = _music->getSlot(slot);
+ musicSlot->fadeTo = _argv[2].toUint16();
+ musicSlot->fadeStep = volume > _argv[2].toUint16() ? -_argv[4].toUint16() : _argv[4].toUint16();
+ musicSlot->fadeTickerStep = _argv[3].toUint16() * 16667 / _music->soundGetTempo();
+ musicSlot->fadeTicker = 0;
#endif
}
@@ -651,13 +653,14 @@ void SoundCommandParser::cmdUpdateHandle(reg_t obj, int16 value) {
return;
}
- _music->_playList[slot]->loop = (GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0);
+ MusicEntry *musicSlot = _music->getSlot(slot);
+ musicSlot->loop = (GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0);
uint32 objVol = CLIP<int>(GET_SEL32V(_segMan, obj, vol), 0, 255);
- if (objVol != _music->_playList[slot]->volume)
- _music->soundSetVolume(_music->_playList[slot], objVol);
+ if (objVol != musicSlot->volume)
+ _music->soundSetVolume(musicSlot, objVol);
uint32 objPrio = GET_SEL32V(_segMan, obj, vol);
- if (objPrio != _music->_playList[slot]->prio)
- _music->soundSetPriority(_music->_playList[slot], objPrio);
+ if (objPrio != musicSlot->prio)
+ _music->soundSetPriority(musicSlot, objPrio);
#endif
}
@@ -745,7 +748,7 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) {
}
uint16 signal = GET_SEL32V(_segMan, obj, signal);
- uint16 dataInc = _music->_playList[slot]->dataInc;
+ uint16 dataInc = _music->getSlot(slot)->dataInc;
switch (signal) {
case 0:
@@ -761,7 +764,7 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) {
break;
}
- uint16 ticker = _music->_playList[slot]->ticker;
+ uint16 ticker = _music->getSlot(slot)->ticker;
PUT_SEL32V(_segMan, obj, min, ticker / 3600);
PUT_SEL32V(_segMan, obj, sec, ticker % 3600 / 60);
PUT_SEL32V(_segMan, obj, frame, ticker);
@@ -816,9 +819,9 @@ void SoundCommandParser::cmdSetHandleVolume(reg_t obj, int16 value) {
value = CLIP<int>(value, 0, Audio::Mixer::kMaxChannelVolume);
- if (_music->_playList[slot]->volume != value) {
- _music->_playList[slot]->volume = value;
- _music->soundSetVolume(_music->_playList[slot], value);
+ if (_music->getSlot(slot)->volume != value) {
+ _music->getSlot(slot)->volume = value;
+ _music->soundSetVolume(_music->getSlot(slot), value);
PUT_SEL32V(_segMan, obj, vol, value);
}
#endif
@@ -864,10 +867,10 @@ void SoundCommandParser::cmdSetHandleLoop(reg_t obj, int16 value) {
return;
}
if (value == -1) {
- _music->_playList[slot]->loop = 1;
+ _music->getSlot(slot)->loop = 1;
PUT_SEL32V(_segMan, obj, loop, 0xFFFF);
} else {
- _music->_playList[slot]->loop = 0;
+ _music->getSlot(slot)->loop = 0;
PUT_SEL32V(_segMan, obj, loop, 1);
}
#endif