Audio latency is much better. Sprites are corrupted in GAW

This commit is contained in:
2026-05-14 22:39:43 +01:00
parent 780f8ee790
commit a9b15ee113
2 changed files with 8 additions and 8 deletions

View File

@@ -12,24 +12,24 @@ namespace Desktop.Audio // Change this to match your project's namespace
public NAudioPlayer()
{
// Set up the audio format: 44100 Hz, 32-bit IEEE float, 1 channel (Mono)
WaveFormat format = WaveFormat.CreateIeeeFloatWaveFormat(44100, 1);
_buffer = new BufferedWaveProvider(format);
// CRITICAL FOR EMULATORS:
// If the emulator runs slightly too fast, the audio buffer will fill up
// and the sound will lag behind the gameplay. Discarding overflow keeps it synced!
// THE FIX: Restrict the physical size of the buffer to exactly 100 milliseconds!
// If the emulator generates audio too fast, the lag can never exceed this limit.
_buffer.BufferDuration = TimeSpan.FromMilliseconds(100);
_buffer.DiscardOnBufferOverflow = true;
_waveOut = new WaveOutEvent();
// 100ms latency is a great sweet spot for WinForms emulators.
// Too low = crackling audio. Too high = delayed sound effects.
_waveOut.DesiredLatency = 100;
// Drop the latency to 50ms for a tighter, snappier response
_waveOut.DesiredLatency = 50;
_waveOut.Init(_buffer);
_waveOut.Play();
}
public void AddSample(float sample)
{