aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/sfx
diff options
context:
space:
mode:
Diffstat (limited to 'engines/sci/sfx')
-rw-r--r--engines/sci/sfx/music.cpp45
-rw-r--r--engines/sci/sfx/music.h27
-rw-r--r--engines/sci/sfx/soundcmd.cpp11
3 files changed, 57 insertions, 26 deletions
diff --git a/engines/sci/sfx/music.cpp b/engines/sci/sfx/music.cpp
index 8d2beff59f..83dc0b26a9 100644
--- a/engines/sci/sfx/music.cpp
+++ b/engines/sci/sfx/music.cpp
@@ -37,10 +37,6 @@
namespace Sci {
-static int f_compare(const void *arg1, const void *arg2) {
- return ((const MusicEntry *)arg2)->prio - ((const MusicEntry *)arg1)->prio;
-}
-
SciMusic::SciMusic(SciVersion soundVersion)
: _soundVersion(soundVersion), _soundOn(true), _inCriticalSection(false) {
@@ -115,19 +111,20 @@ void SciMusic::clearPlayList() {
void SciMusic::stopAll() {
SegManager *segMan = ((SciEngine *)g_engine)->getEngineState()->_segMan; // HACK
- for (uint32 i = 0; i < _playList.size(); i++) {
+ const MusicList::iterator end = _playList.end();
+ for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
if (_soundVersion <= SCI_VERSION_0_LATE)
- PUT_SEL32V(segMan, _playList[i]->soundObj, state, kSoundStopped);
+ PUT_SEL32V(segMan, (*i)->soundObj, state, kSoundStopped);
else
- PUT_SEL32V(segMan, _playList[i]->soundObj, signal, SIGNAL_OFFSET);
+ PUT_SEL32V(segMan, (*i)->soundObj, signal, SIGNAL_OFFSET);
- _playList[i]->dataInc = 0;
- soundStop(_playList[i]);
+ (*i)->dataInc = 0;
+ soundStop(*i);
}
}
void SciMusic::miditimerCallback(void *p) {
- SciMusic* aud = (SciMusic *)p;
+ SciMusic *aud = (SciMusic *)p;
aud->onTimer();
}
@@ -146,6 +143,10 @@ uint16 SciMusic::soundGetVoices() {
}
}
+static int f_compare(const void *arg1, const void *arg2) {
+ return ((const MusicEntry *)arg2)->prio - ((const MusicEntry *)arg1)->prio;
+}
+
void SciMusic::sortPlayList() {
MusicEntry ** pData = _playList.begin();
qsort(pData, _playList.size(), sizeof(MusicEntry *), &f_compare);
@@ -495,4 +496,28 @@ void SciMusic::reconstructPlayList(int savegame_version) {
}
}
+
+MusicEntry::MusicEntry() {
+ soundObj = NULL_REG;
+
+ soundRes = 0;
+ resnum = 0;
+
+ dataInc = 0;
+ ticker = 0;
+ prio = 0;
+ loop = 0;
+ volume = 0;
+
+ fadeTo = 0;
+ fadeStep = 0;
+ fadeTicker = 0;
+ fadeTickerStep = 0;
+
+ status = kSoundStopped;
+
+ pStreamAud = 0;
+ pMidiParser = 0;
+}
+
} // End of namespace Sci
diff --git a/engines/sci/sfx/music.h b/engines/sci/sfx/music.h
index cb220cc25a..e2d195c54f 100644
--- a/engines/sci/sfx/music.h
+++ b/engines/sci/sfx/music.h
@@ -58,7 +58,12 @@ enum SoundStatus {
class MidiParser_SCI;
-struct MusicEntry {
+class MusicEntry
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+ : public Common::Serializable
+#endif
+{
+public:
reg_t soundObj;
SoundResource *soundRes;
@@ -75,10 +80,21 @@ struct MusicEntry {
uint32 fadeTicker;
uint32 fadeTickerStep;
+ SoundStatus status;
+
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+//protected:
+#endif
MidiParser_SCI *pMidiParser;
Audio::AudioStream* pStreamAud;
Audio::SoundHandle hCurrentAud;
- SoundStatus status;
+
+public:
+ MusicEntry();
+
+#ifndef USE_OLD_MUSIC_FUNCTIONS
+ virtual void saveLoadWithSerializer(Common::Serializer &ser);
+#endif
};
typedef Common::Array<MusicEntry *> MusicList;
@@ -120,9 +136,10 @@ public:
uint32 soundGetTempo() const { return _dwTempo; }
MusicEntry *getSlot(reg_t obj) {
- for (uint32 i = 0; i < _playList.size(); i++) {
- if (_playList[i]->soundObj == obj) {
- return _playList[i];
+ const MusicList::iterator end = _playList.end();
+ for (MusicList::iterator i = _playList.begin(); i != end; ++i) {
+ if ((*i)->soundObj == obj) {
+ return *i;
}
}
diff --git a/engines/sci/sfx/soundcmd.cpp b/engines/sci/sfx/soundcmd.cpp
index f7ed18968b..b85067b17f 100644
--- a/engines/sci/sfx/soundcmd.cpp
+++ b/engines/sci/sfx/soundcmd.cpp
@@ -283,7 +283,6 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
#ifndef USE_OLD_MUSIC_FUNCTIONS
MusicEntry *newSound = new MusicEntry();
- newSound->soundRes = 0;
newSound->resnum = number;
if (number && _resMan->testResource(ResourceId(kResourceTypeSound, number)))
newSound->soundRes = new SoundResource(number, _resMan, _soundVersion);
@@ -291,15 +290,6 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
newSound->loop = GET_SEL32V(_segMan, obj, loop) == 0xFFFF ? 1 : 0;
newSound->prio = GET_SEL32V(_segMan, obj, pri) & 0xFF;
newSound->volume = CLIP<int>(GET_SEL32V(_segMan, obj, vol), 0, Audio::Mixer::kMaxChannelVolume);
- newSound->dataInc = 0;
- newSound->pStreamAud = 0;
- newSound->pMidiParser = 0;
- newSound->ticker = 0;
- newSound->fadeTo = 0;
- newSound->fadeStep = 0;
- newSound->fadeTicker = 0;
- newSound->fadeTickerStep = 0;
- newSound->status = kSoundStopped;
// Check if a track with the same sound object is already playing
MusicEntry *oldSound = _music->getSlot(obj);
@@ -317,7 +307,6 @@ void SoundCommandParser::cmdInitHandle(reg_t obj, int16 value) {
// Found a relevant audio resource, play it
int sampleLen;
newSound->pStreamAud = _audio->getAudioStream(number, 65535, &sampleLen);
- newSound->hCurrentAud = Audio::SoundHandle();
} else {
if (newSound->soundRes)
_music->soundInitSnd(newSound);