2011-01-11 02:55:51 +00:00
|
|
|
|
using System;
|
|
|
|
|
|
2013-11-14 19:33:13 +00:00
|
|
|
|
namespace BizHawk.Emulation.Common
|
2011-01-11 02:55:51 +00:00
|
|
|
|
{
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
/// <summary>
|
2016-12-11 17:14:42 +00:00
|
|
|
|
/// uses Metaspu to provide async sound to an ISoundProvider that does not provide its own async implementation
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
/// </summary>
|
2016-12-11 17:14:42 +00:00
|
|
|
|
// Sound Refactor TODO: rename me to MetaspuAsyncSoundProvider
|
|
|
|
|
public class MetaspuAsync : ISoundProvider
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
{
|
2017-04-25 18:22:25 +00:00
|
|
|
|
private readonly ISynchronizingAudioBuffer _buffer;
|
|
|
|
|
private readonly ISoundProvider _input;
|
2016-12-11 17:14:42 +00:00
|
|
|
|
|
|
|
|
|
public MetaspuAsync(ISoundProvider input, ESynchMethod method)
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
{
|
2016-12-11 17:14:42 +00:00
|
|
|
|
input.SetSyncMode(SyncSoundMode.Sync);
|
2017-04-26 13:34:12 +00:00
|
|
|
|
_buffer = Metaspu.MetaspuConstruct(method);
|
2017-04-25 18:22:25 +00:00
|
|
|
|
_input = input;
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2016-12-11 17:14:42 +00:00
|
|
|
|
public void GetSamplesAsync(short[] samples)
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
{
|
|
|
|
|
short[] sampin;
|
|
|
|
|
int numsamp;
|
2017-04-25 18:22:25 +00:00
|
|
|
|
_input.GetSamplesSync(out sampin, out numsamp);
|
|
|
|
|
_buffer.EnqueueSamples(sampin, numsamp);
|
|
|
|
|
_buffer.OutputSamples(samples, samples.Length / 2);
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void DiscardSamples()
|
|
|
|
|
{
|
2017-04-25 18:22:25 +00:00
|
|
|
|
_input.DiscardSamples();
|
|
|
|
|
_buffer.Clear();
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
}
|
2016-12-11 17:14:42 +00:00
|
|
|
|
|
2017-04-14 17:28:23 +00:00
|
|
|
|
public bool CanProvideAsync => true;
|
2016-12-11 17:14:42 +00:00
|
|
|
|
|
2017-04-15 20:37:30 +00:00
|
|
|
|
public SyncSoundMode SyncMode => SyncSoundMode.Async;
|
2016-12-11 17:14:42 +00:00
|
|
|
|
|
2017-04-15 20:37:30 +00:00
|
|
|
|
public void SetSyncMode(SyncSoundMode mode)
|
2016-12-11 17:14:42 +00:00
|
|
|
|
{
|
|
|
|
|
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 not supported");
|
|
|
|
|
}
|
sound api changes. added a new ISyncSoundProvider, which works similarly to ISoundProvider except the source (not the sink) determines the number of samples to process. Added facilities to metaspu, dcfilter, speexresampler to work with ISyncSoundProvider. Add ISyncSoundProvider to IEmulator. All IEmulators must provide sync sound, but they need not provide async sound. When async is needed and an IEmulator doesn't provide it, the frontend will wrap it in a vecna metaspu. SNES, GB changed to provide sync sound only. All other emulator cores mostly unchanged; they just provide stub fakesync alongside async, for now. For the moment, the only use of the sync sound is for realtime audio throttling, where it works and sounds quite nice. In the future, sync sound will be supported for AV dumping as well.
2012-10-11 00:44:59 +00:00
|
|
|
|
}
|
|
|
|
|
|
2011-01-11 02:55:51 +00:00
|
|
|
|
public enum ESynchMethod
|
|
|
|
|
{
|
2017-04-24 12:41:55 +00:00
|
|
|
|
ESynchMethod_N, // nitsuja's
|
|
|
|
|
ESynchMethod_Z, // zero's
|
2017-04-26 13:34:12 +00:00
|
|
|
|
////ESynchMethod_P, //PCSX2 spu2-x //ohno! not available yet in c#
|
2013-11-14 19:33:13 +00:00
|
|
|
|
ESynchMethod_V // vecna
|
2017-04-24 12:41:55 +00:00
|
|
|
|
}
|
2013-11-14 19:33:13 +00:00
|
|
|
|
|
2011-01-11 02:55:51 +00:00
|
|
|
|
public static class Metaspu
|
|
|
|
|
{
|
2017-04-26 13:34:12 +00:00
|
|
|
|
public static ISynchronizingAudioBuffer MetaspuConstruct(ESynchMethod method)
|
2011-01-11 02:55:51 +00:00
|
|
|
|
{
|
|
|
|
|
switch (method)
|
|
|
|
|
{
|
|
|
|
|
case ESynchMethod.ESynchMethod_Z:
|
|
|
|
|
return new ZeromusSynchronizer();
|
|
|
|
|
case ESynchMethod.ESynchMethod_N:
|
|
|
|
|
return new NitsujaSynchronizer();
|
2013-11-14 19:33:13 +00:00
|
|
|
|
case ESynchMethod.ESynchMethod_V:
|
|
|
|
|
return new VecnaSynchronizer();
|
2011-01-11 02:55:51 +00:00
|
|
|
|
default:
|
|
|
|
|
return new NitsujaSynchronizer();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|