mirror of
https://port.numenaute.org/aleajactaest/khanat-code-old.git
synced 2024-11-05 23:09:02 +00:00
Changed: #1459 Simplify the sound group controller interface
This commit is contained in:
parent
beae63c1a0
commit
77c3ccb1e1
8 changed files with 47 additions and 41 deletions
|
@ -58,8 +58,10 @@ private:
|
||||||
CGroupController *m_Parent;
|
CGroupController *m_Parent;
|
||||||
std::map<std::string, CGroupController *> m_Children;
|
std::map<std::string, CGroupController *> m_Children;
|
||||||
|
|
||||||
float m_DevGain;
|
/// Gain as set by the interface
|
||||||
float m_UserGain;
|
float m_Gain;
|
||||||
|
|
||||||
|
/// Gain including parent gain
|
||||||
float m_FinalGain;
|
float m_FinalGain;
|
||||||
|
|
||||||
int m_NbSourcesInclChild;
|
int m_NbSourcesInclChild;
|
||||||
|
@ -70,13 +72,8 @@ public:
|
||||||
|
|
||||||
/// \name UGroupController
|
/// \name UGroupController
|
||||||
//@{
|
//@{
|
||||||
virtual void setDevGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_DevGain = gain; updateSourceGain(); }
|
virtual void setGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); if (m_Gain != gain) { m_Gain = gain; updateSourceGain(); } }
|
||||||
virtual float getDevGain() { return m_DevGain; }
|
virtual float getGain() { return m_Gain; }
|
||||||
|
|
||||||
virtual void setUserGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_UserGain = gain; updateSourceGain(); }
|
|
||||||
virtual float getUserGain() { return m_UserGain; }
|
|
||||||
|
|
||||||
virtual void setGain(float devGain, float userGain) { NLMISC::clamp(devGain, 0.0f, 1.0f); NLMISC::clamp(userGain, 0.0f, 1.0f); m_DevGain = devGain; m_UserGain = userGain; updateSourceGain(); }
|
|
||||||
//@}
|
//@}
|
||||||
|
|
||||||
inline float getFinalGain() const { return m_FinalGain; }
|
inline float getFinalGain() const { return m_FinalGain; }
|
||||||
|
@ -90,7 +87,7 @@ protected:
|
||||||
virtual ~CGroupController(); // subnodes can only be deleted by the root
|
virtual ~CGroupController(); // subnodes can only be deleted by the root
|
||||||
|
|
||||||
private:
|
private:
|
||||||
inline float calculateTotalGain() { return m_DevGain * m_UserGain; }
|
inline float calculateTotalGain() { return m_Gain; }
|
||||||
virtual void calculateFinalGain();
|
virtual void calculateFinalGain();
|
||||||
virtual void increaseSources();
|
virtual void increaseSources();
|
||||||
virtual void decreaseSources();
|
virtual void decreaseSources();
|
||||||
|
|
|
@ -35,9 +35,9 @@
|
||||||
|
|
||||||
// Project includes
|
// Project includes
|
||||||
|
|
||||||
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "effects"
|
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "sound:effects:game"
|
||||||
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "music"
|
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "sound:music:game"
|
||||||
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "dialog"
|
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "sound:dialog:game"
|
||||||
|
|
||||||
namespace NLSOUND {
|
namespace NLSOUND {
|
||||||
|
|
||||||
|
@ -50,13 +50,8 @@ namespace NLSOUND {
|
||||||
class UGroupController
|
class UGroupController
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual void setDevGain(float gain) = 0;
|
virtual void setGain(float gain) = 0;
|
||||||
virtual float getDevGain() = 0;
|
virtual float getGain() = 0;
|
||||||
|
|
||||||
virtual void setUserGain(float gain) = 0;
|
|
||||||
virtual float getUserGain() = 0;
|
|
||||||
|
|
||||||
virtual void setGain(float devGain, float userGain) = 0;
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual ~UGroupController() { }
|
virtual ~UGroupController() { }
|
||||||
|
|
|
@ -106,7 +106,7 @@ static void initSample()
|
||||||
// s_Source->setSourceRelativeMode(true);
|
// s_Source->setSourceRelativeMode(true);
|
||||||
// s_Source->setPitch(2.0f);
|
// s_Source->setPitch(2.0f);
|
||||||
|
|
||||||
s_GroupController = s_AudioMixer->getGroupController("dialog");
|
s_GroupController = s_AudioMixer->getGroupController("sound:dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
static void runSample()
|
static void runSample()
|
||||||
|
@ -129,10 +129,10 @@ static void runSample()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
case '+':
|
case '+':
|
||||||
s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f);
|
s_GroupController->setGain(s_GroupController->getGain() + 0.1f);
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f);
|
s_GroupController->setGain(s_GroupController->getGain() - 0.1f);
|
||||||
break;
|
break;
|
||||||
case 'x':
|
case 'x':
|
||||||
s_Source->stop();
|
s_Source->stop();
|
||||||
|
|
|
@ -100,7 +100,7 @@ static void initSample()
|
||||||
s_StreamSource->setFormat(s_AudioDecoder->getChannels(), s_AudioDecoder->getBitsPerSample(), (uint32)s_AudioDecoder->getSamplesPerSec());
|
s_StreamSource->setFormat(s_AudioDecoder->getChannels(), s_AudioDecoder->getBitsPerSample(), (uint32)s_AudioDecoder->getSamplesPerSec());
|
||||||
//s_StreamSource->setPitch(2.0f);
|
//s_StreamSource->setPitch(2.0f);
|
||||||
|
|
||||||
s_GroupController = s_AudioMixer->getGroupController("dialog");
|
s_GroupController = s_AudioMixer->getGroupController("sound:dialog");
|
||||||
}
|
}
|
||||||
|
|
||||||
//CMutex *s_Mutex = NULL;
|
//CMutex *s_Mutex = NULL;
|
||||||
|
@ -154,10 +154,10 @@ static void runSample()
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
case '+':
|
case '+':
|
||||||
s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f);
|
s_GroupController->setGain(s_GroupController->getGain() + 0.1f);
|
||||||
break;
|
break;
|
||||||
case '-':
|
case '-':
|
||||||
s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f);
|
s_GroupController->setGain(s_GroupController->getGain() - 0.1f);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -42,7 +42,7 @@ using namespace std;
|
||||||
namespace NLSOUND {
|
namespace NLSOUND {
|
||||||
|
|
||||||
CGroupController::CGroupController(CGroupController *parent) :
|
CGroupController::CGroupController(CGroupController *parent) :
|
||||||
m_Parent(parent), m_DevGain(1.0f), m_UserGain(1.0f), m_NbSourcesInclChild(0)
|
m_Parent(parent), m_Gain(1.0f), m_NbSourcesInclChild(0)
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -81,9 +81,7 @@ std::string CGroupController::getPath() // overridden by root
|
||||||
if (it->second == this)
|
if (it->second == this)
|
||||||
{
|
{
|
||||||
const std::string &name = it->first;
|
const std::string &name = it->first;
|
||||||
std::string returnPath = m_Parent->getPath() + "/" + name;
|
std::string returnPath = m_Parent->getPath() + ":" + name;
|
||||||
if (returnPath[0] == '/')
|
|
||||||
returnPath = returnPath.substr(1);
|
|
||||||
return returnPath;
|
return returnPath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -39,6 +39,8 @@
|
||||||
using namespace std;
|
using namespace std;
|
||||||
// using namespace NLMISC;
|
// using namespace NLMISC;
|
||||||
|
|
||||||
|
#define NLSOUND_GROUP_CONTROLLER_ROOT_PATH "sound"
|
||||||
|
|
||||||
namespace NLSOUND {
|
namespace NLSOUND {
|
||||||
|
|
||||||
CGroupControllerRoot::CGroupControllerRoot() : CGroupController(NULL)
|
CGroupControllerRoot::CGroupControllerRoot() : CGroupController(NULL)
|
||||||
|
@ -53,7 +55,8 @@ CGroupControllerRoot::~CGroupControllerRoot()
|
||||||
|
|
||||||
std::string CGroupControllerRoot::getPath()
|
std::string CGroupControllerRoot::getPath()
|
||||||
{
|
{
|
||||||
return "";
|
// The root node is always called sound
|
||||||
|
return NLSOUND_GROUP_CONTROLLER_ROOT_PATH;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CGroupControllerRoot::calculateFinalGain()
|
void CGroupControllerRoot::calculateFinalGain()
|
||||||
|
@ -78,9 +81,13 @@ void CGroupControllerRoot::decreaseSources()
|
||||||
CGroupController *CGroupControllerRoot::getGroupController(const std::string &path)
|
CGroupController *CGroupControllerRoot::getGroupController(const std::string &path)
|
||||||
{
|
{
|
||||||
std::vector<std::string> pathNodes;
|
std::vector<std::string> pathNodes;
|
||||||
NLMISC::splitString(NLMISC::toLower(path), "/", pathNodes);
|
NLMISC::splitString(NLMISC::toLower(path), ":", pathNodes);
|
||||||
CGroupController *active = this;
|
CGroupController *active = this;
|
||||||
for (std::vector<std::string>::iterator it(pathNodes.begin()), end(pathNodes.end()); it != end; ++it)
|
if (pathNodes[0] != NLSOUND_GROUP_CONTROLLER_ROOT_PATH)
|
||||||
|
{
|
||||||
|
nlerror("Root node for group controller must always be 'sound', invalid group '%s' requested", path.c_str());
|
||||||
|
}
|
||||||
|
for (std::vector<std::string>::iterator it(pathNodes.begin() + 1), end(pathNodes.end()); it != end; ++it)
|
||||||
{
|
{
|
||||||
if (!(*it).empty())
|
if (!(*it).empty())
|
||||||
{
|
{
|
||||||
|
|
|
@ -107,6 +107,8 @@ enum TFilterMapping
|
||||||
//-----------------------------------------------
|
//-----------------------------------------------
|
||||||
CSoundManager::CSoundManager(IProgressCallback * /* progressCallBack */)
|
CSoundManager::CSoundManager(IProgressCallback * /* progressCallBack */)
|
||||||
: _AudioMixer(NULL),
|
: _AudioMixer(NULL),
|
||||||
|
_GroupControllerEffects(NULL),
|
||||||
|
_GroupControllerEffectsGame(NULL),
|
||||||
_EnvSoundRoot(NULL),
|
_EnvSoundRoot(NULL),
|
||||||
_UserEntitySoundLevel(1.0f),
|
_UserEntitySoundLevel(1.0f),
|
||||||
_Sources(NULL)
|
_Sources(NULL)
|
||||||
|
@ -139,6 +141,7 @@ CSoundManager::~CSoundManager()
|
||||||
NL3D::UParticleSystemSound::setPSSound(NULL);
|
NL3D::UParticleSystemSound::setPSSound(NULL);
|
||||||
|
|
||||||
_GroupControllerEffects = NULL;
|
_GroupControllerEffects = NULL;
|
||||||
|
_GroupControllerEffectsGame = NULL;
|
||||||
|
|
||||||
// free the audio mixer (and delete all sources)
|
// free the audio mixer (and delete all sources)
|
||||||
delete _AudioMixer;
|
delete _AudioMixer;
|
||||||
|
@ -407,6 +410,7 @@ void CSoundManager::reset ()
|
||||||
NL3D::UParticleSystemSound::setPSSound(NULL);
|
NL3D::UParticleSystemSound::setPSSound(NULL);
|
||||||
|
|
||||||
_GroupControllerEffects = NULL;
|
_GroupControllerEffects = NULL;
|
||||||
|
_GroupControllerEffectsGame = NULL;
|
||||||
|
|
||||||
delete _AudioMixer;
|
delete _AudioMixer;
|
||||||
_AudioMixer = NULL;
|
_AudioMixer = NULL;
|
||||||
|
@ -482,7 +486,8 @@ void CSoundManager::init(IProgressCallback *progressCallBack)
|
||||||
new CSoundAnimManager(_AudioMixer);
|
new CSoundAnimManager(_AudioMixer);
|
||||||
|
|
||||||
// get the controller group for effects
|
// get the controller group for effects
|
||||||
_GroupControllerEffects = _AudioMixer->getGroupController("effects");
|
_GroupControllerEffects = _AudioMixer->getGroupController("sound:effects");
|
||||||
|
_GroupControllerEffectsGame = _AudioMixer->getGroupController("sound:effects:game");
|
||||||
|
|
||||||
// restore the volume
|
// restore the volume
|
||||||
SoundMngr->setSFXVolume(ClientCfg.SoundSFXVolume);
|
SoundMngr->setSFXVolume(ClientCfg.SoundSFXVolume);
|
||||||
|
@ -1543,7 +1548,8 @@ void CSoundManager::updateVolume()
|
||||||
_AudioMixer->setEventMusicVolume(_GameMusicVolume);
|
_AudioMixer->setEventMusicVolume(_GameMusicVolume);
|
||||||
|
|
||||||
// update sfx volume
|
// update sfx volume
|
||||||
_GroupControllerEffects->setGain(_FadeSFXVolume, _SFXVolume);
|
_GroupControllerEffects->setGain(_SFXVolume);
|
||||||
|
_GroupControllerEffectsGame->setGain(_FadeSFXVolume);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -332,9 +332,12 @@ private:
|
||||||
/// Pointer on the audio mixer object
|
/// Pointer on the audio mixer object
|
||||||
NLSOUND::UAudioMixer *_AudioMixer;
|
NLSOUND::UAudioMixer *_AudioMixer;
|
||||||
|
|
||||||
/// The root effects group controller for volume settings
|
/// The root effects group controller for effects volume settings by the user
|
||||||
NLSOUND::UGroupController *_GroupControllerEffects;
|
NLSOUND::UGroupController *_GroupControllerEffects;
|
||||||
|
|
||||||
|
/// The root effects group controller for effects fading by the game
|
||||||
|
NLSOUND::UGroupController *_GroupControllerEffectsGame;
|
||||||
|
|
||||||
/// Pointer on the root of the environmental sounds tree (if any)
|
/// Pointer on the root of the environmental sounds tree (if any)
|
||||||
NLSOUND::UEnvSound *_EnvSoundRoot;
|
NLSOUND::UEnvSound *_EnvSoundRoot;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue