aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--engines/sci/sound/audio.cpp4
-rw-r--r--engines/sci/sound/audio.h2
-rw-r--r--engines/sci/sound/music.cpp24
-rw-r--r--engines/sci/sound/music.h6
-rw-r--r--engines/sci/sound/soundcmd.cpp6
5 files changed, 30 insertions, 12 deletions
diff --git a/engines/sci/sound/audio.cpp b/engines/sci/sound/audio.cpp
index 392290853e..8f6667c21e 100644
--- a/engines/sci/sound/audio.cpp
+++ b/engines/sci/sound/audio.cpp
@@ -192,8 +192,8 @@ static byte *readSOLAudio(Common::SeekableReadStream *audioStream, uint32 &size,
return buffer;
}
-Audio::AudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 volume, int *sampleLen) {
- Audio::AudioStream *audioStream = 0;
+Audio::RewindableAudioStream *AudioPlayer::getAudioStream(uint32 number, uint32 volume, int *sampleLen) {
+ Audio::RewindableAudioStream *audioStream = 0;
uint32 size = 0;
byte *data = 0;
byte flags = 0;
diff --git a/engines/sci/sound/audio.h b/engines/sci/sound/audio.h
index d704dfca07..bfd268e30f 100644
--- a/engines/sci/sound/audio.h
+++ b/engines/sci/sound/audio.h
@@ -65,7 +65,7 @@ public:
void setAudioRate(uint16 rate) { _audioRate = rate; }
Audio::SoundHandle *getAudioHandle() { return &_audioHandle; }
- Audio::AudioStream *getAudioStream(uint32 number, uint32 volume, int *sampleLen);
+ Audio::RewindableAudioStream *getAudioStream(uint32 number, uint32 volume, int *sampleLen);
int getAudioPosition();
int startAudio(uint16 module, uint32 tuple);
void stopAudio();
diff --git a/engines/sci/sound/music.cpp b/engines/sci/sound/music.cpp
index 60ac2e4355..6aab6f4b5e 100644
--- a/engines/sci/sound/music.cpp
+++ b/engines/sci/sound/music.cpp
@@ -323,6 +323,8 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) {
delete pSnd->pStreamAud;
pSnd->pStreamAud = Audio::makeLinearInputStream(channelData, track->digitalSampleSize, track->digitalSampleRate,
Audio::Mixer::FLAG_UNSIGNED, 0, 0);
+ delete pSnd->pLoopStream;
+ pSnd->pLoopStream = 0;
pSnd->soundType = Audio::Mixer::kSFXSoundType;
pSnd->hCurrentAud = Audio::SoundHandle();
} else {
@@ -370,13 +372,18 @@ void SciMusic::soundPlay(MusicEntry *pSnd) {
_mutex.unlock(); // unlock to perform mixer-related calls
if (pSnd->pStreamAud && !_pMixer->isSoundHandleActive(pSnd->hCurrentAud)) {
- // Are we supposed to loop the stream?
- if (pSnd->loop > 1)
- pSnd->pStreamAud->setNumLoops(pSnd->loop);
- else
- pSnd->pStreamAud->setNumLoops(1);
- _pMixer->playInputStream(pSnd->soundType, &pSnd->hCurrentAud,
- pSnd->pStreamAud, -1, pSnd->volume, 0, false);
+ if (pSnd->loop > 1) {
+ pSnd->pLoopStream = new Audio::LoopingAudioStream(pSnd->pStreamAud,
+ pSnd->loop, false
+ );
+ _pMixer->playInputStream(pSnd->soundType, &pSnd->hCurrentAud,
+ pSnd->pLoopStream, -1, pSnd->volume, 0,
+ false);
+ } else {
+ _pMixer->playInputStream(pSnd->soundType, &pSnd->hCurrentAud,
+ pSnd->pStreamAud, -1, pSnd->volume, 0,
+ false);
+ }
} else {
_mutex.lock();
if (pSnd->pMidiParser) {
@@ -434,6 +441,8 @@ void SciMusic::soundKill(MusicEntry *pSnd) {
_pMixer->stopHandle(pSnd->hCurrentAud);
delete pSnd->pStreamAud;
pSnd->pStreamAud = NULL;
+ delete pSnd->pLoopStream;
+ pSnd->pLoopStream = 0;
}
_mutex.lock();
@@ -529,6 +538,7 @@ MusicEntry::MusicEntry() {
soundType = Audio::Mixer::kMusicSoundType;
pStreamAud = 0;
+ pLoopStream = 0;
pMidiParser = 0;
}
diff --git a/engines/sci/sound/music.h b/engines/sci/sound/music.h
index 0ff4eb3257..f9c62fd423 100644
--- a/engines/sci/sound/music.h
+++ b/engines/sci/sound/music.h
@@ -104,7 +104,11 @@ public:
//protected:
#endif
MidiParser_SCI *pMidiParser;
- Audio::AudioStream *pStreamAud;
+
+ // TODO: We need to revise how we store the different
+ // audio stream objects we require.
+ Audio::RewindableAudioStream *pStreamAud;
+ Audio::LoopingAudioStream *pLoopStream;
Audio::SoundHandle hCurrentAud;
public:
diff --git a/engines/sci/sound/soundcmd.cpp b/engines/sci/sound/soundcmd.cpp
index f6059724f4..8c61173ed3 100644
--- a/engines/sci/sound/soundcmd.cpp
+++ b/engines/sci/sound/soundcmd.cpp
@@ -804,7 +804,11 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) {
if (musicSlot->pStreamAud) {
// Update digital sound effect slots here
- uint currentLoopCounter = musicSlot->pStreamAud->getNumPlayedLoops();
+ uint currentLoopCounter = 0;
+
+ if (musicSlot->pLoopStream)
+ currentLoopCounter = musicSlot->pLoopStream->getCompleteIterations();
+
if (currentLoopCounter != musicSlot->sampleLoopCounter) {
// during last time we looped at least one time, update loop accordingly
musicSlot->loop -= currentLoopCounter - musicSlot->sampleLoopCounter;