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...
This commit is contained in:
goyuken 2012-09-29 22:38:47 +00:00
parent 486d621657
commit b6e4d9996e
2 changed files with 30 additions and 12 deletions

View File

@ -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)

View File

@ -25,8 +25,12 @@ namespace BizHawk.Emulation.Sound.Utilities
Queue<short> buffer;
const int depth = 65536;
public DCFilter(ISoundProvider input)
/// <summary>
/// if input == null, run in detatched push mode
/// </summary>
/// <param name="input"></param>
public DCFilter(ISoundProvider input = null)
{
this.input = input;
this.buffer = new Queue<short>(depth * 2);
@ -45,13 +49,13 @@ namespace BizHawk.Emulation.Sound.Utilities
input = null;
return ret;
}
public void GetSamples(short[] samples)
/// <summary>
/// pass a set of samples through the filter. should not be mixed with pull (ISoundProvider) mode
/// </summary>
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();