update track position API

main
cosmonaut 2021-10-28 14:34:33 -07:00
parent d207d6ca0c
commit 8c26f79d28
2 changed files with 24 additions and 4 deletions

View File

@ -1131,7 +1131,7 @@ void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, dou
} }
} }
void FAudioGMS_SoundInstance_SetTrackPosition(double soundInstanceID, double trackPositionInSeconds) void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, double trackPositionInSeconds)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID); FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
@ -1143,16 +1143,18 @@ void FAudioGMS_SoundInstance_SetTrackPosition(double soundInstanceID, double tra
FAudioGMS_SoundState currentState = instance->soundState; FAudioGMS_SoundState currentState = instance->soundState;
if (currentState == SoundState_Playing) if (currentState == SoundState_Playing)
{ {
FAudioGMS_INTERNAL_SoundInstance_Stop(instance); FAudioSourceVoice_Stop(instance->handle, 0, 0);
FAudioSourceVoice_FlushSourceBuffers(instance->handle);
} }
if (instance->isStatic) if (instance->isStatic)
{ {
instance->soundData.staticSound->buffer.PlayBegin = instance->soundData.staticSound->samplesPerSecond * trackPositionInSeconds; instance->soundData.staticSound->buffer.PlayBegin = sampleFrame;
} }
else else
{ {
stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, sampleFrame); stb_vorbis_seek(instance->soundData.streamingSound.fileHandle, sampleFrame);
FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance);
} }
if (currentState == SoundState_Playing) if (currentState == SoundState_Playing)
@ -1230,6 +1232,23 @@ double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID)
} }
} }
double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID)
{
RETURN_ON_NULL_DEVICE(-1.0)
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
if (instance != NULL)
{
uint32_t sampleFrame = instance->handle->src.curBufferOffset / sizeof(float);
return sampleFrame / instance->format.nSamplesPerSec;
}
else
{
Log("Invalid sound instance!");
return -1.0;
}
}
void FAudioGMS_SetListenerPosition(double x, double y, double z) void FAudioGMS_SetListenerPosition(double x, double y, double z)
{ {
RETURN_ON_NULL_DEVICE() RETURN_ON_NULL_DEVICE()

View File

@ -58,7 +58,7 @@ FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPan(double soundInstanceID, double
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetPitch(double soundInstanceID, double pitch);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolume(double soundInstanceID, double volume);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Set3DPosition(double soundInstanceID, double x, double y, double z);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetTrackPosition(double soundInstanceID, double trackPositionInSeconds); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetTrackPositionInSeconds(double soundInstanceID, double trackPositionInSeconds);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolumeOverTime(double soundInstanceID, double volume, double milliseconds); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetVolumeOverTime(double soundInstanceID, double volume, double milliseconds);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLowPassFilter(double soundInstanceID, double lowPassFilter); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetLowPassFilter(double soundInstanceID, double lowPassFilter);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetHighPassFilter(double soundInstanceID, double highPassFilter); FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetHighPassFilter(double soundInstanceID, double highPassFilter);
@ -67,6 +67,7 @@ FAUDIOGMSAPI void FAudioGMS_SoundInstance_SetBandPassFilter(double soundInstance
FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID); FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetPitch(double soundInstanceID);
FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID); FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetVolume(double soundInstanceID);
FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID); FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackLengthInSeconds(double soundInstanceID);
FAUDIOGMSAPI double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_Destroy(double soundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_Destroy(double soundInstanceID);
FAUDIOGMSAPI void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID); FAUDIOGMSAPI void FAudioGMS_SoundInstance_DestroyWhenFinished(double soundInstanceID);