From dbdac5e3f202bb7154a3d7922a8e21034568b155 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Sun, 11 Dec 2016 22:37:28 -0500 Subject: [PATCH] Fix stuff or not --- BizHawk.Client.EmuHawk/MainForm.cs | 9 +-- .../SimpleSyncSoundProvider.cs | 65 +++++++++++++++++++ .../BizHawk.Emulation.Common.csproj | 1 + 3 files changed, 71 insertions(+), 4 deletions(-) create mode 100644 BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs diff --git a/BizHawk.Client.EmuHawk/MainForm.cs b/BizHawk.Client.EmuHawk/MainForm.cs index ab98f43e72..f8cff1ccea 100644 --- a/BizHawk.Client.EmuHawk/MainForm.cs +++ b/BizHawk.Client.EmuHawk/MainForm.cs @@ -35,6 +35,7 @@ using BizHawk.Client.EmuHawk.WinFormExtensions; using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.CoreExtensions; using BizHawk.Client.ApiHawk; +using BizHawk.Emulation.Common.Base_Implementations; namespace BizHawk.Client.EmuHawk { @@ -1353,7 +1354,7 @@ namespace BizHawk.Client.EmuHawk // Sound refator TODO: we can enforce async mode here with a property that gets/sets this but does an async check private ISoundProvider _aviSoundInputAsync; // Note: This sound provider must be in async mode! - private MetaspuSoundProvider _dumpProxy; // an audio proxy used for dumping + private SimpleSyncSoundProvider _dumpProxy; // an audio proxy used for dumping private bool _dumpaudiosync; // set true to for experimental AV dumping private int _avwriterResizew; private int _avwriterResizeh; @@ -1623,7 +1624,7 @@ namespace BizHawk.Client.EmuHawk { // we're video dumping, so async mode only and use the DumpProxy. // note that the avi dumper has already rewired the emulator itself in this case. - GlobalWin.Sound.SetAsyncInputPin(_dumpProxy); + GlobalWin.Sound.SetSyncInputPin(_dumpProxy); } else if (Global.Config.SoundThrottle || !_currentSoundProvider.CanProvideAsync) { @@ -3123,7 +3124,7 @@ namespace BizHawk.Client.EmuHawk _aviSoundInputAsync = new MetaspuAsync(_currentSoundProvider, ESynchMethod.ESynchMethod_V); } } - _dumpProxy = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V); + _dumpProxy = new SimpleSyncSoundProvider(); RewireSound(); } @@ -3257,7 +3258,7 @@ namespace BizHawk.Client.EmuHawk disposableOutput.Dispose(); } - _dumpProxy.Buffer.enqueue_samples(samp, nsamp); + _dumpProxy.PutSamples(samp, nsamp); } catch (Exception e) { diff --git a/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs b/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs new file mode 100644 index 0000000000..378aaf44d7 --- /dev/null +++ b/BizHawk.Emulation.Common/Base Implementations/SimpleSyncSoundProvider.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace BizHawk.Emulation.Common.Base_Implementations +{ + /// + /// A simple sound provider that will operate in sync mode only, offering back whatever data was sent in PutSamples + /// + public class SimpleSyncSoundProvider : ISoundProvider + { + private short[] _buffer = new short[0]; + private int _nsamp = 0; + + public bool CanProvideAsync + { + get { return false; } + } + + public void SetSyncMode(SyncSoundMode mode) + { + if (mode != SyncSoundMode.Sync) + throw new ArgumentException("Only supports Sync mode"); + } + + public SyncSoundMode SyncMode + { + get { return SyncSoundMode.Sync; } + } + + /// + /// Add samples to be output. no queueing; must be drained every frame + /// + /// + /// + public void PutSamples(short[] samples, int nsamp) + { + if (_nsamp != 0) + Console.WriteLine("Warning: Samples disappeared from SimpleSyncSoundProvider"); + + if (_buffer.Length < nsamp * 2) + _buffer = new short[nsamp * 2]; + Array.Copy(samples, _buffer, nsamp * 2); + _nsamp = nsamp; + } + + public void GetSamplesSync(out short[] samples, out int nsamp) + { + samples = _buffer; + nsamp = _nsamp; + _nsamp = 0; + } + + public void GetSamplesAsync(short[] samples) + { + throw new NotImplementedException(); + } + + public void DiscardSamples() + { + _nsamp = 0; + } + } +} diff --git a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj index 0ca128175d..761265bec4 100644 --- a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj +++ b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj @@ -102,6 +102,7 @@ +