Implement source-backed Scooter vehicle in tutorial and outside

This commit is contained in:
UnixNight committed 2026-11-04 18:06:09 -05:00
1 parent 8df5e81070
commit 62c07a3d59
44 files changed
+3135 -174

No files matched your search

+7
View File
@@ -10,6 +10,7 @@ public sealed class SdlAudio : IDisposable
private int length;
private readonly bool loop;
private bool audioInitialized;
public int SourceFrequency {get;private set;}
public bool Paused { get; private set; }
public bool Muted { get; private set; }
public int QueuedBytes
@@ -28,6 +29,7 @@ public sealed class SdlAudio : IDisposable
try
{
if(!Sdl.SDL_LoadWAV(Path.GetFullPath(path),out var spec,out data,out var size))throw new InvalidOperationException(Sdl.Error);
SourceFrequency=spec.Frequency;
length=checked((int)size);
stream=Sdl.SDL_OpenAudioDeviceStream(uint.MaxValue,ref spec,0,0);
if(stream==0)throw new InvalidOperationException(Sdl.Error);
@@ -55,6 +57,11 @@ public sealed class SdlAudio : IDisposable
if (!Sdl.SDL_SetAudioStreamGain(stream, muted ? 0 : 1)) throw new InvalidOperationException(Sdl.Error);
Muted = muted;
}
public void SetFrequency(int frequency)
{
ObjectDisposedException.ThrowIf(stream==0,this);
if(frequency<=0||!Sdl.SDL_SetAudioStreamFrequencyRatio(stream,(float)frequency/SourceFrequency))throw new InvalidOperationException(Sdl.Error);
}
private void Queue(){if(!Sdl.SDL_PutAudioStreamData(stream,data,length))throw new InvalidOperationException(Sdl.Error);}
public void Pump(){if(!Paused && loop && QueuedBytes<length)Queue();}
public void Dispose()