change destroyOnFinish behavior to use OnBufferEnd

main
cosmonaut 2021-11-11 14:45:21 -08:00
parent 6edd9ebc94
commit 3568028dc3
1 changed files with 29 additions and 35 deletions

View File

@ -332,11 +332,14 @@ static inline FAudioGMS_EffectChain *FAudioGMS_INTERNAL_LookupEffectChain(uint32
static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance *instance); static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance *instance);
static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance); static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance);
static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance *instance); static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance *instance);
static void FAudioGMS_INTERNAL_SoundInstance_Destroy(FAudioGMS_SoundInstance *instance);
static void FAudioGMS_INTERNAL_OnBufferEndCallback( static void FAudioGMS_INTERNAL_OnBufferEndCallback(
FAudioVoiceCallback *callback, FAudioVoiceCallback *callback,
FAudioGMS_SoundInstance *instance) FAudioGMS_SoundInstance *instance)
{ {
uint32_t i;
if (instance->isStatic) if (instance->isStatic)
{ {
FAudioGMS_INTERNAL_SoundInstance_Stop(instance); FAudioGMS_INTERNAL_SoundInstance_Stop(instance);
@ -360,6 +363,27 @@ static void FAudioGMS_INTERNAL_OnBufferEndCallback(
FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance); FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance);
instance->queuedSoundInstance = NULL; instance->queuedSoundInstance = NULL;
} }
if (instance->destroyOnFinish)
{
/* this is a callback so we don't want to immediately destroy and screw up data */
instance->destroyTimerActive = 1;
instance->destroyTimer = 0;
if (instance->voice.effectChainAttached)
{
/* If we have active reverb we don't want to clean up until the decay time is over
*/
for (i = 0; i < instance->voice.effectChain->effectCount; i += 1)
{
if (instance->voice.effectChain->effectTypes[i] == EffectType_Reverb)
{
instance->destroyTimer += instance->voice.effectChain->effectParameters[i]
.reverbParameters.DecayTime;
}
}
}
}
} }
} }
@ -707,7 +731,7 @@ static FAudioGMS_SoundInstance *FAudioGMS_INTERNAL_SoundInstance_Init(
&instance->format, &instance->format,
FAUDIO_VOICE_USEFILTER, FAUDIO_VOICE_USEFILTER,
FAUDIO_DEFAULT_FREQ_RATIO, FAUDIO_DEFAULT_FREQ_RATIO,
isStatic ? NULL : &device->voiceCallbacks, &device->voiceCallbacks,
&instance->voice.sends, &instance->voice.sends,
NULL); NULL);
@ -2025,14 +2049,6 @@ void FAudioGMS_Update()
FAudioGMS_INTERNAL_SoundInstance_SetVolume(instance, volume); FAudioGMS_INTERNAL_SoundInstance_SetVolume(instance, volume);
} }
if (instance->destroyOnFinish)
{
FAudioVoiceState state;
FAudioSourceVoice_GetState(
instance->voice.handle,
&state,
FAUDIO_VOICE_NOSAMPLESPLAYED);
if (instance->destroyTimerActive) if (instance->destroyTimerActive)
{ {
instance->destroyTimer -= device->timestep; instance->destroyTimer -= device->timestep;
@ -2042,28 +2058,6 @@ void FAudioGMS_Update()
FAudioGMS_INTERNAL_SoundInstance_Destroy(instance); FAudioGMS_INTERNAL_SoundInstance_Destroy(instance);
} }
} }
else if (state.BuffersQueued == 0)
{
if (instance->voice.effectChainAttached)
{
/* If we have active reverb we don't want to clean up until the decay time is over */
for (j = 0; j < instance->voice.effectChain->effectCount; j += 1)
{
if (instance->voice.effectChain->effectTypes[j] == EffectType_Reverb)
{
instance->destroyTimerActive = 1;
instance->destroyTimer +=
instance->voice.effectChain->effectParameters[j]
.reverbParameters.DecayTime;
}
}
}
else
{
FAudioGMS_INTERNAL_SoundInstance_Destroy(instance);
}
}
}
} }
} }
} }