From c284037c62614489f2511c1e2356be2ab39f11e9 Mon Sep 17 00:00:00 2001 From: cosmonaut Date: Thu, 4 May 2023 12:11:24 -0700 Subject: [PATCH] QOA data open API tweak --- lib/FAudio | 2 +- src/Audio/StaticSound.cs | 11 ++++++++--- src/Audio/StreamingSoundQoa.cs | 2 +- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/FAudio b/lib/FAudio index a016259..f065a55 160000 --- a/lib/FAudio +++ b/lib/FAudio @@ -1 +1 @@ -Subproject commit a016259994797f96db2bda75c90b359258e99d09 +Subproject commit f065a5519fa2a1020eb971c0da66c877f2a97f18 diff --git a/src/Audio/StaticSound.cs b/src/Audio/StaticSound.cs index d2566a3..9cae8eb 100644 --- a/src/Audio/StaticSound.cs +++ b/src/Audio/StaticSound.cs @@ -205,7 +205,7 @@ namespace MoonWorks.Audio fileStream.ReadExactly(fileDataSpan); fileStream.Close(); - var qoaHandle = FAudio.qoa_open((char*) fileDataPtr, (uint) fileDataSpan.Length); + var qoaHandle = FAudio.qoa_open_memory((char*) fileDataPtr, (uint) fileDataSpan.Length); if (qoaHandle == 0) { NativeMemory.Free(fileDataPtr); @@ -215,7 +215,12 @@ namespace MoonWorks.Audio FAudio.qoa_attributes(qoaHandle, out var channels, out var samplerate, out var samples_per_channel_per_frame, out var total_samples_per_channel); - var buffer = FAudio.qoa_load(qoaHandle); + var bufferLengthInBytes = total_samples_per_channel * channels * sizeof(short); + var buffer = NativeMemory.Alloc(bufferLengthInBytes); + FAudio.qoa_decode_entire(qoaHandle, (short*) buffer); + + FAudio.qoa_close(qoaHandle); + NativeMemory.Free(fileDataPtr); return new StaticSound( device, @@ -225,7 +230,7 @@ namespace MoonWorks.Audio (ushort) channels, samplerate, (nint) buffer, - total_samples_per_channel * channels * sizeof(short), + bufferLengthInBytes, true ); } diff --git a/src/Audio/StreamingSoundQoa.cs b/src/Audio/StreamingSoundQoa.cs index 012ca16..9322e0e 100644 --- a/src/Audio/StreamingSoundQoa.cs +++ b/src/Audio/StreamingSoundQoa.cs @@ -23,7 +23,7 @@ namespace MoonWorks.Audio fileStream.ReadExactly(fileDataSpan); fileStream.Close(); - var qoaHandle = FAudio.qoa_open((char*) fileDataPtr, (uint) fileDataSpan.Length); + var qoaHandle = FAudio.qoa_open_memory((char*) fileDataPtr, (uint) fileDataSpan.Length); if (qoaHandle == 0) { NativeMemory.Free(fileDataPtr);