From 2b53f9b9541bf96f4c908cf797118d7cb971dc18 Mon Sep 17 00:00:00 2001 From: zeromus Date: Thu, 3 May 2018 12:55:11 -0500 Subject: [PATCH] fix hangs when sound throttle is enabled and cores go a long time without giving samples. i mean, --- BizHawk.Client.EmuHawk/Sound/Sound.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/BizHawk.Client.EmuHawk/Sound/Sound.cs b/BizHawk.Client.EmuHawk/Sound/Sound.cs index 84362490e7..88a94e44c9 100644 --- a/BizHawk.Client.EmuHawk/Sound/Sound.cs +++ b/BizHawk.Client.EmuHawk/Sound/Sound.cs @@ -15,6 +15,8 @@ namespace BizHawk.Client.EmuHawk public const int BlockAlign = BytesPerSample * ChannelCount; private bool _disposed; + private bool _unjamSoundThrottle; + private readonly ISoundOutput _outputDevice; private readonly SoundOutputProvider _outputProvider = new SoundOutputProvider(); // Buffer for Sync sources private readonly BufferedAsync _bufferedAsync = new BufferedAsync(); // Buffer for Async sources @@ -117,6 +119,7 @@ namespace BizHawk.Client.EmuHawk int silenceSamples = Math.Max(samplesNeeded - samplesPerFrame, 0); _outputDevice.WriteSamples(new short[silenceSamples * 2], silenceSamples); samplesNeeded -= silenceSamples; + _unjamSoundThrottle = isUnderrun; if (isUnderrun) { @@ -163,7 +166,14 @@ namespace BizHawk.Client.EmuHawk { Thread.Sleep((samplesProvided - samplesNeeded) / (SampleRate / 1000)); // Let the audio clock control sleep time samplesNeeded = _outputDevice.CalculateSamplesNeeded(); + if (_unjamSoundThrottle) + { + //may be garbage, but what can we do? + samplesProvided = samplesNeeded; + break; + } } + _unjamSoundThrottle = false; } else {