Added support for changing the master SFX volume.
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/irrlicht@3384 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
3ffcce3351
commit
e1f93c4527
@ -43,6 +43,7 @@ public:
|
|||||||
virtual void pause() = 0;
|
virtual void pause() = 0;
|
||||||
virtual void resume() = 0;
|
virtual void resume() = 0;
|
||||||
virtual void speed(float factor) = 0;
|
virtual void speed(float factor) = 0;
|
||||||
|
virtual void volume(float gain) = 0;
|
||||||
virtual SFXManager::SFXStatus
|
virtual SFXManager::SFXStatus
|
||||||
getStatus() = 0;
|
getStatus() = 0;
|
||||||
}; // SfxBase
|
}; // SfxBase
|
||||||
|
@ -44,6 +44,7 @@ SFXManager::SFXManager()
|
|||||||
{
|
{
|
||||||
// The sound manager initialises OpenAL
|
// The sound manager initialises OpenAL
|
||||||
m_initialized = sound_manager->initialized();
|
m_initialized = sound_manager->initialized();
|
||||||
|
m_masterGain = 1.0f;
|
||||||
m_sfx_buffers.resize(NUM_SOUNDS);
|
m_sfx_buffers.resize(NUM_SOUNDS);
|
||||||
m_sfx_positional.resize(NUM_SOUNDS);
|
m_sfx_positional.resize(NUM_SOUNDS);
|
||||||
m_sfx_rolloff.resize(NUM_SOUNDS);
|
m_sfx_rolloff.resize(NUM_SOUNDS);
|
||||||
@ -207,7 +208,8 @@ SFXBase *SFXManager::newSFX(SFXType id)
|
|||||||
if(race_manager->getNumLocalPlayers() < 2)
|
if(race_manager->getNumLocalPlayers() < 2)
|
||||||
positional = m_sfx_positional[id]!=0;
|
positional = m_sfx_positional[id]!=0;
|
||||||
|
|
||||||
SFXBase *p=new SFXOpenAL(m_sfx_buffers[id], positional, m_sfx_rolloff[id], m_sfx_gain[id]);
|
SFXBase *p = new SFXOpenAL(m_sfx_buffers[id], positional, m_sfx_rolloff[id], m_sfx_gain[id]);
|
||||||
|
p->volume(m_masterGain);
|
||||||
m_all_sfx.push_back(p);
|
m_all_sfx.push_back(p);
|
||||||
return p;
|
return p;
|
||||||
} // newSFX
|
} // newSFX
|
||||||
@ -261,7 +263,7 @@ void SFXManager::resumeAll()
|
|||||||
} // for i in m_all_sfx
|
} // for i in m_all_sfx
|
||||||
} // resumeAll
|
} // resumeAll
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool SFXManager::checkError(const std::string &context)
|
bool SFXManager::checkError(const std::string &context)
|
||||||
{
|
{
|
||||||
// Check (and clear) the error flag
|
// Check (and clear) the error flag
|
||||||
@ -276,6 +278,24 @@ bool SFXManager::checkError(const std::string &context)
|
|||||||
return true;
|
return true;
|
||||||
} // checkError
|
} // checkError
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void SFXManager::setMasterSFXVolume(float gain)
|
||||||
|
{
|
||||||
|
if(gain > 1.0)
|
||||||
|
gain = 1.0f;
|
||||||
|
if(gain < 0.0f)
|
||||||
|
gain = 0.0f;
|
||||||
|
|
||||||
|
m_masterGain = gain;
|
||||||
|
|
||||||
|
for(std::vector<SFXBase*>::iterator i=m_all_sfx.begin();
|
||||||
|
i!=m_all_sfx.end(); i++)
|
||||||
|
{
|
||||||
|
(*i)->volume(m_masterGain);
|
||||||
|
} // for i in m_all_sfx
|
||||||
|
|
||||||
|
} // setMasterSFXVolume
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
const std::string SFXManager::getErrorString(int err)
|
const std::string SFXManager::getErrorString(int err)
|
||||||
{
|
{
|
||||||
|
@ -68,6 +68,7 @@ private:
|
|||||||
std::vector<float> m_sfx_gain;
|
std::vector<float> m_sfx_gain;
|
||||||
std::vector<SFXBase*> m_all_sfx;
|
std::vector<SFXBase*> m_all_sfx;
|
||||||
bool m_initialized;
|
bool m_initialized;
|
||||||
|
float m_masterGain;
|
||||||
void loadSfx();
|
void loadSfx();
|
||||||
void loadSingleSfx(const lisp::Lisp *lisp,
|
void loadSingleSfx(const lisp::Lisp *lisp,
|
||||||
const char *name,
|
const char *name,
|
||||||
@ -80,6 +81,7 @@ public:
|
|||||||
void deleteSFX(SFXBase *sfx);
|
void deleteSFX(SFXBase *sfx);
|
||||||
void pauseAll();
|
void pauseAll();
|
||||||
void resumeAll();
|
void resumeAll();
|
||||||
|
void setMasterSFXVolume(float gain);
|
||||||
static bool checkError(const std::string &context);
|
static bool checkError(const std::string &context);
|
||||||
static const std::string getErrorString(int err);
|
static const std::string getErrorString(int err);
|
||||||
};
|
};
|
||||||
|
@ -43,6 +43,7 @@ SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain)
|
|||||||
m_soundSource = 0;
|
m_soundSource = 0;
|
||||||
m_ok = false;
|
m_ok = false;
|
||||||
m_positional = false;
|
m_positional = false;
|
||||||
|
m_defaultGain = gain;
|
||||||
|
|
||||||
alGenSources(1, &m_soundSource );
|
alGenSources(1, &m_soundSource );
|
||||||
if(!SFXManager::checkError("generating a source")) return;
|
if(!SFXManager::checkError("generating a source")) return;
|
||||||
@ -52,7 +53,7 @@ SFXOpenAL::SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain)
|
|||||||
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
|
alSource3f(m_soundSource, AL_VELOCITY, 0.0, 0.0, 0.0);
|
||||||
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
alSource3f(m_soundSource, AL_DIRECTION, 0.0, 0.0, 0.0);
|
||||||
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
|
alSourcef (m_soundSource, AL_ROLLOFF_FACTOR, rolloff );
|
||||||
alSourcef (m_soundSource, AL_GAIN, gain );
|
alSourcef (m_soundSource, AL_GAIN, m_defaultGain);
|
||||||
if(positional)
|
if(positional)
|
||||||
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
alSourcei (m_soundSource, AL_SOURCE_RELATIVE, AL_FALSE);
|
||||||
else
|
else
|
||||||
@ -89,6 +90,18 @@ void SFXOpenAL::speed(float factor)
|
|||||||
SFXManager::checkError("changing the speed");
|
SFXManager::checkError("changing the speed");
|
||||||
} // speed
|
} // speed
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
/** Changes the volume of a sound effect.
|
||||||
|
* \param gain Volume adjustment between 0.0 (mute) and 1.0 (full volume).
|
||||||
|
*/
|
||||||
|
void SFXOpenAL::volume(float gain)
|
||||||
|
{
|
||||||
|
if(!m_ok) return;
|
||||||
|
|
||||||
|
alSourcef(m_soundSource, AL_GAIN, m_defaultGain * gain);
|
||||||
|
SFXManager::checkError("setting volume");
|
||||||
|
} // volume
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
/** Loops this sound effect.
|
/** Loops this sound effect.
|
||||||
*/
|
*/
|
||||||
|
@ -36,6 +36,7 @@ private:
|
|||||||
ALuint m_soundSource; // Sources are points emitting sound.
|
ALuint m_soundSource; // Sources are points emitting sound.
|
||||||
bool m_ok;
|
bool m_ok;
|
||||||
bool m_positional;
|
bool m_positional;
|
||||||
|
float m_defaultGain;
|
||||||
public:
|
public:
|
||||||
SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain);
|
SFXOpenAL(ALuint buffer, bool positional, float rolloff, float gain);
|
||||||
virtual ~SFXOpenAL();
|
virtual ~SFXOpenAL();
|
||||||
@ -46,6 +47,7 @@ public:
|
|||||||
virtual void resume();
|
virtual void resume();
|
||||||
virtual void speed(float factor);
|
virtual void speed(float factor);
|
||||||
virtual void position(const Vec3 &position);
|
virtual void position(const Vec3 &position);
|
||||||
|
virtual void volume(float gain);
|
||||||
virtual SFXManager::SFXStatus getStatus();
|
virtual SFXManager::SFXStatus getStatus();
|
||||||
|
|
||||||
}; // SFXOpenAL
|
}; // SFXOpenAL
|
||||||
|
Loading…
x
Reference in New Issue
Block a user