diff options
author | Torbjörn Andersson | 2004-01-14 08:06:56 +0000 |
---|---|---|
committer | Torbjörn Andersson | 2004-01-14 08:06:56 +0000 |
commit | b17d77eae9a90a160727935eabdca162823cdc10 (patch) | |
tree | d12e6085d2d1f48b396a2d2477d6ded43b692d77 | |
parent | 4746920c74887c9fff9910e6d39881db3879dd52 (diff) | |
download | scummvm-rg350-b17d77eae9a90a160727935eabdca162823cdc10.tar.gz scummvm-rg350-b17d77eae9a90a160727935eabdca162823cdc10.tar.bz2 scummvm-rg350-b17d77eae9a90a160727935eabdca162823cdc10.zip |
Changed the music fading so that volume is increased when ABS(_fading)
grows larger, both when fading up or down. This fixes the problem where the
volume would "jump" when changing the fading "direction" of a stream.
Also changed the logic for deciding which music stream to stop if both
streams are playing and a third stream is started. Before it always tried
to pick the one that was fading down. Now it will pick the one with the
lowest volume, assuming that the more faded a stream is the lower its
volume.
Together, this should fix some abrupt music changes at the watchman's hut,
where it would sometimes start two music streams in rapid succession.
svn-id: r12372
-rw-r--r-- | sword2/driver/d_sound.cpp | 29 |
1 files changed, 22 insertions, 7 deletions
diff --git a/sword2/driver/d_sound.cpp b/sword2/driver/d_sound.cpp index 5a15aed16f..2a2a442896 100644 --- a/sword2/driver/d_sound.cpp +++ b/sword2/driver/d_sound.cpp @@ -141,7 +141,7 @@ void MusicHandle::fadeUp(void) { if (_fading > 0) _fading = -_fading; else if (_fading == 0) - _fading = -FADE_SAMPLES; + _fading = -1; } int32 MusicHandle::play(const char *filename, uint32 musicId, bool looping) { @@ -221,8 +221,10 @@ int MusicHandle::readBuffer(int16 *buffer, const int numSamples) { } out = (out * _fading) / FADE_SAMPLES; } else if (_fading < 0) { - _fading++; - out = (out * (FADE_SAMPLES + _fading)) / FADE_SAMPLES; + _fading--; + out = -(out * _fading) / FADE_SAMPLES; + if (_fading == -FADE_SAMPLES) + _fading = 0; } } @@ -420,14 +422,27 @@ int32 Sound::streamCompMusic(const char *filename, uint32 musicId, bool looping) int32 primaryStream = -1; int32 secondaryStream = -1; - // If both music streams are playing, that should mean one of them is - // fading out. Pick that one, and stop it completely. + // If both music streams are playing, one of them will have to go. if (_music[0]._streaming && _music[1]._streaming) { - if (_music[0]._fading > 0) + if (_music[0]._fading == 0 && _music[1]._fading == 0) { + // None of them are fading. This shouldn't happen, so + // just pick one and be done with it. primaryStream = 0; - else + } else if (_music[0]._fading != 0 && _music[1]._fading == 0) { + // Stream 0 is fading, so pick that one. + primaryStream = 0; + } else if (_music[0]._fading == 0 && _music[1]._fading > 0) { + // Stream 1 is fading, so pick that one. primaryStream = 1; + } else { + // Both streams are fading. Pick the one that is + // closest to silent. + if (ABS(_music[0]._fading) < ABS(_music[1]._fading)) + primaryStream = 0; + else + primaryStream = 1; + } _music[primaryStream].stop(); } |