forked from MoonsideGames/FAudioGMS
change destroyOnFinish behavior to use OnBufferEnd
parent
6edd9ebc94
commit
3568028dc3
|
@ -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_Play(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(
|
||||
FAudioVoiceCallback *callback,
|
||||
FAudioGMS_SoundInstance *instance)
|
||||
{
|
||||
uint32_t i;
|
||||
|
||||
if (instance->isStatic)
|
||||
{
|
||||
FAudioGMS_INTERNAL_SoundInstance_Stop(instance);
|
||||
|
@ -360,6 +363,27 @@ static void FAudioGMS_INTERNAL_OnBufferEndCallback(
|
|||
FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance);
|
||||
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,
|
||||
FAUDIO_VOICE_USEFILTER,
|
||||
FAUDIO_DEFAULT_FREQ_RATIO,
|
||||
isStatic ? NULL : &device->voiceCallbacks,
|
||||
&device->voiceCallbacks,
|
||||
&instance->voice.sends,
|
||||
NULL);
|
||||
|
||||
|
@ -2025,14 +2049,6 @@ void FAudioGMS_Update()
|
|||
FAudioGMS_INTERNAL_SoundInstance_SetVolume(instance, volume);
|
||||
}
|
||||
|
||||
if (instance->destroyOnFinish)
|
||||
{
|
||||
FAudioVoiceState state;
|
||||
FAudioSourceVoice_GetState(
|
||||
instance->voice.handle,
|
||||
&state,
|
||||
FAUDIO_VOICE_NOSAMPLESPLAYED);
|
||||
|
||||
if (instance->destroyTimerActive)
|
||||
{
|
||||
instance->destroyTimer -= device->timestep;
|
||||
|
@ -2042,28 +2058,6 @@ void FAudioGMS_Update()
|
|||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue