From d32d161dced1d19d5831956a8e5e14bbc16103ab Mon Sep 17 00:00:00 2001 From: danij Date: Thu, 6 Aug 2015 16:30:19 +0100 Subject: [PATCH] Refactor|Audio: Perform frame synchronous audio operations in audio::System --- doomsday/apps/client/include/audio/s_main.h | 4 -- doomsday/apps/client/include/audio/system.h | 4 ++ doomsday/apps/client/src/audio/s_main.cpp | 45 --------------------- doomsday/apps/client/src/audio/system.cpp | 36 ++++++++++++++++- doomsday/apps/client/src/clientapp.cpp | 6 +-- 5 files changed, 42 insertions(+), 53 deletions(-) diff --git a/doomsday/apps/client/include/audio/s_main.h b/doomsday/apps/client/include/audio/s_main.h index 42d2af5089..ec29a60f05 100644 --- a/doomsday/apps/client/include/audio/s_main.h +++ b/doomsday/apps/client/include/audio/s_main.h @@ -72,10 +72,6 @@ void S_MapChange(void); */ void S_SetupForChangedMap(void); -void S_StartFrame(void); - -void S_EndFrame(void); - /** * Gets information about a defined sound. Linked sounds are resolved. * diff --git a/doomsday/apps/client/include/audio/system.h b/doomsday/apps/client/include/audio/system.h index b921028deb..5f0c30b7fc 100644 --- a/doomsday/apps/client/include/audio/system.h +++ b/doomsday/apps/client/include/audio/system.h @@ -51,6 +51,10 @@ class System : public de::System */ void reset(); +public: /// @todo make private: + void startFrame(); + void endFrame(); + private: DENG2_PRIVATE(d) }; diff --git a/doomsday/apps/client/src/audio/s_main.cpp b/doomsday/apps/client/src/audio/s_main.cpp index 03e64138b5..b9f3820e32 100644 --- a/doomsday/apps/client/src/audio/s_main.cpp +++ b/doomsday/apps/client/src/audio/s_main.cpp @@ -56,10 +56,6 @@ using namespace de; -BEGIN_PROF_TIMERS() - PROF_SOUND_STARTFRAME -END_PROF_TIMERS() - audiodriver_t *audioDriver; int showSoundInfo; @@ -143,47 +139,6 @@ void S_SetupForChangedMap() #endif } -void S_StartFrame() -{ -#ifdef DD_PROFILE - static int i; - if(++i > 40) - { - i = 0; - PRINT_PROF( PROF_SOUND_STARTFRAME ); - } -#endif - -BEGIN_PROF( PROF_SOUND_STARTFRAME ); - -#ifdef __CLIENT__ - static int oldMusVolume = -1; - - if(musVolume != oldMusVolume) - { - oldMusVolume = musVolume; - Mus_SetVolume(musVolume / 255.0f); - } - - // Update all channels (freq, 2D:pan,volume, 3D:position,velocity). - Sfx_StartFrame(); - Mus_StartFrame(); -#endif - - // Remove stopped sounds from the LSM. - Sfx_Logical_SetOneSoundPerEmitter(sfxOneSoundPerEmitter); - Sfx_PurgeLogical(); - -END_PROF( PROF_SOUND_STARTFRAME ); -} - -void S_EndFrame() -{ -#ifdef __CLIENT__ - Sfx_EndFrame(); -#endif -} - mobj_t *S_GetListenerMobj() { return DD_Player(displayPlayer)->publicData().mo; diff --git a/doomsday/apps/client/src/audio/system.cpp b/doomsday/apps/client/src/audio/system.cpp index 50a1915b8c..bd666c9095 100644 --- a/doomsday/apps/client/src/audio/system.cpp +++ b/doomsday/apps/client/src/audio/system.cpp @@ -1,6 +1,8 @@ /** @file system.cpp Audio subsystem module. * - * @authors Copyright © 2015 Daniel Swanson + * @authors Copyright © 2003-2013 Jaakko Keränen + * @authors Copyright © 2006-2015 Daniel Swanson + * @authors Copyright © 2007 Jamie Jones * * * @par License * GPL: http://www.gnu.org/licenses/gpl.html @@ -28,6 +30,7 @@ #include "audio/s_main.h" #include "audio/s_mus.h" #include "audio/s_sfx.h" +#include #include #include #include @@ -82,6 +85,37 @@ void System::reset() _api_S.StopMusic(); } +/** + * @todo Do this in audio::System::timeChanged() + */ +void System::startFrame() +{ +#ifdef __CLIENT__ + static int oldMusVolume = -1; + + if(musVolume != oldMusVolume) + { + oldMusVolume = musVolume; + Mus_SetVolume(musVolume / 255.0f); + } + + // Update all channels (freq, 2D:pan,volume, 3D:position,velocity). + Sfx_StartFrame(); + Mus_StartFrame(); +#endif + + // Remove stopped sounds from the LSM. + Sfx_Logical_SetOneSoundPerEmitter(sfxOneSoundPerEmitter); + Sfx_PurgeLogical(); +} + +void System::endFrame() +{ +#ifdef __CLIENT__ + Sfx_EndFrame(); +#endif +} + /** * Console command for playing a (local) sound effect. */ diff --git a/doomsday/apps/client/src/clientapp.cpp b/doomsday/apps/client/src/clientapp.cpp index 17c045ac6f..227965a554 100644 --- a/doomsday/apps/client/src/clientapp.cpp +++ b/doomsday/apps/client/src/clientapp.cpp @@ -475,8 +475,8 @@ void ClientApp::initialize() void ClientApp::preFrame() { - // Frame syncronous I/O operations. - S_StartFrame(); /// @todo Move to AudioSystem::timeChanged(). + // Frame synchronous I/O operations. + App_AudioSystem().startFrame(); if(gx.BeginFrame) /// @todo Move to GameSystem::timeChanged(). { @@ -498,7 +498,7 @@ void ClientApp::postFrame() gx.EndFrame(); } - S_EndFrame(); + App_AudioSystem().endFrame(); // This is a good time to recycle unneeded memory allocations, as we're just // finished and shown a frame and there might be free time before we have to