From 2825b8b40290fc9db87d0df96c82cf6a4b0cc21c Mon Sep 17 00:00:00 2001 From: kaetemi Date: Tue, 10 Apr 2012 18:18:58 +0200 Subject: [PATCH] Fixed: #1459 Done --- code/nel/include/nel/sound/audio_mixer_user.h | 3 --- .../include/nel/sound/group_controller_root.h | 3 ++- .../include/nel/sound/u_group_controller.h | 5 +++++ .../stream_ogg_vorbis/stream_ogg_vorbis.cpp | 21 ++++++++++++++++--- code/nel/src/sound/group_controller.cpp | 2 ++ code/nel/src/sound/music_sound.cpp | 6 +++--- code/nel/src/sound/sound.cpp | 8 ++++--- code/nel/src/sound/source_common.cpp | 2 +- code/nel/src/sound/stream_sound.cpp | 6 +++--- 9 files changed, 39 insertions(+), 17 deletions(-) diff --git a/code/nel/include/nel/sound/audio_mixer_user.h b/code/nel/include/nel/sound/audio_mixer_user.h index c060edd48..977fe066b 100644 --- a/code/nel/include/nel/sound/audio_mixer_user.h +++ b/code/nel/include/nel/sound/audio_mixer_user.h @@ -39,9 +39,6 @@ // Current version is 2, Ryzom Live uses 1 // Provided to allow compatibility with old binary files #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 { class CLigoConfig; diff --git a/code/nel/include/nel/sound/group_controller_root.h b/code/nel/include/nel/sound/group_controller_root.h index 5d47ff50a..2cc86f5b3 100644 --- a/code/nel/include/nel/sound/group_controller_root.h +++ b/code/nel/include/nel/sound/group_controller_root.h @@ -32,6 +32,7 @@ // STL includes // NeL includes +#include // Project includes #include @@ -44,7 +45,7 @@ namespace NLSOUND { * \author Jan Boon (Kaetemi) * CGroupControllerRoot */ -class CGroupControllerRoot : public CGroupController +class CGroupControllerRoot : public CGroupController, public NLMISC::CManualSingleton { public: CGroupControllerRoot(); diff --git a/code/nel/include/nel/sound/u_group_controller.h b/code/nel/include/nel/sound/u_group_controller.h index a74e9da73..533f29936 100644 --- a/code/nel/include/nel/sound/u_group_controller.h +++ b/code/nel/include/nel/sound/u_group_controller.h @@ -35,6 +35,10 @@ // 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 { /** @@ -45,6 +49,7 @@ namespace NLSOUND { */ class UGroupController { +public: virtual void setDevGain(float gain) = 0; virtual float getDevGain() = 0; diff --git a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp index db5b8b214..596d07721 100644 --- a/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp +++ b/code/nel/samples/sound/stream_ogg_vorbis/stream_ogg_vorbis.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include // Project includes @@ -325,6 +326,7 @@ static ov_callbacks OV_CALLBACKS_NLMISC_STREAM = { static UAudioMixer *s_AudioMixer = NULL; static UStreamSource *s_StreamSource = NULL; static IAudioDecoder *s_AudioDecoder = NULL; +static UGroupController *s_GroupController = NULL; static void initSample() { @@ -368,6 +370,8 @@ static void initSample() s_AudioDecoder = IAudioDecoder::createAudioDecoder(sample, false, false); s_StreamSource->setFormat(s_AudioDecoder->getChannels(), s_AudioDecoder->getBitsPerSample(), (uint32)s_AudioDecoder->getSamplesPerSec()); s_StreamSource->setPitch(2.0f); + + s_GroupController = s_AudioMixer->getGroupController("dialog"); } //CMutex *s_Mutex = NULL; @@ -405,13 +409,23 @@ static void runSample() 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()) { if (_kbhit()) { - _getch(); - return; + switch (_getch()) + { + case '+': + s_GroupController->setUserGain(s_GroupController->getUserGain() + 0.1f); + break; + case '-': + s_GroupController->setUserGain(s_GroupController->getUserGain() - 0.1f); + break; + default: + return; + } } bufferMore(bytes); s_AudioMixer->update(); @@ -440,6 +454,7 @@ static void runSample() static void releaseSample() { //NLMISC::CHTimer::clear(); + s_GroupController = NULL; delete s_AudioDecoder; s_AudioDecoder = NULL; delete s_StreamSource; s_StreamSource = NULL; delete s_AudioMixer; s_AudioMixer = NULL; diff --git a/code/nel/src/sound/group_controller.cpp b/code/nel/src/sound/group_controller.cpp index 86f46301e..1cce28bf0 100644 --- a/code/nel/src/sound/group_controller.cpp +++ b/code/nel/src/sound/group_controller.cpp @@ -62,6 +62,8 @@ CGroupController::~CGroupController() void CGroupController::addSource(CSourceCommon *source) { + nlassert(this); + m_Sources.insert(source); increaseSources(); } diff --git a/code/nel/src/sound/music_sound.cpp b/code/nel/src/sound/music_sound.cpp index f95edfb26..803103dd9 100644 --- a/code/nel/src/sound/music_sound.cpp +++ b/code/nel/src/sound/music_sound.cpp @@ -21,7 +21,7 @@ #include "nel/georges/u_form_elm.h" #if NLSOUND_SHEET_VERSION_BUILT < 2 -# include "nel/sound/audio_mixer_user.h" +# include "nel/sound/group_controller_root.h" #endif using namespace std; @@ -76,7 +76,7 @@ void CMusicSound::importForm(const std::string& filename, NLGEORGES::UFormElm& root.getValueByName(_TimeBeforeCanReplay, ".SoundType.TimeBeforeCanReplay"); #if NLSOUND_SHEET_VERSION_BUILT < 2 - _GroupController = static_cast(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER)); + _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_MUSIC_GROUP_CONTROLLER); #endif } @@ -106,7 +106,7 @@ void CMusicSound::serial(NLMISC::IStream &s) s.serial(_MinimumPlayTime, _TimeBeforeCanReplay); #if NLSOUND_SHEET_VERSION_BUILT < 2 - if (s.isReading()) _GroupController = static_cast(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 } diff --git a/code/nel/src/sound/sound.cpp b/code/nel/src/sound/sound.cpp index a943fa543..07c10f8ef 100644 --- a/code/nel/src/sound/sound.cpp +++ b/code/nel/src/sound/sound.cpp @@ -28,6 +28,7 @@ #include "nel/sound/stream_sound.h" #include "nel/sound/group_controller.h" +#include "nel/sound/group_controller_root.h" using namespace std; using namespace NLMISC; @@ -137,7 +138,7 @@ void CSound::serial(NLMISC::IStream &s) s.serial(name); } - nlassert(CAudioMixerUser::instance()); // not sure + nlassert(CGroupControllerRoot::getInstance()); // not sure #if NLSOUND_SHEET_VERSION_BUILT < 2 if (s.isReading()) _GroupController = static_cast(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER)); #else @@ -245,12 +246,13 @@ void CSound::importForm(const std::string& filename, NLGEORGES::UFormElm& roo _Priority = MidPri; } + nlassert(CGroupControllerRoot::getInstance()); // not sure #if NLSOUND_SHEET_VERSION_BUILT < 2 - _GroupController = static_cast(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER)); + _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_GROUP_CONTROLLER); #else std::string groupControllerPath; root.getValueByName(groupControllerPath, ".GroupControllerPath"); - _GroupController = static_cast(CAudioMixerUser::instance()->getGroupController(groupControllerPath)); + _GroupController = CGroupControllerRoot::getInstance()->getGroupController(groupControllerPath); #endif } diff --git a/code/nel/src/sound/source_common.cpp b/code/nel/src/sound/source_common.cpp index 3af1eb6ae..7b27deb03 100644 --- a/code/nel/src/sound/source_common.cpp +++ b/code/nel/src/sound/source_common.cpp @@ -45,7 +45,7 @@ CSourceCommon::CSourceCommon(TSoundId id, bool spawn, TSpawnEndCallback cb, void _GroupController(groupController ? groupController : id->getGroupController()) { CAudioMixerUser::instance()->addSource(this); - groupController->addSource(this); + _GroupController->addSource(this); // get a local copy of the sound parameter _InitialGain = _Gain = id->getGain(); diff --git a/code/nel/src/sound/stream_sound.cpp b/code/nel/src/sound/stream_sound.cpp index 7addbbe0a..7552e79e5 100644 --- a/code/nel/src/sound/stream_sound.cpp +++ b/code/nel/src/sound/stream_sound.cpp @@ -18,7 +18,7 @@ #include "nel/sound/stream_sound.h" #if NLSOUND_SHEET_VERSION_BUILT < 2 -# include "nel/sound/audio_mixer_user.h" +# include "nel/sound/group_controller_root.h" #endif namespace NLSOUND { @@ -57,7 +57,7 @@ void CStreamSound::importForm(const std::string &filename, NLGEORGES::UFormElm & root.getValueByName(m_Alpha, ".SoundType.Alpha"); #if NLSOUND_SHEET_VERSION_BUILT < 2 - _GroupController = static_cast(CAudioMixerUser::instance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER)); + _GroupController = CGroupControllerRoot::getInstance()->getGroupController(NLSOUND_SHEET_V1_DEFAULT_SOUND_STREAM_GROUP_CONTROLLER); #endif } @@ -70,7 +70,7 @@ void CStreamSound::serial(NLMISC::IStream &s) s.serial(m_Alpha); #if NLSOUND_SHEET_VERSION_BUILT < 2 - if (s.isReading()) _GroupController = static_cast(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 }