From 883d9d220766c9e1b3c8938ccdfe7cb08606a006 Mon Sep 17 00:00:00 2001 From: adelikat Date: Thu, 27 Apr 2017 12:12:11 -0500 Subject: [PATCH] Rename MetaspuAsync to MetaspuAsyncSoundProvider and remove the todo, also friendlier enum names --- .../Sound/Utilities/Metaspu.cs | 21 +- .../Consoles/PC Engine/ADPCM.cs | 2 +- .../Sound/IAsyncSoundProvider.cs | 252 +++++++++--------- 3 files changed, 137 insertions(+), 138 deletions(-) diff --git a/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs b/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs index 38ca793412..a4b4de202f 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs +++ b/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs @@ -8,11 +8,11 @@ namespace BizHawk.Emulation.Common { switch (method) { - case ESynchMethod.ESynchMethod_Z: + case ESynchMethod.Zeromus: return new ZeromusSynchronizer(); - case ESynchMethod.ESynchMethod_N: + case ESynchMethod.Nitsuja: return new NitsujaSynchronizer(); - case ESynchMethod.ESynchMethod_V: + case ESynchMethod.Vecna: return new VecnaSynchronizer(); default: return new NitsujaSynchronizer(); @@ -21,15 +21,14 @@ namespace BizHawk.Emulation.Common } /// - /// uses Metaspu to provide async sound to an ISoundProvider that does not provide its own async implementation + /// uses to provide async sound to an that does not provide its own async implementation /// - // Sound Refactor TODO: rename me to MetaspuAsyncSoundProvider - public class MetaspuAsync : ISoundProvider + public class MetaspuAsyncSoundProvider : ISoundProvider { private readonly ISynchronizingAudioBuffer _buffer; private readonly ISoundProvider _input; - public MetaspuAsync(ISoundProvider input, ESynchMethod method) + public MetaspuAsyncSoundProvider(ISoundProvider input, ESynchMethod method) { input.SetSyncMode(SyncSoundMode.Sync); _buffer = Metaspu.MetaspuConstruct(method); @@ -71,9 +70,9 @@ namespace BizHawk.Emulation.Common public enum ESynchMethod { - ESynchMethod_N, // nitsuja's - ESynchMethod_Z, // zero's - ////ESynchMethod_P, //PCSX2 spu2-x //ohno! not available yet in c# - ESynchMethod_V // vecna + Nitsuja, // nitsuja's + Zeromus, // zero's + ////PCSX2, //PCSX2 spu2-x //ohno! not available yet in c# + Vecna // vecna } } \ No newline at end of file diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs index 62b2776e08..89472c489b 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs @@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.PCEngine { ScsiCDBus SCSI; PCEngine pce; - MetaspuSoundProvider SoundProvider = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V); + MetaspuSoundProvider SoundProvider = new MetaspuSoundProvider(ESynchMethod.Vecna); // *************************************************************************** diff --git a/BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs b/BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs index 817df23700..564735fb76 100644 --- a/BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs +++ b/BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs @@ -1,131 +1,131 @@ -using System; -using BizHawk.Emulation.Common; - -namespace BizHawk.Emulation.Cores.Components -{ - /// - /// This interface is for legacy sound implementations in some older cores - /// This needs to go away, but is provided here, for now - /// - internal interface IAsyncSoundProvider - { - void GetSamples(short[] samples); - void DiscardSamples(); +using System; +using BizHawk.Emulation.Common; + +namespace BizHawk.Emulation.Cores.Components +{ + /// + /// This interface is for legacy sound implementations in some older cores + /// This needs to go away, but is provided here, for now + /// + internal interface IAsyncSoundProvider + { + void GetSamples(short[] samples); + void DiscardSamples(); } - /// - /// TODO: this is a shim for now, and needs to go away - /// turns an into a full ISoundProvider - /// This is used in cores that have an async only sound implementation - /// better is implement a sync sound option in those cores without the need for - /// this class or an IAsyncSoundProvider interface - /// - internal class FakeSyncSound : ISoundProvider - { - private readonly IAsyncSoundProvider _source; - private readonly int _spf; - - /// - /// Initializes a new instance of the class. - /// - /// The async sound provider - /// number of sample pairs to request and provide on each GetSamples() call - public FakeSyncSound(IAsyncSoundProvider source, int spf) - { - _source = source; - _spf = spf; - SyncMode = SyncSoundMode.Sync; - } - - public void GetSamplesSync(out short[] samples, out int nsamp) - { - if (SyncMode != SyncSoundMode.Sync) - { - throw new InvalidOperationException("Must be in sync mode to call a sync method"); - } - - short[] ret = new short[_spf * 2]; - _source.GetSamples(ret); - samples = ret; - nsamp = _spf; - } - - public void DiscardSamples() - { - _source.DiscardSamples(); - } - - public void GetSamplesAsync(short[] samples) - { - if (SyncMode != SyncSoundMode.Async) - { - throw new InvalidOperationException("Must be in async mode to call an async method"); - } - - _source.GetSamples(samples); - } - - public bool CanProvideAsync => true; - - public SyncSoundMode SyncMode { get; private set; } - - public void SetSyncMode(SyncSoundMode mode) - { - SyncMode = mode; - } - } - - // An async sound provider - // This class needs to go away, it takes an IAsyncSoundProvider - // and is only used by legacy sound implementations - internal class MetaspuSoundProvider : ISoundProvider + /// + /// TODO: this is a shim for now, and needs to go away + /// turns an into a full ISoundProvider + /// This is used in cores that have an async only sound implementation + /// better is implement a sync sound option in those cores without the need for + /// this class or an IAsyncSoundProvider interface + /// + internal class FakeSyncSound : ISoundProvider + { + private readonly IAsyncSoundProvider _source; + private readonly int _spf; + + /// + /// Initializes a new instance of the class. + /// + /// The async sound provider + /// number of sample pairs to request and provide on each GetSamples() call + public FakeSyncSound(IAsyncSoundProvider source, int spf) + { + _source = source; + _spf = spf; + SyncMode = SyncSoundMode.Sync; + } + + public void GetSamplesSync(out short[] samples, out int nsamp) + { + if (SyncMode != SyncSoundMode.Sync) + { + throw new InvalidOperationException("Must be in sync mode to call a sync method"); + } + + short[] ret = new short[_spf * 2]; + _source.GetSamples(ret); + samples = ret; + nsamp = _spf; + } + + public void DiscardSamples() + { + _source.DiscardSamples(); + } + + public void GetSamplesAsync(short[] samples) + { + if (SyncMode != SyncSoundMode.Async) + { + throw new InvalidOperationException("Must be in async mode to call an async method"); + } + + _source.GetSamples(samples); + } + + public bool CanProvideAsync => true; + + public SyncSoundMode SyncMode { get; private set; } + + public void SetSyncMode(SyncSoundMode mode) + { + SyncMode = mode; + } + } + + // An async sound provider + // This class needs to go away, it takes an IAsyncSoundProvider + // and is only used by legacy sound implementations + internal class MetaspuSoundProvider : ISoundProvider { private readonly short[] _pullBuffer = new short[1470]; - public MetaspuSoundProvider(ESynchMethod method) - { - Buffer = Metaspu.MetaspuConstruct(method); - } - - public ISynchronizingAudioBuffer Buffer { get; } - - public MetaspuSoundProvider() - : this(ESynchMethod.ESynchMethod_V) - { - } - - public void PullSamples(IAsyncSoundProvider source) - { - Array.Clear(_pullBuffer, 0, 1470); - source.GetSamples(_pullBuffer); - Buffer.EnqueueSamples(_pullBuffer, 735); - } - - public bool CanProvideAsync => true; - - public SyncSoundMode SyncMode => SyncSoundMode.Async; - - public void SetSyncMode(SyncSoundMode mode) - { - if (mode != SyncSoundMode.Async) - { - throw new NotSupportedException("Only Async mode is supported."); - } - } - - public void GetSamplesSync(out short[] samples, out int nsamp) - { - throw new InvalidOperationException("Sync mode is not supported."); - } - - public void GetSamplesAsync(short[] samples) - { - Buffer.OutputSamples(samples, samples.Length / 2); - } - - public void DiscardSamples() - { - Buffer.Clear(); - } - } -} + public MetaspuSoundProvider(ESynchMethod method) + { + Buffer = Metaspu.MetaspuConstruct(method); + } + + public ISynchronizingAudioBuffer Buffer { get; } + + public MetaspuSoundProvider() + : this(ESynchMethod.Vecna) + { + } + + public void PullSamples(IAsyncSoundProvider source) + { + Array.Clear(_pullBuffer, 0, 1470); + source.GetSamples(_pullBuffer); + Buffer.EnqueueSamples(_pullBuffer, 735); + } + + public bool CanProvideAsync => true; + + public SyncSoundMode SyncMode => SyncSoundMode.Async; + + public void SetSyncMode(SyncSoundMode mode) + { + if (mode != SyncSoundMode.Async) + { + throw new NotSupportedException("Only Async mode is supported."); + } + } + + public void GetSamplesSync(out short[] samples, out int nsamp) + { + throw new InvalidOperationException("Sync mode is not supported."); + } + + public void GetSamplesAsync(short[] samples) + { + Buffer.OutputSamples(samples, samples.Length / 2); + } + + public void DiscardSamples() + { + Buffer.Clear(); + } + } +}