From 90250633de37f0e12f0a6dd0da22431d83c21080 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Wed, 24 Nov 2021 11:26:02 -0800 Subject: [PATCH] add play sync API --- gamemaker/extensions/FAudioGMS/FAudioGMS.dll | 4 +-- gamemaker/extensions/FAudioGMS/FAudioGMS.yy | 6 ++++ src/FAudioGMS.c | 38 ++++++++++++++------ src/FAudioGMS.h | 3 ++ 4 files changed, 39 insertions(+), 12 deletions(-) diff --git a/gamemaker/extensions/FAudioGMS/FAudioGMS.dll b/gamemaker/extensions/FAudioGMS/FAudioGMS.dll index e5fec6a..59c9164 100644 --- a/gamemaker/extensions/FAudioGMS/FAudioGMS.dll +++ b/gamemaker/extensions/FAudioGMS/FAudioGMS.dll @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d4f989c39a281394849cf09760ca1fde979ce87e00bb0c764cee46b6c5389cee -size 1521152 +oid sha256:b9ca9d72cefbd6f9da1eef87324769053cfde6c596588141b5f494552ca46336 +size 1521664 diff --git a/gamemaker/extensions/FAudioGMS/FAudioGMS.yy b/gamemaker/extensions/FAudioGMS/FAudioGMS.yy index 9eb2290..e0393b4 100644 --- a/gamemaker/extensions/FAudioGMS/FAudioGMS.yy +++ b/gamemaker/extensions/FAudioGMS/FAudioGMS.yy @@ -177,6 +177,10 @@ 2, 2, ],"resourceVersion":"1.0","name":"FAudioGMS_SoundInstance_QueueSoundInstance","tags":[],"resourceType":"GMExtensionFunction",}, + {"externalName":"FAudioGMS_SoundInstance_QueueSyncPlay","kind":1,"help":"FAudioGMS_SoundInstance_QueueSyncPlay(soundInstanceID)","hidden":false,"returnType":2,"argCount":0,"args":[ + 2, + ],"resourceVersion":"1.0","name":"FAudioGMS_SoundInstance_QueueSyncPlay","tags":[],"resourceType":"GMExtensionFunction",}, + {"externalName":"FAudioGMS_SoundInstance_SyncPlay","kind":1,"help":"FAudioGMS_SoundInstance_SyncPlay()","hidden":false,"returnType":2,"argCount":0,"args":[],"resourceVersion":"1.0","name":"FAudioGMS_SoundInstance_SyncPlay","tags":[],"resourceType":"GMExtensionFunction",}, ],"constants":[],"ProxyFiles":[ {"TargetMask":7,"resourceVersion":"1.0","name":"libFAudioGMS.so","tags":[],"resourceType":"GMProxyFile",}, {"TargetMask":3,"resourceVersion":"1.0","name":"FAudioGMSAndroidDummy.ext","tags":[],"resourceType":"GMProxyFile",}, @@ -190,6 +194,8 @@ {"name":"FAudioGMS_SoundInstance_Play","path":"extensions/FAudioGMS/FAudioGMS.yy",}, {"name":"FAudioGMS_SoundInstance_Pause","path":"extensions/FAudioGMS/FAudioGMS.yy",}, {"name":"FAudioGMS_SoundInstance_Stop","path":"extensions/FAudioGMS/FAudioGMS.yy",}, + {"name":"FAudioGMS_SoundInstance_QueueSyncPlay","path":"extensions/FAudioGMS/FAudioGMS.yy",}, + {"name":"FAudioGMS_SoundInstance_SyncPlay","path":"extensions/FAudioGMS/FAudioGMS.yy",}, {"name":"FAudioGMS_SoundInstance_SetLoop","path":"extensions/FAudioGMS/FAudioGMS.yy",}, {"name":"FAudioGMS_SoundInstance_SetPan","path":"extensions/FAudioGMS/FAudioGMS.yy",}, {"name":"FAudioGMS_SoundInstance_SetPitch","path":"extensions/FAudioGMS/FAudioGMS.yy",}, diff --git a/src/FAudioGMS.c b/src/FAudioGMS.c index e5d222d..6929093 100644 --- a/src/FAudioGMS.c +++ b/src/FAudioGMS.c @@ -327,7 +327,7 @@ static inline FAudioGMS_EffectChain *FAudioGMS_INTERNAL_LookupEffectChain(uint32 /* Forward declarations to avoid some annoying BS */ static void FAudioGMS_INTERNAL_SoundInstance_AddBuffers(FAudioGMS_SoundInstance *instance); -static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance); +static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance, uint32_t operationSet); static void FAudioGMS_INTERNAL_SoundInstance_Stop(FAudioGMS_SoundInstance *instance); static void FAudioGMS_INTERNAL_SoundInstance_Destroy(FAudioGMS_SoundInstance *instance); @@ -379,7 +379,7 @@ static void FAudioGMS_INTERNAL_OnBufferEndCallback( { if (instance->queuedSoundInstance != NULL) { - FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance->queuedSoundInstance, 0); instance->queuedSoundInstance = NULL; } @@ -1141,7 +1141,7 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddEmitter( FAudioGMS_INTERNAL_Apply3D(instance); } -static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance) +static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *instance, uint32_t operationSet) { if (instance->soundState == SoundState_Playing) { @@ -1190,7 +1190,7 @@ static void FAudioGMS_INTERNAL_SoundInstance_Play(FAudioGMS_SoundInstance *insta FAudioGMS_INTERNAL_SoundInstance_AddBuffers(instance); } - FAudioSourceVoice_Start(instance->voice.handle, 0, 0); + FAudioSourceVoice_Start(instance->voice.handle, 0, operationSet); instance->soundState = SoundState_Playing; } @@ -1202,10 +1202,28 @@ void FAudioGMS_SoundInstance_Play(double soundInstanceID) if (instance != NULL) { - FAudioGMS_INTERNAL_SoundInstance_Play(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 0); } } +FAUDIOGMSAPI void FAudioGMS_SoundInstance_QueueSyncPlay(double soundInstanceID) +{ + RETURN_ON_NULL_DEVICE_VOID + FAudioGMS_SoundInstance *instance = + FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); + + if (instance != NULL) + { + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 1); /* operation set */ + } +} + +void FAudioGMS_SoundInstance_SyncPlay() +{ + RETURN_ON_NULL_DEVICE_VOID + FAudio_CommitOperationSet(device->handle, 1); +} + static void FAudioGMS_INTERNAL_SoundInstance_Pause(FAudioGMS_SoundInstance *instance) { if (instance != NULL) @@ -1284,7 +1302,7 @@ void FAudioGMS_SoundInstance_SetLoop(double soundInstanceID, double loop) /* We need to pause and play so that static buffers get resubmitted */ FAudioGMS_INTERNAL_SoundInstance_Pause(instance); - FAudioGMS_INTERNAL_SoundInstance_Play(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 0); } } } @@ -1407,7 +1425,7 @@ void FAudioGMS_SoundInstance_SetTrackPositionInSeconds( if (currentState == SoundState_Playing) { - FAudioGMS_INTERNAL_SoundInstance_Play(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 0); } } } @@ -1467,7 +1485,7 @@ void FAudioGMS_SoundInstance_SetPlayRegion( if (instance->isStatic && instance->soundState == SoundState_Playing) { FAudioGMS_INTERNAL_SoundInstance_Stop(instance); - FAudioGMS_INTERNAL_SoundInstance_Play(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 0); } else if (!instance->isStatic) { @@ -1483,7 +1501,7 @@ void FAudioGMS_SoundInstance_SetPlayRegion( if (instance->isStatic && instance->soundState != SoundState_Stopped) { FAudioGMS_INTERNAL_SoundInstance_Pause(instance); - FAudioGMS_INTERNAL_SoundInstance_Play(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 0); } } } @@ -2081,7 +2099,7 @@ void FAudioGMS_ResumeAll() if (instance != NULL && instance->isGlobalPaused) { instance->isGlobalPaused = 0; - FAudioGMS_INTERNAL_SoundInstance_Play(instance); + FAudioGMS_INTERNAL_SoundInstance_Play(instance, 0); } } } diff --git a/src/FAudioGMS.h b/src/FAudioGMS.h index 5a2504e..590afb4 100644 --- a/src/FAudioGMS.h +++ b/src/FAudioGMS.h @@ -57,6 +57,9 @@ extern "C" FAUDIOGMSAPI void FAudioGMS_SoundInstance_Pause(double soundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Stop(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_QueueSyncPlay(double soundInstanceID); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_SyncPlay(); + FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPlayRegion( double soundInstanceID, double startInMilliseconds,