aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Dupont2010-10-10 21:12:10 +0000
committerSylvain Dupont2010-10-10 21:12:10 +0000
commitaa89bbbcbd8764a5fd7a6d64e902b3b293384f4f (patch)
tree9e6375b43defa78965abcc7dc2f10ba3058a13b0
parent23aa94ec0273058e7fc1d826a654970d2dc71df7 (diff)
downloadscummvm-rg350-aa89bbbcbd8764a5fd7a6d64e902b3b293384f4f.tar.gz
scummvm-rg350-aa89bbbcbd8764a5fd7a6d64e902b3b293384f4f.tar.bz2
scummvm-rg350-aa89bbbcbd8764a5fd7a6d64e902b3b293384f4f.zip
TOON: Music attenuation when someone talks
svn-id: r53130
-rw-r--r--engines/toon/audio.cpp37
-rw-r--r--engines/toon/audio.h4
2 files changed, 38 insertions, 3 deletions
diff --git a/engines/toon/audio.cpp b/engines/toon/audio.cpp
index 192265de85..a0633c7f86 100644
--- a/engines/toon/audio.cpp
+++ b/engines/toon/audio.cpp
@@ -203,6 +203,8 @@ AudioStreamInstance::AudioStreamInstance(AudioManager *man, Audio::Mixer *mixer,
_currentReadSize = 8;
_man = man;
_looping = looping;
+ _musicAttenuation = 1000;
+
// preload one packet
if (_totalSize > 0) {
_file->skip(8);
@@ -341,6 +343,8 @@ void AudioStreamInstance::play(bool fade, Audio::Mixer::SoundType soundType) {
_stopped = false;
_fadingIn = fade;
_fadeTime = 0;
+ _soundType = soundType;
+ _musicAttenuation = 1000; // max volume
_mixer->playStream(soundType, &_handle, this);
handleFade(0);
}
@@ -348,6 +352,12 @@ void AudioStreamInstance::play(bool fade, Audio::Mixer::SoundType soundType) {
void AudioStreamInstance::handleFade(int numSamples) {
debugC(5, kDebugAudio, "handleFade(%d)", numSamples);
+ // Fading enabled only for music
+ if (_soundType != Audio::Mixer::kMusicSoundType)
+ return;
+
+ int32 finalVolume = _volume;
+
if (_fadingOut) {
_fadeTime += numSamples;
@@ -356,8 +366,7 @@ void AudioStreamInstance::handleFade(int numSamples) {
stopNow();
_fadingOut = false;
}
-
- _mixer->setChannelVolume(_handle, _volume - _fadeTime * _volume / 40960);
+ finalVolume = _volume - _fadeTime * _volume / 40960;
} else {
if (_fadingIn) {
_fadeTime += numSamples;
@@ -366,9 +375,25 @@ void AudioStreamInstance::handleFade(int numSamples) {
_fadingIn = false;
}
- _mixer->setChannelVolume(_handle, _volume * _fadeTime / 40960);
+ finalVolume = _volume * _fadeTime / 40960;
}
}
+
+ // the music is too loud when someone is talking
+ // smoothing to avoid big volume changes
+ if (_man->voiceStillPlaying()) {
+ _musicAttenuation -= numSamples >> 4;
+ if (_musicAttenuation < 250)
+ _musicAttenuation = 250;
+ } else {
+ _musicAttenuation += numSamples >> 5;
+ if (_musicAttenuation > 1000)
+ _musicAttenuation = 1000;
+ }
+
+
+ _mixer->setChannelVolume(_handle, finalVolume * _musicAttenuation / 1000);
+
}
void AudioStreamInstance::stop(bool fade /*= false*/) {
@@ -400,6 +425,10 @@ AudioStreamPackage::AudioStreamPackage(ToonEngine *vm) : _vm(vm) {
_indexBuffer = 0;
}
+AudioStreamPackage::~AudioStreamPackage() {
+ delete [] _indexBuffer;
+}
+
bool AudioStreamPackage::loadAudioPackage(Common::String indexFile, Common::String streamFile) {
debugC(4, kDebugAudio, "loadAudioPackage(%s, %s)", indexFile.c_str(), streamFile.c_str());
@@ -408,6 +437,8 @@ bool AudioStreamPackage::loadAudioPackage(Common::String indexFile, Common::Stri
if (!fileData)
return false;
+ delete[] _indexBuffer;
+
_indexBuffer = new uint32[size / 4];
memcpy(_indexBuffer, fileData, size);
diff --git a/engines/toon/audio.h b/engines/toon/audio.h
index ae46531817..5a8274e086 100644
--- a/engines/toon/audio.h
+++ b/engines/toon/audio.h
@@ -81,6 +81,7 @@ protected:
int32 _bufferOffset;
int32 _compBufferSize;
Audio::SoundHandle _handle;
+ Audio::Mixer::SoundType _soundType;
Audio::Mixer *_mixer;
int32 _lastADPCMval1;
int32 _lastADPCMval2;
@@ -90,12 +91,15 @@ protected:
int32 _currentReadSize;
bool _looping;
int32 _volume;
+ int32 _musicAttenuation;
};
class AudioStreamPackage {
public:
AudioStreamPackage(ToonEngine *vm);
+ ~AudioStreamPackage();
+
bool loadAudioPackage(Common::String indexFile, Common::String streamFile);
void getInfo(int32 id, int32 *offset, int32 *size);
Common::SeekableReadStream *getStream(int32 id, bool ownMemory = false);