Audio latency is much better. Sprites are corrupted in GAW
This commit is contained in:
@@ -89,7 +89,7 @@ namespace Desktop
|
|||||||
IsRunning = true;
|
IsRunning = true;
|
||||||
TotalFrameCount = 0;
|
TotalFrameCount = 0;
|
||||||
|
|
||||||
double TargetFrameTime = 1000.0 / 60.0;
|
double TargetFrameTime = 1000.0 / 59.92274;
|
||||||
|
|
||||||
_emulatorTask = Task.Run(() =>
|
_emulatorTask = Task.Run(() =>
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,25 +12,25 @@ namespace Desktop.Audio // Change this to match your project's namespace
|
|||||||
|
|
||||||
public NAudioPlayer()
|
public NAudioPlayer()
|
||||||
{
|
{
|
||||||
// Set up the audio format: 44100 Hz, 32-bit IEEE float, 1 channel (Mono)
|
|
||||||
WaveFormat format = WaveFormat.CreateIeeeFloatWaveFormat(44100, 1);
|
WaveFormat format = WaveFormat.CreateIeeeFloatWaveFormat(44100, 1);
|
||||||
|
|
||||||
_buffer = new BufferedWaveProvider(format);
|
_buffer = new BufferedWaveProvider(format);
|
||||||
|
|
||||||
// CRITICAL FOR EMULATORS:
|
// THE FIX: Restrict the physical size of the buffer to exactly 100 milliseconds!
|
||||||
// If the emulator runs slightly too fast, the audio buffer will fill up
|
// If the emulator generates audio too fast, the lag can never exceed this limit.
|
||||||
// and the sound will lag behind the gameplay. Discarding overflow keeps it synced!
|
_buffer.BufferDuration = TimeSpan.FromMilliseconds(100);
|
||||||
|
|
||||||
_buffer.DiscardOnBufferOverflow = true;
|
_buffer.DiscardOnBufferOverflow = true;
|
||||||
|
|
||||||
_waveOut = new WaveOutEvent();
|
_waveOut = new WaveOutEvent();
|
||||||
|
|
||||||
// 100ms latency is a great sweet spot for WinForms emulators.
|
// Drop the latency to 50ms for a tighter, snappier response
|
||||||
// Too low = crackling audio. Too high = delayed sound effects.
|
_waveOut.DesiredLatency = 50;
|
||||||
_waveOut.DesiredLatency = 100;
|
|
||||||
_waveOut.Init(_buffer);
|
_waveOut.Init(_buffer);
|
||||||
_waveOut.Play();
|
_waveOut.Play();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void AddSample(float sample)
|
public void AddSample(float sample)
|
||||||
{
|
{
|
||||||
// Convert the float (-1.0f to 1.0f) into 4 raw bytes
|
// Convert the float (-1.0f to 1.0f) into 4 raw bytes
|
||||||
|
|||||||
Reference in New Issue
Block a user