add StaticSound.FromQOA
parent
6cd44c6f24
commit
8829b7bcc3
|
@ -197,6 +197,39 @@ namespace MoonWorks.Audio
|
|||
return sound;
|
||||
}
|
||||
|
||||
public static unsafe StaticSound FromQOA(AudioDevice device, string path)
|
||||
{
|
||||
var fileStream = new FileStream(path, FileMode.Open, FileAccess.Read);
|
||||
var fileDataPtr = NativeMemory.Alloc((nuint) fileStream.Length);
|
||||
var fileDataSpan = new Span<byte>(fileDataPtr, (int) fileStream.Length);
|
||||
fileStream.ReadExactly(fileDataSpan);
|
||||
fileStream.Close();
|
||||
|
||||
var qoaHandle = FAudio.qoa_open((char*) fileDataPtr, (uint) fileDataSpan.Length);
|
||||
if (qoaHandle == 0)
|
||||
{
|
||||
NativeMemory.Free(fileDataPtr);
|
||||
Logger.LogError("Error opening QOA file!");
|
||||
throw new AudioLoadException("Error opening QOA file!");
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
return new StaticSound(
|
||||
device,
|
||||
1,
|
||||
16,
|
||||
(ushort) (channels * 2),
|
||||
(ushort) channels,
|
||||
samplerate,
|
||||
(nint) buffer,
|
||||
total_samples_per_channel * channels * sizeof(short),
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
public StaticSound(
|
||||
AudioDevice device,
|
||||
ushort formatTag,
|
||||
|
|
Loading…
Reference in New Issue