[Scummvm-cvs-logs] SF.net SVN: scummvm:[47033] scummvm/trunk/sound/mixer.cpp
lordhoto at users.sourceforge.net
lordhoto at users.sourceforge.net
Tue Jan 5 20:52:32 CET 2010
Revision: 47033
http://scummvm.svn.sourceforge.net/scummvm/?rev=47033&view=rev
Author: lordhoto
Date: 2010-01-05 19:52:32 +0000 (Tue, 05 Jan 2010)
Log Message:
-----------
- Do not calculate left/right channel volume every SimpleChannel::mix call anymore, but do it once
- Notify a channel, when it's channel volume type changed from inside MixerImpl::setVolumeForSoundType
Modified Paths:
--------------
scummvm/trunk/sound/mixer.cpp
Modified: scummvm/trunk/sound/mixer.cpp
===================================================================
--- scummvm/trunk/sound/mixer.cpp 2010-01-05 19:52:12 UTC (rev 47032)
+++ scummvm/trunk/sound/mixer.cpp 2010-01-05 19:52:32 UTC (rev 47033)
@@ -58,8 +58,9 @@
void pause(bool paused);
bool isPaused() const { return (_pauseLevel != 0); }
- void setVolume(const byte volume) { _volume = volume; }
- void setBalance(const int8 balance) { _balance = balance; }
+ void setVolume(const byte volume);
+ void setBalance(const int8 balance);
+ void notifyGlobalVolChange() { updateChannelVolumes(); }
uint32 getElapsedTime();
@@ -75,11 +76,18 @@
int _pauseLevel;
int _id;
-protected:
- Mixer *_mixer;
byte _volume;
int8 _balance;
+ void updateChannelVolumes();
+ st_volume_t _volL, _volR;
+
+protected:
+ st_volume_t getLeftVolume() const { return _volL; }
+ st_volume_t getRightVolume() const { return _volR; }
+
+ Mixer *_mixer;
+
uint32 _samplesConsumed;
uint32 _samplesDecoded;
uint32 _mixerTimeStamp;
@@ -372,7 +380,13 @@
// TODO: Maybe we should do logarithmic (not linear) volume
// scaling? See also Player_V2::setMasterVolume
+ Common::StackLock lock(_mutex);
_volumeForSoundType[type] = volume;
+
+ for (int i = 0; i != NUM_CHANNELS; ++i) {
+ if (_channels[i] && _channels[i]->getType() == type)
+ _channels[i]->notifyGlobalVolChange();
+ }
}
int MixerImpl::getVolumeForSoundType(SoundType type) const {
@@ -390,8 +404,42 @@
: _type(type), _mixer(mixer), _id(id), _permanent(permanent), _volume(Mixer::kMaxChannelVolume),
_balance(0), _pauseLevel(0), _samplesConsumed(0), _samplesDecoded(0), _mixerTimeStamp(0),
_pauseStartTime(0), _pauseTime(0) {
+ updateChannelVolumes();
}
+void Channel::setVolume(const byte volume) {
+ _volume = volume;
+ updateChannelVolumes();
+}
+
+void Channel::setBalance(const int8 balance) {
+ _balance = balance;
+ updateChannelVolumes();
+}
+
+void Channel::updateChannelVolumes() {
+ // From the channel balance/volume and the global volume, we compute
+ // the effective volume for the left and right channel. Note the
+ // slightly odd divisor: the 255 reflects the fact that the maximal
+ // value for _volume is 255, while the 127 is there because the
+ // balance value ranges from -127 to 127. The mixer (music/sound)
+ // volume is in the range 0 - kMaxMixerVolume.
+ // Hence, the vol_l/vol_r values will be in that range, too
+
+ int vol = _mixer->getVolumeForSoundType(_type) * _volume;
+
+ if (_balance == 0) {
+ _volL = vol / Mixer::kMaxChannelVolume;
+ _volR = vol / Mixer::kMaxChannelVolume;
+ } else if (_balance < 0) {
+ _volL = vol / Mixer::kMaxChannelVolume;
+ _volR = ((127 + _balance) * vol) / (Mixer::kMaxChannelVolume * 127);
+ } else {
+ _volL = ((127 - _balance) * vol) / (Mixer::kMaxChannelVolume * 127);
+ _volR = vol / Mixer::kMaxChannelVolume;
+ }
+}
+
void Channel::pause(bool paused) {
//assert((paused && _pauseLevel >= 0) || (!paused && _pauseLevel));
@@ -467,32 +515,10 @@
} else {
assert(_converter);
- // From the channel balance/volume and the global volume, we compute
- // the effective volume for the left and right channel. Note the
- // slightly odd divisor: the 255 reflects the fact that the maximal
- // value for _volume is 255, while the 127 is there because the
- // balance value ranges from -127 to 127. The mixer (music/sound)
- // volume is in the range 0 - kMaxMixerVolume.
- // Hence, the vol_l/vol_r values will be in that range, too
-
- int vol = _mixer->getVolumeForSoundType(getType()) * _volume;
- st_volume_t vol_l, vol_r;
-
- if (_balance == 0) {
- vol_l = vol / Mixer::kMaxChannelVolume;
- vol_r = vol / Mixer::kMaxChannelVolume;
- } else if (_balance < 0) {
- vol_l = vol / Mixer::kMaxChannelVolume;
- vol_r = ((127 + _balance) * vol) / (Mixer::kMaxChannelVolume * 127);
- } else {
- vol_l = ((127 - _balance) * vol) / (Mixer::kMaxChannelVolume * 127);
- vol_r = vol / Mixer::kMaxChannelVolume;
- }
-
_samplesConsumed = _samplesDecoded;
_mixerTimeStamp = g_system->getMillis();
_pauseTime = 0;
- _samplesDecoded += _converter->flow(*_input, data, len, vol_l, vol_r);
+ _samplesDecoded += _converter->flow(*_input, data, len, getLeftVolume(), getRightVolume());
}
}
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