Render original lab and Jimmy with native Vulkan and SDL3 on .NET 10
This commit is contained in:
1 parent
3df20ac19a
commit
008c0e16da
41 files changed
+2125
-68
No files matched your search
@@ -0,0 +1,44 @@
|
||||
using GamePort.Platform;
|
||||
|
||||
namespace GamePort.Audio;
|
||||
|
||||
/// <summary>Plays recovered WAV unchanged through an SDL3 conversion/mixing stream.</summary>
|
||||
public sealed class SdlAudio : IDisposable
|
||||
{
|
||||
private nint stream;
|
||||
private nint data;
|
||||
private int length;
|
||||
private readonly bool loop;
|
||||
public int QueuedBytes
|
||||
{
|
||||
get
|
||||
{
|
||||
var bytes = Sdl.SDL_GetAudioStreamQueued(stream);
|
||||
return bytes >= 0 ? bytes : throw new InvalidOperationException(Sdl.Error);
|
||||
}
|
||||
}
|
||||
public SdlAudio(string path,bool loop=false)
|
||||
{
|
||||
this.loop=loop;
|
||||
if(!Sdl.SDL_InitSubSystem(Sdl.InitAudio))throw new InvalidOperationException(Sdl.Error);
|
||||
try
|
||||
{
|
||||
if(!Sdl.SDL_LoadWAV(Path.GetFullPath(path),out var spec,out data,out var size))throw new InvalidOperationException(Sdl.Error);
|
||||
length=checked((int)size);
|
||||
stream=Sdl.SDL_OpenAudioDeviceStream(uint.MaxValue,ref spec,0,0);
|
||||
if(stream==0)throw new InvalidOperationException(Sdl.Error);
|
||||
Queue();
|
||||
if(!Sdl.SDL_ResumeAudioStreamDevice(stream))throw new InvalidOperationException(Sdl.Error);
|
||||
Console.WriteLine($"SDL3 WAV stream: {spec.Frequency} Hz, {spec.Channels} channel(s), {length} source bytes.");
|
||||
}
|
||||
catch{Dispose();throw;}
|
||||
}
|
||||
private void Queue(){if(!Sdl.SDL_PutAudioStreamData(stream,data,length))throw new InvalidOperationException(Sdl.Error);}
|
||||
public void Pump(){if(loop && QueuedBytes<length)Queue();}
|
||||
public void Dispose()
|
||||
{
|
||||
if(stream!=0){Sdl.SDL_DestroyAudioStream(stream);stream=0;}
|
||||
if(data!=0){Sdl.SDL_free(data);data=0;}
|
||||
Sdl.SDL_QuitSubSystem(Sdl.InitAudio);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user