aboutsummaryrefslogtreecommitdiff
path: root/engines
diff options
context:
space:
mode:
authorsylvaintv2011-03-06 17:54:03 +0100
committersylvaintv2011-03-06 17:54:03 +0100
commit95a1624f6d6091d143a6f203b9083f96df152871 (patch)
tree97921a7df71e4d51dedf9c8398334d9eb9bcc292 /engines
parentbc73a6bd76140e4ff83d83388a60c4411b69476d (diff)
downloadscummvm-rg350-95a1624f6d6091d143a6f203b9083f96df152871.tar.gz
scummvm-rg350-95a1624f6d6091d143a6f203b9083f96df152871.tar.bz2
scummvm-rg350-95a1624f6d6091d143a6f203b9083f96df152871.zip
TOON: Improve music fading between rooms
Diffstat (limited to 'engines')
-rw-r--r--engines/toon/audio.cpp46
-rw-r--r--engines/toon/audio.h5
2 files changed, 31 insertions, 20 deletions
diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp
index e5e5b85832..3fd89d5f91 100644
--- a/engines/toon/audio.cpp
+++ b/engines/toon/audio.cpp
@@ -63,6 +63,8 @@ AudioManager::AudioManager(ToonEngine *vm, Audio::Mixer *mixer) : _vm(vm), _mixe
_voiceMuted = false;
_musicMuted = false;
_sfxMuted = false;
+
+ _currentMusicChannel = 0;
}
AudioManager::~AudioManager(void) {
@@ -113,24 +115,23 @@ void AudioManager::playMusic(Common::String dir, Common::String music) {
return;
// see what channel to take
- if (_channels[0] && _channels[0]->isPlaying() && _channels[1] && _channels[1]->isPlaying()) {
- // take the one that is fading
- if (_channels[0]->isFading()) {
- _channels[0]->stop(false);
- _channels[1]->stop(true);
- _currentMusicChannel = 0;
- } else {
- _channels[1]->stop(false);
- _channels[0]->stop(true);
- _currentMusicChannel = 1;
+ // if the current channel didn't really start. reuse this one
+ if (_channels[_currentMusicChannel] && _channels[_currentMusicChannel]->isPlaying()) {
+ if (_channels[_currentMusicChannel]->getPlayedSampleCount() < 500) {
+ _channels[_currentMusicChannel]->stop(false);
+ _currentMusicChannel = 1 - _currentMusicChannel;
}
- } else if (_channels[0] && _channels[0]->isPlaying()) {
- _channels[0]->stop(true);
- _currentMusicChannel = 1;
- } else {
- if (_channels[1] && _channels[1]->isPlaying())
- _channels[1]->stop(true);
- _currentMusicChannel = 0;
+ else
+ {
+ _channels[_currentMusicChannel]->stop(true);
+ }
+ }
+ // go to the next channel
+ _currentMusicChannel = 1 - _currentMusicChannel;
+
+ // if it's already playing.. stop it quickly (no fade)
+ if (_channels[_currentMusicChannel] && _channels[_currentMusicChannel]->isPlaying()) {
+ _channels[_currentMusicChannel]->stop(false);
}
// no need to delete instance here it will automatically deleted by the mixer is done with it
@@ -261,6 +262,7 @@ AudioStreamInstance::AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer,
_looping = looping;
_musicAttenuation = 1000;
_deleteFileStream = deleteFileStreamAtEnd;
+ _playedSamples = 0;
// preload one packet
if (_totalSize > 0) {
@@ -309,6 +311,8 @@ int AudioStreamInstance::readBuffer(int16 *buffer, const int numSamples) {
_bufferOffset += leftSamples;
}
+ _playedSamples += numSamples;
+
return numSamples;
}
@@ -468,9 +472,11 @@ void AudioStreamInstance::stop(bool fade /*= false*/) {
debugC(1, kDebugAudio, "stop(%d)", (fade) ? 1 : 0);
if (fade) {
- _fadingIn = false;
- _fadingOut = true;
- _fadeTime = 0;
+ if (!_fadingOut) {
+ _fadingIn = false;
+ _fadingOut = true;
+ _fadeTime = 0;
+ }
} else {
stopNow();
}
diff --git a/engines/toon/audio.h b/engines/toon/audio.h
index 7c1eedfee9..19e4d9a354 100644
--- a/engines/toon/audio.h
+++ b/engines/toon/audio.h
@@ -52,6 +52,10 @@ public:
return _fadingIn || _fadingOut;
}
+ int32 getPlayedSampleCount() {
+ return _playedSamples;
+ }
+
void setVolume(int32 volume);
protected:
int readBuffer(int16 *buffer, const int numSamples);
@@ -93,6 +97,7 @@ protected:
int32 _volume;
int32 _musicAttenuation;
bool _deleteFileStream;
+ int32 _playedSamples;
};
class AudioStreamPackage {