[Scummvm-cvs-logs] SF.net SVN: scummvm:[53130] scummvm/trunk/engines/toon
sylvaintv at users.sourceforge.net
sylvaintv at users.sourceforge.net
Sun Oct 10 23:12:10 CEST 2010
Revision: 53130
http://scummvm.svn.sourceforge.net/scummvm/?rev=53130&view=rev
Author: sylvaintv
Date: 2010-10-10 21:12:10 +0000 (Sun, 10 Oct 2010)
Log Message:
-----------
TOON: Music attenuation when someone talks
Modified Paths:
--------------
scummvm/trunk/engines/toon/audio.cpp
scummvm/trunk/engines/toon/audio.h
Modified: scummvm/trunk/engines/toon/audio.cpp
===================================================================
--- scummvm/trunk/engines/toon/audio.cpp 2010-10-10 20:30:36 UTC (rev 53129)
+++ scummvm/trunk/engines/toon/audio.cpp 2010-10-10 21:12:10 UTC (rev 53130)
@@ -203,6 +203,8 @@
_currentReadSize = 8;
_man = man;
_looping = looping;
+ _musicAttenuation = 1000;
+
// preload one packet
if (_totalSize > 0) {
_file->skip(8);
@@ -341,6 +343,8 @@
_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::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 @@
stopNow();
_fadingOut = false;
}
-
- _mixer->setChannelVolume(_handle, _volume - _fadeTime * _volume / 40960);
+ finalVolume = _volume - _fadeTime * _volume / 40960;
} else {
if (_fadingIn) {
_fadeTime += numSamples;
@@ -366,9 +375,25 @@
_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 @@
_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 @@
if (!fileData)
return false;
+ delete[] _indexBuffer;
+
_indexBuffer = new uint32[size / 4];
memcpy(_indexBuffer, fileData, size);
Modified: scummvm/trunk/engines/toon/audio.h
===================================================================
--- scummvm/trunk/engines/toon/audio.h 2010-10-10 20:30:36 UTC (rev 53129)
+++ scummvm/trunk/engines/toon/audio.h 2010-10-10 21:12:10 UTC (rev 53130)
@@ -81,6 +81,7 @@
int32 _bufferOffset;
int32 _compBufferSize;
Audio::SoundHandle _handle;
+ Audio::Mixer::SoundType _soundType;
Audio::Mixer *_mixer;
int32 _lastADPCMval1;
int32 _lastADPCMval2;
@@ -90,12 +91,15 @@
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);
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Scummvm-git-logs
mailing list