Use AL_SOFT_deferred_updates to sync updates when availeble

This commit is contained in:
Chris Robinson 2014-06-25 21:48:13 -07:00
parent c6bb52c866
commit a6900b48ba
2 changed files with 36 additions and 7 deletions

View file

@ -135,6 +135,20 @@ static ALCenum checkALCError(ALCdevice *device, const char *fn, unsigned int ln)
#define getALCError(d) checkALCError((d), __FILE__, __LINE__) #define getALCError(d) checkALCError((d), __FILE__, __LINE__)
// Fallback methods for when AL_SOFT_deferred_updates isn't available. In most
// cases these don't actually do anything, except on some Creative drivers
// where they act as appropriate fallbacks.
static ALvoid AL_APIENTRY _wrap_DeferUpdatesSOFT(void)
{
alcSuspendContext(alcGetCurrentContext());
}
static ALvoid AL_APIENTRY _wrap_ProcessUpdatesSOFT(void)
{
alcProcessContext(alcGetCurrentContext());
}
class OpenALSoundStream : public SoundStream class OpenALSoundStream : public SoundStream
{ {
OpenALSoundRenderer *Renderer; OpenALSoundRenderer *Renderer;
@ -579,6 +593,7 @@ template<typename T>
static void LoadALFunc(const char *name, T *x) static void LoadALFunc(const char *name, T *x)
{ *x = reinterpret_cast<T>(alGetProcAddress(name)); } { *x = reinterpret_cast<T>(alGetProcAddress(name)); }
#define LOAD_FUNC(x) (LoadALFunc(#x, &x))
OpenALSoundRenderer::OpenALSoundRenderer() OpenALSoundRenderer::OpenALSoundRenderer()
: Device(NULL), Context(NULL), SFXPaused(0), PrevEnvironment(NULL), EnvSlot(0) : Device(NULL), Context(NULL), SFXPaused(0), PrevEnvironment(NULL), EnvSlot(0)
{ {
@ -652,6 +667,7 @@ OpenALSoundRenderer::OpenALSoundRenderer()
ALC.EXT_EFX = alcIsExtensionPresent(Device, "ALC_EXT_EFX"); ALC.EXT_EFX = alcIsExtensionPresent(Device, "ALC_EXT_EFX");
ALC.EXT_disconnect = alcIsExtensionPresent(Device, "ALC_EXT_disconnect");; ALC.EXT_disconnect = alcIsExtensionPresent(Device, "ALC_EXT_disconnect");;
AL.EXT_source_distance_model = alIsExtensionPresent("AL_EXT_source_distance_model"); AL.EXT_source_distance_model = alIsExtensionPresent("AL_EXT_source_distance_model");
AL.SOFT_deferred_updates = alIsExtensionPresent("AL_SOFT_deferred_updates");
AL.SOFT_loop_points = alIsExtensionPresent("AL_SOFT_loop_points"); AL.SOFT_loop_points = alIsExtensionPresent("AL_SOFT_loop_points");
alDopplerFactor(0.5f); alDopplerFactor(0.5f);
@ -660,6 +676,17 @@ OpenALSoundRenderer::OpenALSoundRenderer()
if(AL.EXT_source_distance_model) if(AL.EXT_source_distance_model)
alEnable(AL_SOURCE_DISTANCE_MODEL); alEnable(AL_SOURCE_DISTANCE_MODEL);
if(AL.SOFT_deferred_updates)
{
LOAD_FUNC(alDeferUpdatesSOFT);
LOAD_FUNC(alProcessUpdatesSOFT);
}
else
{
alDeferUpdatesSOFT = _wrap_DeferUpdatesSOFT;
alProcessUpdatesSOFT = _wrap_ProcessUpdatesSOFT;
}
ALenum err = getALError(); ALenum err = getALError();
if(err != AL_NO_ERROR) if(err != AL_NO_ERROR)
{ {
@ -703,7 +730,6 @@ OpenALSoundRenderer::OpenALSoundRenderer()
if(*snd_efx && ALC.EXT_EFX) if(*snd_efx && ALC.EXT_EFX)
{ {
// EFX function pointers // EFX function pointers
#define LOAD_FUNC(x) (LoadALFunc(#x, &x))
LOAD_FUNC(alGenEffects); LOAD_FUNC(alGenEffects);
LOAD_FUNC(alDeleteEffects); LOAD_FUNC(alDeleteEffects);
LOAD_FUNC(alIsEffect); LOAD_FUNC(alIsEffect);
@ -739,7 +765,6 @@ OpenALSoundRenderer::OpenALSoundRenderer()
LOAD_FUNC(alGetAuxiliaryEffectSlotiv); LOAD_FUNC(alGetAuxiliaryEffectSlotiv);
LOAD_FUNC(alGetAuxiliaryEffectSlotf); LOAD_FUNC(alGetAuxiliaryEffectSlotf);
LOAD_FUNC(alGetAuxiliaryEffectSlotfv); LOAD_FUNC(alGetAuxiliaryEffectSlotfv);
#undef LOAD_FUNC
if(getALError() == AL_NO_ERROR) if(getALError() == AL_NO_ERROR)
{ {
ALuint envReverb; ALuint envReverb;
@ -788,6 +813,7 @@ OpenALSoundRenderer::OpenALSoundRenderer()
if(EnvSlot) if(EnvSlot)
Printf(" EFX enabled\n"); Printf(" EFX enabled\n");
} }
#undef LOAD_FUNC
OpenALSoundRenderer::~OpenALSoundRenderer() OpenALSoundRenderer::~OpenALSoundRenderer()
{ {
@ -838,7 +864,7 @@ void OpenALSoundRenderer::SetSfxVolume(float volume)
ALuint source = GET_PTRID(schan->SysChannel); ALuint source = GET_PTRID(schan->SysChannel);
volume = SfxVolume; volume = SfxVolume;
alcSuspendContext(Context); alDeferUpdatesSOFT();
alSourcef(source, AL_MAX_GAIN, volume); alSourcef(source, AL_MAX_GAIN, volume);
alSourcef(source, AL_GAIN, volume * schan->Volume); alSourcef(source, AL_GAIN, volume * schan->Volume);
} }
@ -1330,7 +1356,7 @@ void OpenALSoundRenderer::ChannelVolume(FISoundChannel *chan, float volume)
if(chan == NULL || chan->SysChannel == NULL) if(chan == NULL || chan->SysChannel == NULL)
return; return;
alcSuspendContext(Context); alDeferUpdatesSOFT();
ALuint source = GET_PTRID(chan->SysChannel); ALuint source = GET_PTRID(chan->SysChannel);
alSourcef(source, AL_GAIN, SfxVolume * volume); alSourcef(source, AL_GAIN, SfxVolume * volume);
@ -1456,7 +1482,7 @@ void OpenALSoundRenderer::UpdateSoundParams3D(SoundListener *listener, FISoundCh
if(chan == NULL || chan->SysChannel == NULL) if(chan == NULL || chan->SysChannel == NULL)
return; return;
alcSuspendContext(Context); alDeferUpdatesSOFT();
FVector3 dir = pos - listener->position; FVector3 dir = pos - listener->position;
chan->DistanceSqr = dir.LengthSquared(); chan->DistanceSqr = dir.LengthSquared();
@ -1495,7 +1521,7 @@ void OpenALSoundRenderer::UpdateListener(SoundListener *listener)
if(!listener->valid) if(!listener->valid)
return; return;
alcSuspendContext(Context); alDeferUpdatesSOFT();
float angle = listener->angle; float angle = listener->angle;
ALfloat orient[6]; ALfloat orient[6];
@ -1593,7 +1619,7 @@ void OpenALSoundRenderer::UpdateListener(SoundListener *listener)
void OpenALSoundRenderer::UpdateSounds() void OpenALSoundRenderer::UpdateSounds()
{ {
alcProcessContext(Context); alProcessUpdatesSOFT();
// For some reason this isn't being called? // For some reason this isn't being called?
foreach(SoundStream*, stream, Streams) foreach(SoundStream*, stream, Streams)

View file

@ -128,6 +128,7 @@ private:
} ALC; } ALC;
struct { struct {
bool EXT_source_distance_model; bool EXT_source_distance_model;
bool SOFT_deferred_updates;
bool SOFT_loop_points; bool SOFT_loop_points;
} AL; } AL;
@ -171,6 +172,8 @@ private:
LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf; LPALGETAUXILIARYEFFECTSLOTF alGetAuxiliaryEffectSlotf;
LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv; LPALGETAUXILIARYEFFECTSLOTFV alGetAuxiliaryEffectSlotfv;
ALvoid (AL_APIENTRY*alDeferUpdatesSOFT)(void);
ALvoid (AL_APIENTRY*alProcessUpdatesSOFT)(void);
void LoadReverb(const ReverbContainer *env); void LoadReverb(const ReverbContainer *env);
void PurgeStoppedSources(); void PurgeStoppedSources();