Rename MetaspuAsync to MetaspuAsyncSoundProvider and remove the todo, also friendlier enum names

This commit is contained in:
adelikat 2017-04-27 12:12:11 -05:00
parent 957736b787
commit 883d9d2207
3 changed files with 137 additions and 138 deletions

View File

@ -8,11 +8,11 @@ namespace BizHawk.Emulation.Common
{ {
switch (method) switch (method)
{ {
case ESynchMethod.ESynchMethod_Z: case ESynchMethod.Zeromus:
return new ZeromusSynchronizer(); return new ZeromusSynchronizer();
case ESynchMethod.ESynchMethod_N: case ESynchMethod.Nitsuja:
return new NitsujaSynchronizer(); return new NitsujaSynchronizer();
case ESynchMethod.ESynchMethod_V: case ESynchMethod.Vecna:
return new VecnaSynchronizer(); return new VecnaSynchronizer();
default: default:
return new NitsujaSynchronizer(); return new NitsujaSynchronizer();
@ -21,15 +21,14 @@ namespace BizHawk.Emulation.Common
} }
/// <summary> /// <summary>
/// uses Metaspu to provide async sound to an ISoundProvider that does not provide its own async implementation /// uses <seealso cref="Metaspu"/> to provide async sound to an <seealso cref="ISoundProvider"/> that does not provide its own async implementation
/// </summary> /// </summary>
// Sound Refactor TODO: rename me to MetaspuAsyncSoundProvider public class MetaspuAsyncSoundProvider : ISoundProvider
public class MetaspuAsync : ISoundProvider
{ {
private readonly ISynchronizingAudioBuffer _buffer; private readonly ISynchronizingAudioBuffer _buffer;
private readonly ISoundProvider _input; private readonly ISoundProvider _input;
public MetaspuAsync(ISoundProvider input, ESynchMethod method) public MetaspuAsyncSoundProvider(ISoundProvider input, ESynchMethod method)
{ {
input.SetSyncMode(SyncSoundMode.Sync); input.SetSyncMode(SyncSoundMode.Sync);
_buffer = Metaspu.MetaspuConstruct(method); _buffer = Metaspu.MetaspuConstruct(method);
@ -71,9 +70,9 @@ namespace BizHawk.Emulation.Common
public enum ESynchMethod public enum ESynchMethod
{ {
ESynchMethod_N, // nitsuja's Nitsuja, // nitsuja's
ESynchMethod_Z, // zero's Zeromus, // zero's
////ESynchMethod_P, //PCSX2 spu2-x //ohno! not available yet in c# ////PCSX2, //PCSX2 spu2-x //ohno! not available yet in c#
ESynchMethod_V // vecna Vecna // vecna
} }
} }

View File

@ -10,7 +10,7 @@ namespace BizHawk.Emulation.Cores.PCEngine
{ {
ScsiCDBus SCSI; ScsiCDBus SCSI;
PCEngine pce; PCEngine pce;
MetaspuSoundProvider SoundProvider = new MetaspuSoundProvider(ESynchMethod.ESynchMethod_V); MetaspuSoundProvider SoundProvider = new MetaspuSoundProvider(ESynchMethod.Vecna);
// *************************************************************************** // ***************************************************************************

View File

@ -1,131 +1,131 @@
using System; using System;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Components namespace BizHawk.Emulation.Cores.Components
{ {
/// <summary> /// <summary>
/// This interface is for legacy sound implementations in some older cores /// This interface is for legacy sound implementations in some older cores
/// This needs to go away, but is provided here, for now /// This needs to go away, but is provided here, for now
/// </summary> /// </summary>
internal interface IAsyncSoundProvider internal interface IAsyncSoundProvider
{ {
void GetSamples(short[] samples); void GetSamples(short[] samples);
void DiscardSamples(); void DiscardSamples();
} }
/// <summary> /// <summary>
/// TODO: this is a shim for now, and needs to go away /// TODO: this is a shim for now, and needs to go away
/// turns an <seealso cref="IAsyncSoundProvider"/> into a full ISoundProvider /// turns an <seealso cref="IAsyncSoundProvider"/> into a full ISoundProvider
/// This is used in cores that have an async only sound implementation /// 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 /// better is implement a sync sound option in those cores without the need for
/// this class or an IAsyncSoundProvider interface /// this class or an IAsyncSoundProvider interface
/// </summary> /// </summary>
internal class FakeSyncSound : ISoundProvider internal class FakeSyncSound : ISoundProvider
{ {
private readonly IAsyncSoundProvider _source; private readonly IAsyncSoundProvider _source;
private readonly int _spf; private readonly int _spf;
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="FakeSyncSound"/> class. /// Initializes a new instance of the <see cref="FakeSyncSound"/> class.
/// </summary> /// </summary>
/// <param name="source">The async sound provider</param> /// <param name="source">The async sound provider</param>
/// <param name="spf">number of sample pairs to request and provide on each GetSamples() call</param> /// <param name="spf">number of sample pairs to request and provide on each GetSamples() call</param>
public FakeSyncSound(IAsyncSoundProvider source, int spf) public FakeSyncSound(IAsyncSoundProvider source, int spf)
{ {
_source = source; _source = source;
_spf = spf; _spf = spf;
SyncMode = SyncSoundMode.Sync; SyncMode = SyncSoundMode.Sync;
} }
public void GetSamplesSync(out short[] samples, out int nsamp) public void GetSamplesSync(out short[] samples, out int nsamp)
{ {
if (SyncMode != SyncSoundMode.Sync) if (SyncMode != SyncSoundMode.Sync)
{ {
throw new InvalidOperationException("Must be in sync mode to call a sync method"); throw new InvalidOperationException("Must be in sync mode to call a sync method");
} }
short[] ret = new short[_spf * 2]; short[] ret = new short[_spf * 2];
_source.GetSamples(ret); _source.GetSamples(ret);
samples = ret; samples = ret;
nsamp = _spf; nsamp = _spf;
} }
public void DiscardSamples() public void DiscardSamples()
{ {
_source.DiscardSamples(); _source.DiscardSamples();
} }
public void GetSamplesAsync(short[] samples) public void GetSamplesAsync(short[] samples)
{ {
if (SyncMode != SyncSoundMode.Async) if (SyncMode != SyncSoundMode.Async)
{ {
throw new InvalidOperationException("Must be in async mode to call an async method"); throw new InvalidOperationException("Must be in async mode to call an async method");
} }
_source.GetSamples(samples); _source.GetSamples(samples);
} }
public bool CanProvideAsync => true; public bool CanProvideAsync => true;
public SyncSoundMode SyncMode { get; private set; } public SyncSoundMode SyncMode { get; private set; }
public void SetSyncMode(SyncSoundMode mode) public void SetSyncMode(SyncSoundMode mode)
{ {
SyncMode = mode; SyncMode = mode;
} }
} }
// An async sound provider // An async sound provider
// This class needs to go away, it takes an IAsyncSoundProvider // This class needs to go away, it takes an IAsyncSoundProvider
// and is only used by legacy sound implementations // and is only used by legacy sound implementations
internal class MetaspuSoundProvider : ISoundProvider internal class MetaspuSoundProvider : ISoundProvider
{ {
private readonly short[] _pullBuffer = new short[1470]; private readonly short[] _pullBuffer = new short[1470];
public MetaspuSoundProvider(ESynchMethod method) public MetaspuSoundProvider(ESynchMethod method)
{ {
Buffer = Metaspu.MetaspuConstruct(method); Buffer = Metaspu.MetaspuConstruct(method);
} }
public ISynchronizingAudioBuffer Buffer { get; } public ISynchronizingAudioBuffer Buffer { get; }
public MetaspuSoundProvider() public MetaspuSoundProvider()
: this(ESynchMethod.ESynchMethod_V) : this(ESynchMethod.Vecna)
{ {
} }
public void PullSamples(IAsyncSoundProvider source) public void PullSamples(IAsyncSoundProvider source)
{ {
Array.Clear(_pullBuffer, 0, 1470); Array.Clear(_pullBuffer, 0, 1470);
source.GetSamples(_pullBuffer); source.GetSamples(_pullBuffer);
Buffer.EnqueueSamples(_pullBuffer, 735); Buffer.EnqueueSamples(_pullBuffer, 735);
} }
public bool CanProvideAsync => true; public bool CanProvideAsync => true;
public SyncSoundMode SyncMode => SyncSoundMode.Async; public SyncSoundMode SyncMode => SyncSoundMode.Async;
public void SetSyncMode(SyncSoundMode mode) public void SetSyncMode(SyncSoundMode mode)
{ {
if (mode != SyncSoundMode.Async) if (mode != SyncSoundMode.Async)
{ {
throw new NotSupportedException("Only Async mode is supported."); throw new NotSupportedException("Only Async mode is supported.");
} }
} }
public void GetSamplesSync(out short[] samples, out int nsamp) public void GetSamplesSync(out short[] samples, out int nsamp)
{ {
throw new InvalidOperationException("Sync mode is not supported."); throw new InvalidOperationException("Sync mode is not supported.");
} }
public void GetSamplesAsync(short[] samples) public void GetSamplesAsync(short[] samples)
{ {
Buffer.OutputSamples(samples, samples.Length / 2); Buffer.OutputSamples(samples, samples.Length / 2);
} }
public void DiscardSamples() public void DiscardSamples()
{ {
Buffer.Clear(); Buffer.Clear();
} }
} }
} }