Changed: #1459 Simplify the sound group controller interface

This commit is contained in:
kaetemi 2012-04-13 11:54:20 +02:00
parent beae63c1a0
commit 77c3ccb1e1
8 changed files with 47 additions and 41 deletions

View file

@ -58,8 +58,10 @@ private:
CGroupController *m_Parent;
std::map<std::string, CGroupController *> m_Children;
float m_DevGain;
float m_UserGain;
/// Gain as set by the interface
float m_Gain;
/// Gain including parent gain
float m_FinalGain;
int m_NbSourcesInclChild;
@ -70,13 +72,8 @@ public:
/// \name UGroupController
//@{
virtual void setDevGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); m_DevGain = gain; updateSourceGain(); }
virtual float getDevGain() { return m_DevGain; }
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(); }
virtual void setGain(float gain) { NLMISC::clamp(gain, 0.0f, 1.0f); if (m_Gain != gain) { m_Gain = gain; updateSourceGain(); } }
virtual float getGain() { return m_Gain; }
//@}
inline float getFinalGain() const { return m_FinalGain; }
@ -90,7 +87,7 @@ protected:
virtual ~CGroupController(); // subnodes can only be deleted by the root
private:
inline float calculateTotalGain() { return m_DevGain * m_UserGain; }
inline float calculateTotalGain() { return m_Gain; }
virtual void calculateFinalGain();
virtual void increaseSources();
virtual void decreaseSources();

View file

@ -35,9 +35,9 @@
// Project includes
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "effects"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "music"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "dialog"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER "sound:effects:game"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER "sound:music:game"
#define NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER "sound:dialog:game"
namespace NLSOUND {
@ -50,13 +50,8 @@ namespace NLSOUND {
class UGroupController
{
public:
virtual void setDevGain(float gain) = 0;
virtual float getDevGain() = 0;
virtual void setUserGain(float gain) = 0;
virtual float getUserGain() = 0;
virtual void setGain(float devGain, float userGain) = 0;
virtual void setGain(float gain) = 0;
virtual float getGain() = 0;
protected:
virtual ~UGroupController() { }

View file

@ -106,7 +106,7 @@ static void initSample()
// s_Source->setSourceRelativeMode(true);
// s_Source->setPitch(2.0f);
s_GroupController = s_AudioMixer->getGroupController("dialog");
s_GroupController = s_AudioMixer->getGroupController("sound:dialog");
}
static void runSample()
@ -129,10 +129,10 @@ static void runSample()
#endif
{
case '+':
s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f);
s_GroupController->setGain(s_GroupController->getGain() + 0.1f);
break;
case '-':
s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f);
s_GroupController->setGain(s_GroupController->getGain() - 0.1f);
break;
case 'x':
s_Source->stop();

View file

@ -100,7 +100,7 @@ static void initSample()
s_StreamSource->setFormat(s_AudioDecoder->getChannels(), s_AudioDecoder->getBitsPerSample(), (uint32)s_AudioDecoder->getSamplesPerSec());
//s_StreamSource->setPitch(2.0f);
s_GroupController = s_AudioMixer->getGroupController("dialog");
s_GroupController = s_AudioMixer->getGroupController("sound:dialog");
}
//CMutex *s_Mutex = NULL;
@ -154,10 +154,10 @@ static void runSample()
#endif
{
case '+':
s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f);
s_GroupController->setGain(s_GroupController->getGain() + 0.1f);
break;
case '-':
s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f);
s_GroupController->setGain(s_GroupController->getGain() - 0.1f);
break;
default:
return;

View file

@ -42,7 +42,7 @@ using namespace std;
namespace NLSOUND {
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)
{
const std::string &name = it->first;
std::string returnPath = m_Parent->getPath() + "/" + name;
if (returnPath[0] == '/')
returnPath = returnPath.substr(1);
std::string returnPath = m_Parent->getPath() + ":" + name;
return returnPath;
}
}

View file

@ -39,6 +39,8 @@
using namespace std;
// using namespace NLMISC;
#define NLSOUND_GROUP_CONTROLLER_ROOT_PATH "sound"
namespace NLSOUND {
CGroupControllerRoot::CGroupControllerRoot() : CGroupController(NULL)
@ -53,7 +55,8 @@ CGroupControllerRoot::~CGroupControllerRoot()
std::string CGroupControllerRoot::getPath()
{
return "";
// The root node is always called sound
return NLSOUND_GROUP_CONTROLLER_ROOT_PATH;
}
void CGroupControllerRoot::calculateFinalGain()
@ -78,9 +81,13 @@ void CGroupControllerRoot::decreaseSources()
CGroupController *CGroupControllerRoot::getGroupController(const std::string &path)
{
std::vector<std::string> pathNodes;
NLMISC::splitString(NLMISC::toLower(path), "/", pathNodes);
NLMISC::splitString(NLMISC::toLower(path), ":", pathNodes);
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())
{

View file

@ -107,6 +107,8 @@ enum TFilterMapping
//-----------------------------------------------
CSoundManager::CSoundManager(IProgressCallback * /* progressCallBack */)
: _AudioMixer(NULL),
_GroupControllerEffects(NULL),
_GroupControllerEffectsGame(NULL),
_EnvSoundRoot(NULL),
_UserEntitySoundLevel(1.0f),
_Sources(NULL)
@ -139,6 +141,7 @@ CSoundManager::~CSoundManager()
NL3D::UParticleSystemSound::setPSSound(NULL);
_GroupControllerEffects = NULL;
_GroupControllerEffectsGame = NULL;
// free the audio mixer (and delete all sources)
delete _AudioMixer;
@ -407,6 +410,7 @@ void CSoundManager::reset ()
NL3D::UParticleSystemSound::setPSSound(NULL);
_GroupControllerEffects = NULL;
_GroupControllerEffectsGame = NULL;
delete _AudioMixer;
_AudioMixer = NULL;
@ -482,7 +486,8 @@ void CSoundManager::init(IProgressCallback *progressCallBack)
new CSoundAnimManager(_AudioMixer);
// get the controller group for effects
_GroupControllerEffects = _AudioMixer->getGroupController("effects");
_GroupControllerEffects = _AudioMixer->getGroupController("sound:effects");
_GroupControllerEffectsGame = _AudioMixer->getGroupController("sound:effects:game");
// restore the volume
SoundMngr->setSFXVolume(ClientCfg.SoundSFXVolume);
@ -1543,7 +1548,8 @@ void CSoundManager::updateVolume()
_AudioMixer->setEventMusicVolume(_GameMusicVolume);
// update sfx volume
_GroupControllerEffects->setGain(_FadeSFXVolume, _SFXVolume);
_GroupControllerEffects->setGain(_SFXVolume);
_GroupControllerEffectsGame->setGain(_FadeSFXVolume);
}
}

View file

@ -332,9 +332,12 @@ private:
/// Pointer on the audio mixer object
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;
/// 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)
NLSOUND::UEnvSound *_EnvSoundRoot;