diff --git a/code/nel/src/sound/driver/openal/listener_al.cpp b/code/nel/src/sound/driver/openal/listener_al.cpp index da7e6bc31..67eaf2478 100644 --- a/code/nel/src/sound/driver/openal/listener_al.cpp +++ b/code/nel/src/sound/driver/openal/listener_al.cpp @@ -145,8 +145,9 @@ void CListenerAL::getOrientation( NLMISC::CVector& front, NLMISC::CVector& u */ void CListenerAL::setGain( float gain ) { - alListenerf( AL_GAIN, gain ); - alTestError(); + CSoundDriverAL::getInstance()->setGain(gain); +// alListenerf( AL_GAIN, gain ); +// alTestError(); } @@ -155,14 +156,15 @@ void CListenerAL::setGain( float gain ) */ float CListenerAL::getGain() const { - ALfloat gain; -#ifdef NL_OS_WINDOWS - alGetListenerf( AL_GAIN, &gain ); -#else - alGetListenerfv( AL_GAIN, &gain ); -#endif - alTestError(); - return gain; + return CSoundDriverAL::getInstance()->getGain(); +// ALfloat gain; +//#ifdef NL_OS_WINDOWS +// alGetListenerf( AL_GAIN, &gain ); +//#else +// alGetListenerfv( AL_GAIN, &gain ); +//#endif +// alTestError(); +// return gain; } diff --git a/code/nel/src/sound/driver/openal/sound_driver_al.cpp b/code/nel/src/sound/driver/openal/sound_driver_al.cpp index 25f8dfa7c..270117c4f 100644 --- a/code/nel/src/sound/driver/openal/sound_driver_al.cpp +++ b/code/nel/src/sound/driver/openal/sound_driver_al.cpp @@ -173,7 +173,7 @@ uint32 NLSOUND_interfaceVersion () */ CSoundDriverAL::CSoundDriverAL(ISoundDriver::IStringMapperProvider *stringMapper) : _StringMapper(stringMapper), _AlDevice(NULL), _AlContext(NULL), -_NbExpBuffers(0), _NbExpSources(0), _RolloffFactor(1.f) +_NbExpBuffers(0), _NbExpSources(0), _RolloffFactor(1.f), _MasterGain(1.f) { alExtInit(); } @@ -698,6 +698,20 @@ void CSoundDriverAL::removeMusicChannel(CMusicChannelAL *musicChannel) else nlwarning("AL: removeMusicChannel already called"); } +/// Set the gain +void CSoundDriverAL::setGain( float gain ) +{ + clamp(gain, 0.f, 1.f); + _MasterGain= gain; + // TODO: update all sources in not using manual rollof ? +} + +/// Get the gain +float CSoundDriverAL::getGain() +{ + return _MasterGain; +} + /// Delete a buffer or a source bool CSoundDriverAL::deleteItem( ALuint name, TDeleteFunctionAL aldeletefunc, vector& names ) { diff --git a/code/nel/src/sound/driver/openal/sound_driver_al.h b/code/nel/src/sound/driver/openal/sound_driver_al.h index 7e0dbf1a8..848637f6c 100644 --- a/code/nel/src/sound/driver/openal/sound_driver_al.h +++ b/code/nel/src/sound/driver/openal/sound_driver_al.h @@ -164,6 +164,17 @@ public: /// (Internal) Remove music channel (should be called by the destructor of the music channel class). void removeMusicChannel(CMusicChannelAL *musicChannel); + /** Set the gain (volume value inside [0 , 1]). (default: 1) + * 0.0 -> silence + * 0.5 -> -6dB + * 1.0 -> no attenuation + * values > 1 (amplification) not supported by most drivers + */ + void setGain( float gain ); + + /// Get the gain + float getGain(); + protected: /// Allocate nb new buffers or sources @@ -182,6 +193,9 @@ protected: /// Delete a buffer or a source bool deleteItem( ALuint name, TDeleteFunctionAL aldeletefunc, std::vector& names ); + + /// Master Volume [0,1] + float _MasterGain; };