forked from MoonsideGames/FAudioGMS
fix track position calculation on streaming audio
parent
61f3511fdf
commit
8c8d481dcf
|
@ -175,6 +175,7 @@ typedef struct FAudioGMS_StreamingSound
|
|||
stb_vorbis_info info;
|
||||
float* streamBuffer;
|
||||
uint32_t streamBufferSize;
|
||||
uint32_t mostRecentBufferOffset; /* used for calculating track position */
|
||||
} FAudioGMS_StreamingSound;
|
||||
|
||||
typedef struct FAudioGMS_SoundInstance
|
||||
|
@ -861,6 +862,8 @@ static void FAudioGMS_INTERNAL_SoundInstance_AddBuffer(FAudioGMS_SoundInstance*
|
|||
instance->soundData.streamingSound.streamBufferSize = requiredStagingBufferSize;
|
||||
}
|
||||
|
||||
instance->soundData.streamingSound.mostRecentBufferOffset = stb_vorbis_get_sample_offset(instance->soundData.streamingSound.fileHandle);
|
||||
|
||||
/* NOTE: this function returns samples per channel, not total samples */
|
||||
uint32_t sampleCount = stb_vorbis_get_samples_float_interleaved(
|
||||
instance->soundData.streamingSound.fileHandle,
|
||||
|
@ -927,6 +930,7 @@ double FAudioGMS_StreamingSound_LoadOGG(char* filePath)
|
|||
instance->soundData.streamingSound.info = info;
|
||||
instance->soundData.streamingSound.streamBuffer = NULL;
|
||||
instance->soundData.streamingSound.streamBufferSize = 0;
|
||||
instance->soundData.streamingSound.mostRecentBufferOffset = 0;
|
||||
|
||||
FAudioGMS_INTERNAL_SoundInstance_AddBuffer(instance);
|
||||
|
||||
|
@ -1278,11 +1282,18 @@ double FAudioGMS_SoundInstance_GetTrackPositionInSeconds(double soundInstanceID)
|
|||
FAudioGMS_SoundInstance* instance = FAudioGMS_INTERNAL_LookupSoundInstance((uint32_t)soundInstanceID);
|
||||
|
||||
if (instance != NULL)
|
||||
{
|
||||
if (instance->isStatic)
|
||||
{
|
||||
uint32_t sampleFrame = instance->voice.handle->src.curBufferOffset / sizeof(float);
|
||||
return sampleFrame / instance->format.nSamplesPerSec;
|
||||
}
|
||||
else
|
||||
{
|
||||
return ((double)instance->soundData.streamingSound.mostRecentBufferOffset + instance->voice.handle->src.curBufferOffset) / instance->format.nSamplesPerSec;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log("Invalid sound instance!");
|
||||
return -1.0;
|
||||
|
|
Loading…
Reference in New Issue