EMI: Remap volumes from the range 0-100 to the range 0-255 for the audio mixer.

This commit is contained in:
Joni Vähämäki 2014-08-14 17:01:05 +03:00
parent d5355e6713
commit 029b57e3ab
2 changed files with 9 additions and 5 deletions

View File

@ -53,9 +53,9 @@ class EMISound {
public:
EMISound(int fps);
~EMISound();
bool startVoice(const Common::String &soundName, int volume = 127, int pan = 64);
bool startSfx(const Common::String &soundName, int volume = 127, int pan = 64);
bool startSfxFrom(const Common::String &soundName, const Math::Vector3d &pos, int volume = 127);
bool startVoice(const Common::String &soundName, int volume = 100, int pan = 64);
bool startSfx(const Common::String &soundName, int volume = 100, int pan = 64);
bool startSfxFrom(const Common::String &soundName, const Math::Vector3d &pos, int volume = 100);
bool getSoundStatus(const Common::String &soundName);
void stopSound(const Common::String &soundName);
int32 getPosIn16msTicks(const Common::String &soundName);

View File

@ -39,7 +39,7 @@ SoundTrack::SoundTrack() {
_paused = false;
_positioned = false;
_balance = 0;
_volume = Audio::Mixer::kMaxChannelVolume;
_volume = 100;
_disposeAfterPlaying = DisposeAfterUse::YES;
_sync = 0;
_fadeMode = FadeNone;
@ -64,6 +64,9 @@ void SoundTrack::setSoundName(const Common::String &name) {
}
void SoundTrack::setVolume(int volume) {
if (volume > 100) {
volume = 100;
}
_volume = volume;
if (_handle) {
g_system->getMixer()->setChannelVolume(*_handle, (byte)getEffectiveVolume());
@ -146,7 +149,8 @@ void SoundTrack::setFade(float fade) {
}
int SoundTrack::getEffectiveVolume() {
return _volume * _attenuation * _fade;
int mixerVolume = _volume * Audio::Mixer::kMaxChannelVolume / 100;
return mixerVolume * _attenuation * _fade;
}
} // end of namespace Grim