From 0a965ced69bbc28ce16e9ae4e80a74a60f95a5e1 Mon Sep 17 00:00:00 2001 From: Martin Kiewitz Date: Fri, 1 Jan 2010 22:15:52 +0000 Subject: SCI/newmusic: changed setting volume from fade logic, implemented updating loop selector for sound fx svn-id: r46856 --- engines/sci/sfx/music.cpp | 11 ++++++----- engines/sci/sfx/music.h | 2 ++ engines/sci/sfx/soundcmd.cpp | 14 +++++++++++--- 3 files changed, 19 insertions(+), 8 deletions(-) (limited to 'engines/sci/sfx') diff --git a/engines/sci/sfx/music.cpp b/engines/sci/sfx/music.cpp index 8a5f55f7c0..01771935c0 100644 --- a/engines/sci/sfx/music.cpp +++ b/engines/sci/sfx/music.cpp @@ -359,9 +359,8 @@ void SciMusic::soundInitSnd(MusicEntry *pSnd) { void SciMusic::onTimer() { const MusicList::iterator end = _playList.end(); - for (MusicList::iterator i = _playList.begin(); i != end; ++i) { + for (MusicList::iterator i = _playList.begin(); i != end; ++i) (*i)->onTimer(_soundVersion); - } } void SciMusic::soundPlay(MusicEntry *pSnd) { @@ -521,11 +520,13 @@ MusicEntry::MusicEntry() { hold = 0; pauseCounter = 0; + sampleLoopCounter = 0; fadeTo = 0; fadeStep = 0; fadeTicker = 0; fadeTickerStep = 0; + fadeVolumeSet = false; status = kSoundStopped; @@ -542,6 +543,7 @@ void MusicEntry::onTimer(SciVersion soundVersion) { if (status != kSoundPlaying) return; + // Fade MIDI and digital sound effects if (fadeStep) doFade(); @@ -569,9 +571,8 @@ void MusicEntry::doFade() { // Only process MIDI streams in this thread, not digital sound effects if (pMidiParser) pMidiParser->setVolume(volume); - // TODO: create onTimer within audio.cpp to do the handling there, if we do it in cmdUpdateCues it wont - // work right, because the last volume set won't get done at all. Also we are fading digital sound effects - // currently here in any case currently. Fade code should get moved to void SciMusic::onTimer() + if (pStreamAud) + fadeVolumeSet = true; // set flag so that SoundCommandParser::cmdUpdateCues will set the volume of the stream } } diff --git a/engines/sci/sfx/music.h b/engines/sci/sfx/music.h index f1202ab822..a1458b234c 100644 --- a/engines/sci/sfx/music.h +++ b/engines/sci/sfx/music.h @@ -87,11 +87,13 @@ public: byte hold; int16 pauseCounter; + uint sampleLoopCounter; byte fadeTo; short fadeStep; uint32 fadeTicker; uint32 fadeTickerStep; + bool fadeVolumeSet; SoundStatus status; diff --git a/engines/sci/sfx/soundcmd.cpp b/engines/sci/sfx/soundcmd.cpp index 12c909493b..3c1f9b62ef 100644 --- a/engines/sci/sfx/soundcmd.cpp +++ b/engines/sci/sfx/soundcmd.cpp @@ -775,7 +775,12 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) { Audio::Mixer *mixer = g_system->getMixer(); if (musicSlot->pStreamAud) { - + uint currentLoopCounter = musicSlot->pStreamAud->getNumPlayedLoops(); + if (currentLoopCounter != musicSlot->sampleLoopCounter) { + // during last time we looped at least one time, update loop accordingly + musicSlot->loop -= currentLoopCounter - musicSlot->sampleLoopCounter; + musicSlot->sampleLoopCounter = currentLoopCounter; + } // TODO: We need to update loop selector here, when sample is looping if (!mixer->isSoundHandleActive(musicSlot->hCurrentAud)) { musicSlot->ticker = SIGNAL_OFFSET; @@ -784,8 +789,11 @@ void SoundCommandParser::cmdUpdateCues(reg_t obj, int16 value) { } else { musicSlot->ticker = (uint16)(mixer->getSoundElapsedTime(musicSlot->hCurrentAud) * 0.06); } - if (musicSlot->fadeStep) - mixer->setChannelVolume(musicSlot->hCurrentAud, musicSlot->volume); + // We get a flag from MusicEntry::doFade() here to set volume for the stream + if (musicSlot->fadeVolumeSet) { + mixer->setChannelVolume(musicSlot->hCurrentAud, musicSlot->volume); + musicSlot->fadeVolumeSet = false; + } } _music->_mutex.lock(); // and lock again -- cgit v1.2.3