Skip to content

Commit

Permalink
Refactor|Audio: Perform frame synchronous audio operations in audio::…
Browse files Browse the repository at this point in the history
…System
  • Loading branch information
danij-deng committed Aug 6, 2015
1 parent dfd1091 commit d32d161
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 53 deletions.
4 changes: 0 additions & 4 deletions doomsday/apps/client/include/audio/s_main.h
Expand Up @@ -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.
*
Expand Down
4 changes: 4 additions & 0 deletions doomsday/apps/client/include/audio/system.h
Expand Up @@ -51,6 +51,10 @@ class System : public de::System
*/
void reset();

public: /// @todo make private:
void startFrame();
void endFrame();

private:
DENG2_PRIVATE(d)
};
Expand Down
45 changes: 0 additions & 45 deletions doomsday/apps/client/src/audio/s_main.cpp
Expand Up @@ -56,10 +56,6 @@

using namespace de;

BEGIN_PROF_TIMERS()
PROF_SOUND_STARTFRAME
END_PROF_TIMERS()

audiodriver_t *audioDriver;

int showSoundInfo;
Expand Down Expand Up @@ -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;
Expand Down
36 changes: 35 additions & 1 deletion doomsday/apps/client/src/audio/system.cpp
@@ -1,6 +1,8 @@
/** @file system.cpp Audio subsystem module.
*
* @authors Copyright © 2015 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2003-2013 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2006-2015 Daniel Swanson <danij@dengine.net>
* @authors Copyright © 2007 Jamie Jones <jamie_jones_au@yahoo.com.au> *
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
Expand Down Expand Up @@ -28,6 +30,7 @@
#include "audio/s_main.h"
#include "audio/s_mus.h"
#include "audio/s_sfx.h"
#include <doomsday/audio/logical.h>
#include <doomsday/console/cmd.h>
#include <doomsday/console/var.h>
#include <de/App>
Expand Down Expand Up @@ -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.
*/
Expand Down
6 changes: 3 additions & 3 deletions doomsday/apps/client/src/clientapp.cpp
Expand Up @@ -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().
{
Expand All @@ -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
Expand Down

0 comments on commit d32d161

Please sign in to comment.