From 691632f1880efd98834d118e4859a59d3eb8b533 Mon Sep 17 00:00:00 2001 From: adelikat Date: Fri, 16 Dec 2016 08:50:05 -0600 Subject: [PATCH] More IAsyncSoundProvider and related classes to BizHawk.Emulation.Cores and make them internal, since they are implementation details, and they are deprecrated and not intended to be used in future cores. --- .../BizHawk.Emulation.Common.csproj | 2 - .../Sound/Utilities/Metaspu.cs | 58 --------- .../BizHawk.Emulation.Cores.csproj | 20 +-- .../Consoles/PC Engine/ADPCM.cs | 3 +- .../Consoles/Sega/SMS/SMS.ISoundProvider.cs | 3 +- .../Sound}/IAsyncSoundProvider.cs | 80 ++++++++++-- .../Sound}/SoundMixer.cs | 119 +++++++++--------- BizHawk.Emulation.Cores/Sound/YM2413.cs | 1 + BizHawk.Emulation.Cores/Sound/YM2612.cs | 2 + 9 files changed, 146 insertions(+), 142 deletions(-) rename {BizHawk.Emulation.Common/Interfaces => BizHawk.Emulation.Cores/Sound}/IAsyncSoundProvider.cs (51%) rename {BizHawk.Emulation.Common/Sound/Utilities => BizHawk.Emulation.Cores/Sound}/SoundMixer.cs (79%) diff --git a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj index ce06f98ac7..fd5a2c2852 100644 --- a/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj +++ b/BizHawk.Emulation.Common/BizHawk.Emulation.Common.csproj @@ -126,7 +126,6 @@ - @@ -147,7 +146,6 @@ - diff --git a/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs b/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs index be230af925..e473b94d75 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs +++ b/BizHawk.Emulation.Common/Sound/Utilities/Metaspu.cs @@ -58,64 +58,6 @@ namespace BizHawk.Emulation.Common } } - // An async sound provider - // Sound refactor TODO: can this be combined with the other Metaspu? - public class MetaspuSoundProvider : ISoundProvider - { - public MetaspuSoundProvider(ESynchMethod method) - { - Buffer = Metaspu.metaspu_construct(method); - } - - public ISynchronizingAudioBuffer Buffer { get; set; } - private readonly short[] pullBuffer = new short[1470]; - - public MetaspuSoundProvider() - : this(ESynchMethod.ESynchMethod_V) - { - } - - public void PullSamples(IAsyncSoundProvider source) - { - Array.Clear(pullBuffer, 0, 1470); - source.GetSamples(pullBuffer); - Buffer.enqueue_samples(pullBuffer, 735); - } - - public bool CanProvideAsync - { - get { return true; } - } - - public SyncSoundMode SyncMode - { - get { return 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.output_samples(samples, samples.Length / 2); - } - - public void DiscardSamples() - { - Buffer.clear(); - } - } - public interface ISynchronizingAudioBuffer { void enqueue_samples(short[] buf, int samples_provided); diff --git a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj index f6c9f2d3d7..daaac6ad08 100644 --- a/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj +++ b/BizHawk.Emulation.Cores/BizHawk.Emulation.Cores.csproj @@ -911,32 +911,32 @@ - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs - PCEngine.cs + PCEngine.cs @@ -1197,8 +1197,10 @@ + + diff --git a/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs b/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs index 3bace6afb6..03ec7dba05 100644 --- a/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs +++ b/BizHawk.Emulation.Cores/Consoles/PC Engine/ADPCM.cs @@ -1,9 +1,8 @@ using System; -using System.IO; -using System.Globalization; using BizHawk.Common; using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores.Components; namespace BizHawk.Emulation.Cores.PCEngine { diff --git a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ISoundProvider.cs b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ISoundProvider.cs index ba64537826..fd44ce7fe5 100644 --- a/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ISoundProvider.cs +++ b/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.ISoundProvider.cs @@ -1,5 +1,4 @@ -using System; -using BizHawk.Emulation.Common; +using BizHawk.Emulation.Cores.Components; namespace BizHawk.Emulation.Cores.Sega.MasterSystem { diff --git a/BizHawk.Emulation.Common/Interfaces/IAsyncSoundProvider.cs b/BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs similarity index 51% rename from BizHawk.Emulation.Common/Interfaces/IAsyncSoundProvider.cs rename to BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs index e06e30afb6..86aaca7e6e 100644 --- a/BizHawk.Emulation.Common/Interfaces/IAsyncSoundProvider.cs +++ b/BizHawk.Emulation.Cores/Sound/IAsyncSoundProvider.cs @@ -1,25 +1,26 @@ using System; +using BizHawk.Emulation.Common; -namespace BizHawk.Emulation.Common -{ - /// - /// This interface is for legacy sound implementations in some older cores - /// This needs to go away, but is provided here, for now - /// - public interface IAsyncSoundProvider +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 + /// TODO: this is a shim for now, and needs to go away /// turns an IAsyncSoundPRovider into a full ISoundProvider /// This is used in cores that have an async only sound implementation - /// better is impleemnt a sync sound option in those cores without the need for + /// better is implement a sync sound option in those cores without the need for /// this class or an IAsyncSoundPRovider interface /// - public class FakeSyncSound : ISoundProvider + internal class FakeSyncSound : ISoundProvider { private readonly IAsyncSoundProvider source; private readonly int spf; @@ -75,4 +76,63 @@ namespace BizHawk.Emulation.Common 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 + { + public MetaspuSoundProvider(ESynchMethod method) + { + Buffer = Metaspu.metaspu_construct(method); + } + + public ISynchronizingAudioBuffer Buffer { get; set; } + private readonly short[] pullBuffer = new short[1470]; + + public MetaspuSoundProvider() + : this(ESynchMethod.ESynchMethod_V) + { + } + + public void PullSamples(IAsyncSoundProvider source) + { + Array.Clear(pullBuffer, 0, 1470); + source.GetSamples(pullBuffer); + Buffer.enqueue_samples(pullBuffer, 735); + } + + public bool CanProvideAsync + { + get { return true; } + } + + public SyncSoundMode SyncMode + { + get { return 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.output_samples(samples, samples.Length / 2); + } + + public void DiscardSamples() + { + Buffer.clear(); + } + } } diff --git a/BizHawk.Emulation.Common/Sound/Utilities/SoundMixer.cs b/BizHawk.Emulation.Cores/Sound/SoundMixer.cs similarity index 79% rename from BizHawk.Emulation.Common/Sound/Utilities/SoundMixer.cs rename to BizHawk.Emulation.Cores/Sound/SoundMixer.cs index d4ab8b8e27..f370d977e9 100644 --- a/BizHawk.Emulation.Common/Sound/Utilities/SoundMixer.cs +++ b/BizHawk.Emulation.Cores/Sound/SoundMixer.cs @@ -1,59 +1,60 @@ -using System.Collections.Generic; - -namespace BizHawk.Emulation.Common -{ - /// - /// An interface that extends a sound provider to provide mixing capabilities through the SoundMixer class - /// - public interface IMixedSoundProvider : IAsyncSoundProvider - { - int MaxVolume { get; set; } - } - - // This is a straightforward class to mix/chain multiple ISoundProvider sources. - public sealed class SoundMixer : IAsyncSoundProvider - { - private readonly List SoundProviders; - - public SoundMixer(params IMixedSoundProvider[] soundProviders) - { - SoundProviders = new List(soundProviders); - } - - public void AddSource(IMixedSoundProvider source) - { - SoundProviders.Add(source); - } - - public void DisableSource(IMixedSoundProvider source) - { - SoundProviders.Remove(source); - } - - public void DiscardSamples() - { - foreach (var soundSource in SoundProviders) - { - soundSource.DiscardSamples(); - } - } - - public void GetSamples(short[] samples) - { - foreach (var soundSource in SoundProviders) - { - soundSource.GetSamples(samples); - } - } - - // Splits the volume space equally between available sources. - public void EqualizeVolumes() - { - int eachVolume = short.MaxValue / SoundProviders.Count; - foreach (var source in SoundProviders) - { - source.MaxVolume = eachVolume; - } - } - } -} +using System.Collections.Generic; + +namespace BizHawk.Emulation.Cores.Components +{ + // TODO: Sound mixer is a good concept, but it needs to be refactored to use an ISoundProvider, it perhaps can enforce only recieving providers in Async mode + /// + /// An interface that extends a sound provider to provide mixing capabilities through the SoundMixer class + /// + internal interface IMixedSoundProvider : IAsyncSoundProvider + { + int MaxVolume { get; set; } + } + + // This is a straightforward class to mix/chain multiple ISoundProvider sources. + internal sealed class SoundMixer : IAsyncSoundProvider + { + private readonly List SoundProviders; + + public SoundMixer(params IMixedSoundProvider[] soundProviders) + { + SoundProviders = new List(soundProviders); + } + + public void AddSource(IMixedSoundProvider source) + { + SoundProviders.Add(source); + } + + public void DisableSource(IMixedSoundProvider source) + { + SoundProviders.Remove(source); + } + + public void DiscardSamples() + { + foreach (var soundSource in SoundProviders) + { + soundSource.DiscardSamples(); + } + } + + public void GetSamples(short[] samples) + { + foreach (var soundSource in SoundProviders) + { + soundSource.GetSamples(samples); + } + } + + // Splits the volume space equally between available sources. + public void EqualizeVolumes() + { + int eachVolume = short.MaxValue / SoundProviders.Count; + foreach (var source in SoundProviders) + { + source.MaxVolume = eachVolume; + } + } + } +} diff --git a/BizHawk.Emulation.Cores/Sound/YM2413.cs b/BizHawk.Emulation.Cores/Sound/YM2413.cs index 2aa41032bb..c902e88a4e 100644 --- a/BizHawk.Emulation.Cores/Sound/YM2413.cs +++ b/BizHawk.Emulation.Cores/Sound/YM2413.cs @@ -7,6 +7,7 @@ using System; using BizHawk.Common; +using BizHawk.Emulation.Cores.Components; namespace BizHawk.Emulation.Common.Components { diff --git a/BizHawk.Emulation.Cores/Sound/YM2612.cs b/BizHawk.Emulation.Cores/Sound/YM2612.cs index 3e96a49f83..a856524c57 100644 --- a/BizHawk.Emulation.Cores/Sound/YM2612.cs +++ b/BizHawk.Emulation.Cores/Sound/YM2612.cs @@ -2,6 +2,8 @@ using System.Collections.Generic; using System.IO; +using BizHawk.Emulation.Cores.Components; + namespace BizHawk.Emulation.Common.Components { // ======================================================================