1
0
mirror of https://github.com/rwengine/openrw.git synced 2024-11-22 02:12:45 +01:00

Implement basic sound volume managment

Basic of basics. :P
This commit is contained in:
Filip Gawin 2018-09-22 22:22:54 +02:00 committed by Daniel Evans
parent a813837040
commit d1c31952b5
2 changed files with 29 additions and 1 deletions

View File

@ -210,6 +210,8 @@ bool SoundManager::isPaused(const std::string& name) {
void SoundManager::playSound(const std::string& name) {
auto sound = sounds.find(name);
if (sound != sounds.end()) {
auto vol = getCalculatedVolumeOfMusic();
sound->second.setGain(vol);
return sound->second.play();
}
}
@ -224,7 +226,7 @@ void SoundManager::playSfx(size_t name, const glm::vec3& position, bool looping,
}
buffer->second.setPitch(1.f);
buffer->second.setGain(1.f);
buffer->second.setGain(getCalculatedVolumeOfEffects());
if (maxDist != -1) {
buffer->second.setMaxDistance(static_cast<float>(maxDist));
}
@ -322,3 +324,16 @@ void SoundManager::setSoundPosition(const std::string& name,
position.y, position.z));
}
}
void SoundManager::setVolume(float vol) {
_volume = vol;
}
float SoundManager::getCalculatedVolumeOfEffects() const {
return _volume * _effectsVolume;
}
float SoundManager::getCalculatedVolumeOfMusic() const {
return _volume * _musicVolume;
}

View File

@ -85,6 +85,10 @@ public:
void pause(bool p);
void setVolume(float vol);
float getCalculatedVolumeOfEffects() const;
float getCalculatedVolumeOfMusic() const;
private:
bool initializeOpenAL();
void initializeAVCodec();
@ -106,6 +110,15 @@ private:
GameWorld* _engine;
LoaderSDT sdt{};
/// Sound volume
float _volume = 1.f;
/// Multiplier for effects
float _effectsVolume = 0.2f;
/// Multiplier for music and cutscenes audio
float _musicVolume = 1.f;
};
#endif