This commit is contained in:
kaetemi 2012-04-10 18:18:58 +02:00
parent 85c89ea6f8
commit a35d949a4d
9 changed files with 39 additions and 17 deletions

View file

@ -39,9 +39,6 @@
// Current version is 2, Ryzom Live uses 1 // Current version is 2, Ryzom Live uses 1
// Provided to allow compatibility with old binary files // Provided to allow compatibility with old binary files
#define NLSOUND_SHEET_VERSION_BUILT 1 #define NLSOUND_SHEET_VERSION_BUILT 1
#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"
namespace NLLIGO { namespace NLLIGO {
class CLigoConfig; class CLigoConfig;

View file

@ -32,6 +32,7 @@
// STL includes // STL includes
// NeL includes // NeL includes
#include <nel/misc/singleton.h>
// Project includes // Project includes
#include <nel/sound/group_controller.h> #include <nel/sound/group_controller.h>
@ -44,7 +45,7 @@ namespace NLSOUND {
* \author Jan Boon (Kaetemi) * \author Jan Boon (Kaetemi)
* CGroupControllerRoot * CGroupControllerRoot
*/ */
class CGroupControllerRoot : public CGroupController class CGroupControllerRoot : public CGroupController, public NLMISC::CManualSingleton<CGroupControllerRoot>
{ {
public: public:
CGroupControllerRoot(); CGroupControllerRoot();

View file

@ -35,6 +35,10 @@
// Project includes // 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"
namespace NLSOUND { namespace NLSOUND {
/** /**
@ -45,6 +49,7 @@ namespace NLSOUND {
*/ */
class UGroupController class UGroupController
{ {
public:
virtual void setDevGain(float gain) = 0; virtual void setDevGain(float gain) = 0;
virtual float getDevGain() = 0; virtual float getDevGain() = 0;

View file

@ -40,6 +40,7 @@
#include <nel/sound/u_audio_mixer.h> #include <nel/sound/u_audio_mixer.h>
#include <nel/sound/u_listener.h> #include <nel/sound/u_listener.h>
#include <nel/sound/u_stream_source.h> #include <nel/sound/u_stream_source.h>
#include <nel/sound/u_group_controller.h>
#include <nel/misc/hierarchical_timer.h> #include <nel/misc/hierarchical_timer.h>
// Project includes // Project includes
@ -325,6 +326,7 @@ static ov_callbacks OV_CALLBACKS_NLMISC_STREAM = {
static UAudioMixer *s_AudioMixer = NULL; static UAudioMixer *s_AudioMixer = NULL;
static UStreamSource *s_StreamSource = NULL; static UStreamSource *s_StreamSource = NULL;
static IAudioDecoder *s_AudioDecoder = NULL; static IAudioDecoder *s_AudioDecoder = NULL;
static UGroupController *s_GroupController = NULL;
static void initSample() static void initSample()
{ {
@ -368,6 +370,8 @@ static void initSample()
s_AudioDecoder = IAudioDecoder::createAudioDecoder(sample, false, false); s_AudioDecoder = IAudioDecoder::createAudioDecoder(sample, false, false);
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");
} }
//CMutex *s_Mutex = NULL; //CMutex *s_Mutex = NULL;
@ -405,13 +409,23 @@ static void runSample()
s_StreamSource->play(); s_StreamSource->play();
printf("Press ANY key to exit\n"); printf("Change volume with - and +\n");
printf("Press ANY other key to exit\n");
while (!s_AudioDecoder->isMusicEnded()) while (!s_AudioDecoder->isMusicEnded())
{ {
if (_kbhit()) if (_kbhit())
{ {
_getch(); switch (_getch())
return; {
case '+':
s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f);
break;
case '-':
s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f);
break;
default:
return;
}
} }
bufferMore(bytes); bufferMore(bytes);
s_AudioMixer->update(); s_AudioMixer->update();
@ -440,6 +454,7 @@ static void runSample()
static void releaseSample() static void releaseSample()
{ {
//NLMISC::CHTimer::clear(); //NLMISC::CHTimer::clear();
s_GroupController = NULL;
delete s_AudioDecoder; s_AudioDecoder = NULL; delete s_AudioDecoder; s_AudioDecoder = NULL;
delete s_StreamSource; s_StreamSource = NULL; delete s_StreamSource; s_StreamSource = NULL;
delete s_AudioMixer; s_AudioMixer = NULL; delete s_AudioMixer; s_AudioMixer = NULL;

View file

@ -62,6 +62,8 @@ CGroupController::~CGroupController()
void CGroupController::addSource(CSourceCommon *source) void CGroupController::addSource(CSourceCommon *source)
{ {
nlassert(this);
m_Sources.insert(source); m_Sources.insert(source);
increaseSources(); increaseSources();
} }

View file

@ -21,7 +21,7 @@
#include "nel/georges/u_form_elm.h" #include "nel/georges/u_form_elm.h"
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
# include "nel/sound/audio_mixer_user.h" # include "nel/sound/group_controller_root.h"
#endif #endif
using namespace std; using namespace std;
@ -76,7 +76,7 @@ void CMusicSound::importForm(const std::string& filename, NLGEORGES::UFormElm&
root.getValueByName(_TimeBeforeCanReplay, ".SoundType.TimeBeforeCanReplay"); root.getValueByName(_TimeBeforeCanReplay, ".SoundType.TimeBeforeCanReplay");
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
_GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER)); _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER);
#endif #endif
} }
@ -106,7 +106,7 @@ void CMusicSound::serial(NLMISC::IStream &s)
s.serial(_MinimumPlayTime, _TimeBeforeCanReplay); s.serial(_MinimumPlayTime, _TimeBeforeCanReplay);
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
if (s.isReading()) _GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER)); if (s.isReading()) _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER);
#endif #endif
} }

View file

@ -28,6 +28,7 @@
#include "nel/sound/stream_sound.h" #include "nel/sound/stream_sound.h"
#include "nel/sound/group_controller.h" #include "nel/sound/group_controller.h"
#include "nel/sound/group_controller_root.h"
using namespace std; using namespace std;
using namespace NLMISC; using namespace NLMISC;
@ -137,7 +138,7 @@ void CSound::serial(NLMISC::IStream &s)
s.serial(name); s.serial(name);
} }
nlassert(CAudioMixerUser::instance()); // not sure nlassert(CGroupControllerRoot::getInstance()); // not sure
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
if (s.isReading()) _GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER)); if (s.isReading()) _GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER));
#else #else
@ -245,12 +246,13 @@ void CSound::importForm(const std::string& filename, NLGEORGES::UFormElm& roo
_Priority = MidPri; _Priority = MidPri;
} }
nlassert(CGroupControllerRoot::getInstance()); // not sure
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
_GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER)); _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER);
#else #else
std::string groupControllerPath; std::string groupControllerPath;
root.getValueByName(groupControllerPath, ".GroupControllerPath"); root.getValueByName(groupControllerPath, ".GroupControllerPath");
_GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(groupControllerPath)); _GroupController = CGroupControllerRoot::getInstance()->getGroupController(groupControllerPath);
#endif #endif
} }

View file

@ -45,7 +45,7 @@ CSourceCommon::CSourceCommon(TSoundId id, bool spawn, TSpawnEndCallback cb, void
_GroupController(groupController ? groupController : id->getGroupController()) _GroupController(groupController ? groupController : id->getGroupController())
{ {
CAudioMixerUser::instance()->addSource(this); CAudioMixerUser::instance()->addSource(this);
groupController->addSource(this); _GroupController->addSource(this);
// get a local copy of the sound parameter // get a local copy of the sound parameter
_InitialGain = _Gain = id->getGain(); _InitialGain = _Gain = id->getGain();

View file

@ -18,7 +18,7 @@
#include "nel/sound/stream_sound.h" #include "nel/sound/stream_sound.h"
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
# include "nel/sound/audio_mixer_user.h" # include "nel/sound/group_controller_root.h"
#endif #endif
namespace NLSOUND { namespace NLSOUND {
@ -57,7 +57,7 @@ void CStreamSound::importForm(const std::string &filename, NLGEORGES::UFormElm &
root.getValueByName(m_Alpha, ".SoundType.Alpha"); root.getValueByName(m_Alpha, ".SoundType.Alpha");
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
_GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER)); _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER);
#endif #endif
} }
@ -70,7 +70,7 @@ void CStreamSound::serial(NLMISC::IStream &s)
s.serial(m_Alpha); s.serial(m_Alpha);
#if NLSOUND_SHEET_VERSION_BUILT < 2 #if NLSOUND_SHEET_VERSION_BUILT < 2
if (s.isReading()) _GroupController = static_cast<CGroupController *>(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER)); if (s.isReading()) _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER);
#endif #endif
} }