fix hangs when sound throttle is enabled and cores go a long time without giving samples. i mean,

This commit is contained in:
zeromus 2018-05-03 12:55:11 -05:00
parent a374f9f4b8
commit 2b53f9b954
1 changed files with 10 additions and 0 deletions

View File

@ -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
{