From b6e4d9996ef38fbe43ca29c68ad9eec2abed304a Mon Sep 17 00:00:00 2001 From: goyuken Date: Sat, 29 Sep 2012 22:38:47 +0000 Subject: [PATCH] DCFilter: add a "push" mode more suited to being placed between a resampler and a metaspu Gambatte: change the order of output from "GB => resampler => metaspu => DCFilter" to "GB => resampler => DCFilter => metaspu". This doesn't change anything under most circumstances, except when playing the emulator in slow motion (for instance, 50% throttle). There, the metaspu sometimes adds silence to the output, which isn't actually silence if it has a different DC offset than the audio it's being mixed with. Well, 50% throttle sound output will always suck anyway... --- .../Consoles/Nintendo/Gameboy/Gambatte.cs | 16 +++++++++--- BizHawk.Emulation/Sound/Utilities/DCFilter.cs | 26 +++++++++++++------ 2 files changed, 30 insertions(+), 12 deletions(-) diff --git a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs index 18114ca4da..8e65deb69f 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/Gameboy/Gambatte.cs @@ -585,13 +585,15 @@ namespace BizHawk.Emulation.Consoles.GB int soundbuffcontains = 0; Sound.Utilities.SpeexResampler resampler; - ISoundProvider metaspu; + Sound.MetaspuSoundProvider metaspu; + + Sound.Utilities.DCFilter dcfilter; void InitSound() { - var metaspu = new Sound.MetaspuSoundProvider(Sound.ESynchMethod.ESynchMethod_V); - resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, metaspu.buffer.enqueue_samples); - this.metaspu = new Sound.Utilities.DCFilter(metaspu);// metaspu; + dcfilter = new Sound.Utilities.DCFilter(); + metaspu = new Sound.MetaspuSoundProvider(Sound.ESynchMethod.ESynchMethod_V); + resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, LoadThroughSamples); } void DisposeSound() @@ -600,6 +602,12 @@ namespace BizHawk.Emulation.Consoles.GB resampler = null; } + void LoadThroughSamples(short[] buff, int length) + { + dcfilter.PushThroughSamples(buff, length * 2); + metaspu.buffer.enqueue_samples(buff, length); + } + public void GetSamples(short[] samples) { if (soundbuffcontains > 0) diff --git a/BizHawk.Emulation/Sound/Utilities/DCFilter.cs b/BizHawk.Emulation/Sound/Utilities/DCFilter.cs index e2575c6ce1..b910e1c1ec 100644 --- a/BizHawk.Emulation/Sound/Utilities/DCFilter.cs +++ b/BizHawk.Emulation/Sound/Utilities/DCFilter.cs @@ -25,8 +25,12 @@ namespace BizHawk.Emulation.Sound.Utilities Queue buffer; const int depth = 65536; - - public DCFilter(ISoundProvider input) + + /// + /// if input == null, run in detatched push mode + /// + /// + public DCFilter(ISoundProvider input = null) { this.input = input; this.buffer = new Queue(depth * 2); @@ -45,13 +49,13 @@ namespace BizHawk.Emulation.Sound.Utilities input = null; return ret; } - - public void GetSamples(short[] samples) + + /// + /// pass a set of samples through the filter. should not be mixed with pull (ISoundProvider) mode + /// + public void PushThroughSamples(short[] samples, int length) { - - input.GetSamples(samples); - - for (int i = 0; i < samples.Length; i += 2) + for (int i = 0; i < length; i += 2) { sumL -= buffer.Dequeue(); sumR -= buffer.Dequeue(); @@ -80,6 +84,12 @@ namespace BizHawk.Emulation.Sound.Utilities } } + public void GetSamples(short[] samples) + { + input.GetSamples(samples); + PushThroughSamples(samples, samples.Length); + } + public void DiscardSamples() { input.DiscardSamples();