Audio latency is much better. Sprites are corrupted in GAW
This commit is contained in:
@@ -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)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user