From 6a81746636e7caef9d5a0182a19cd8251f9c33ed Mon Sep 17 00:00:00 2001 From: jdpurcell Date: Fri, 23 Jan 2015 05:39:19 +0000 Subject: [PATCH] Temporary fix for N64 sound problems with new sound provider. --- BizHawk.Client.EmuHawk/SoundOutputProvider.cs | 30 ++++++++++++++++--- 1 file changed, 26 insertions(+), 4 deletions(-) diff --git a/BizHawk.Client.EmuHawk/SoundOutputProvider.cs b/BizHawk.Client.EmuHawk/SoundOutputProvider.cs index 2972663a4e..c15613ef07 100644 --- a/BizHawk.Client.EmuHawk/SoundOutputProvider.cs +++ b/BizHawk.Client.EmuHawk/SoundOutputProvider.cs @@ -37,6 +37,10 @@ namespace BizHawk.Client.EmuHawk private Queue _outputCountHistory = new Queue(); private Queue _hardCorrectionHistory = new Queue(); + private bool _disableFramerateCompensation; + private double _lastSamplesPerFrame; + private int _lastBaseProviderSampleCount; + private short[] _resampleBuffer = new short[0]; private double _resampleLengthRoundingError; @@ -52,6 +56,9 @@ namespace BizHawk.Client.EmuHawk _extraCountHistory.Clear(); _outputCountHistory.Clear(); _hardCorrectionHistory.Clear(); + _disableFramerateCompensation = false; + _lastSamplesPerFrame = 0.0; + _lastBaseProviderSampleCount = 0; _resampleBuffer = new short[0]; _resampleLengthRoundingError = 0.0; @@ -122,11 +129,12 @@ namespace BizHawk.Client.EmuHawk if (LogDebug) { - Console.WriteLine("Avg: {0:0.0} ms, Min: {1:0.0} ms, Max: {2:0.0} ms, Scale: {3:0.0000}", + Console.WriteLine("Avg: {0:0.0} ms, Min: {1:0.0} ms, Max: {2:0.0} ms, Scale: {3:0.0000} {4}", _extraCountHistory.Average() * 1000.0 / SampleRate, _extraCountHistory.Min() * 1000.0 / SampleRate, _extraCountHistory.Max() * 1000.0 / SampleRate, - scaleFactor); + scaleFactor, + _disableFramerateCompensation ? "*" : ""); } return outputSampleCount; @@ -139,11 +147,25 @@ namespace BizHawk.Client.EmuHawk BaseSoundProvider.GetSamples(out samples, out count); - if (count != 0) + if (SamplesPerFrame != _lastSamplesPerFrame) { - scaleFactor *= SamplesPerFrame / count; + _disableFramerateCompensation = false; } + if (count != 0 && !_disableFramerateCompensation) + { + if (_lastBaseProviderSampleCount != 0 && Math.Abs(count - _lastBaseProviderSampleCount) > 10) + { + _disableFramerateCompensation = true; + } + + scaleFactor *= SamplesPerFrame / count; + + _lastBaseProviderSampleCount = count; + } + + _lastSamplesPerFrame = SamplesPerFrame; + double newCountTarget = count * scaleFactor; int newCount = (int)Math.Round(newCountTarget + _resampleLengthRoundingError); // Do not resample for one-sample differences. With NTSC @ 59.94 FPS, for example,