rearrange the api of DCFilter a bit to make it less dumb. nothing of real importance

This commit is contained in:
goyuken 2012-12-09 15:58:55 +00:00
parent 210d415e3d
commit cb4288ada4
5 changed files with 42 additions and 58 deletions

View File

@ -185,7 +185,7 @@ namespace BizHawk
//tia = new TIA(this, frameBuffer); //tia = new TIA(this, frameBuffer);
tia = new TIA(this); tia = new TIA(this);
// dcfilter coefficent is from real observed hardware behavior: a latched "1" will fully decay by ~170 or so tia sound cycles // dcfilter coefficent is from real observed hardware behavior: a latched "1" will fully decay by ~170 or so tia sound cycles
dcfilter = new Emulation.Sound.Utilities.DCFilter(tia, 256); dcfilter = Emulation.Sound.Utilities.DCFilter.AsISoundProvider(tia, 256);
// Setup 6532 // Setup 6532
m6532 = new M6532(this); m6532 = new M6532(this);

View File

@ -738,7 +738,7 @@ namespace BizHawk.Emulation.Consoles.GB
void InitSound() void InitSound()
{ {
resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, null, this); resampler = new Sound.Utilities.SpeexResampler(2, 2097152, 44100, 2097152, 44100, null, this);
dcfilter = new Sound.Utilities.DCFilter(resampler, 65536); dcfilter = Sound.Utilities.DCFilter.AsISyncSoundProvider(resampler, 65536);
} }
void DisposeSound() void DisposeSound()

View File

@ -125,7 +125,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
public Namco163Audio() public Namco163Audio()
{ {
resampler = new Sound.Utilities.SpeexResampler(2, 119318, 44100, 119318, 44100, null, null); resampler = new Sound.Utilities.SpeexResampler(2, 119318, 44100, 119318, 44100, null, null);
dc = new Sound.Utilities.DCFilter(4096); dc = Sound.Utilities.DCFilter.DetatchedMode(4096);
metaspu = new Sound.MetaspuAsync(resampler, Sound.ESynchMethod.ESynchMethod_V); metaspu = new Sound.MetaspuAsync(resampler, Sound.ESynchMethod.ESynchMethod_V);
} }

View File

@ -309,7 +309,7 @@ namespace BizHawk.Emulation.Consoles.Nintendo
return ret; return ret;
} }
Sound.Utilities.DCFilter dc = new Sound.Utilities.DCFilter(4096); Sound.Utilities.DCFilter dc = Sound.Utilities.DCFilter.DetatchedMode(4096);
public void ApplyCustomAudio(short[] samples) public void ApplyCustomAudio(short[] samples)
{ {

View File

@ -27,53 +27,42 @@ namespace BizHawk.Emulation.Sound.Utilities
int depth; int depth;
/// <summary> public static DCFilter AsISoundProvider(ISoundProvider input, int filterwidth)
/// if input == null, run in detatched push mode {
/// </summary> if (input == null)
/// <param name="input"></param> throw new ArgumentNullException();
public DCFilter(ISoundProvider input = null, int filterwidth = 65536) return new DCFilter(input, null, filterwidth);
}
public static DCFilter AsISyncSoundProvider(ISyncSoundProvider syncinput, int filterwidth)
{
if (syncinput == null)
throw new ArgumentNullException();
return new DCFilter(null, syncinput, filterwidth);
}
public static DCFilter DetatchedMode(int filterwidth)
{
return new DCFilter(null, null, filterwidth);
}
DCFilter(ISoundProvider input, ISyncSoundProvider syncinput, int filterwidth)
{ {
if (filterwidth < 1 || filterwidth > 65536) if (filterwidth < 1 || filterwidth > 65536)
throw new ArgumentOutOfRangeException(); throw new ArgumentOutOfRangeException();
this.input = input; this.input = input;
this.syncinput = null; this.syncinput = syncinput;
this.depth = filterwidth; depth = filterwidth;
this.buffer = new Queue<short>(depth * 2); buffer = new Queue<short>(depth * 2);
for (int i = 0; i < depth * 2; i++) for (int i = 0; i < depth * 2; i++)
buffer.Enqueue(0); buffer.Enqueue(0);
} }
/// <summary> /// <summary>
/// detached mode /// pass a set of samples through the filter. should only be used in detached mode
/// </summary>
/// <param name="filterwidth"></param>
public DCFilter(int filterwidth)
{
if (filterwidth < 1 || filterwidth > 65536)
throw new ArgumentOutOfRangeException();
this.input = null;
this.syncinput = null;
this.depth = filterwidth;
this.buffer = new Queue<short>(depth * 2);
for (int i = 0; i < depth * 2; i++)
buffer.Enqueue(0);
}
public DCFilter(ISyncSoundProvider input, int filterwidth)
{
if (filterwidth < 1 || filterwidth > 65536)
throw new ArgumentOutOfRangeException();
this.input = null;
this.syncinput = input;
this.depth = filterwidth;
this.buffer = new Queue<short>(depth * 2);
for (int i = 0; i < depth * 2; i++)
buffer.Enqueue(0);
}
/// <summary>
/// pass a set of samples through the filter. should not be mixed with pull (ISoundProvider) mode or sync mode
/// </summary> /// </summary>
/// <param name="samples">sample buffer to modify</param>
/// <param name="length">number of samples (not pairs). stereo</param>
public void PushThroughSamples(short[] samples, int length) public void PushThroughSamples(short[] samples, int length)
{ {
PushThroughSamples(samples, samples, length); PushThroughSamples(samples, samples, length);
@ -107,36 +96,26 @@ namespace BizHawk.Emulation.Sound.Utilities
else else
samplesout[i + 1] = (short)bigR; samplesout[i + 1] = (short)bigR;
} }
} }
public void GetSamples(short[] samples) void ISoundProvider.GetSamples(short[] samples)
{ {
input.GetSamples(samples); input.GetSamples(samples);
PushThroughSamples(samples, samples.Length); PushThroughSamples(samples, samples.Length);
} }
public void DiscardSamples() void ISoundProvider.DiscardSamples()
{ {
if (input != null) input.DiscardSamples();
input.DiscardSamples();
if (syncinput != null)
syncinput.DiscardSamples();
} }
public int MaxVolume int ISoundProvider.MaxVolume
{ {
get get { return input.MaxVolume; }
{ set { input.MaxVolume = value; }
return input.MaxVolume;
}
set
{
input.MaxVolume = value;
}
} }
public void GetSamples(out short[] samples, out int nsamp) void ISyncSoundProvider.GetSamples(out short[] samples, out int nsamp)
{ {
short[] sampin; short[] sampin;
int nsampin; int nsampin;
@ -146,5 +125,10 @@ namespace BizHawk.Emulation.Sound.Utilities
samples = ret; samples = ret;
nsamp = nsampin; nsamp = nsampin;
} }
void ISyncSoundProvider.DiscardSamples()
{
syncinput.DiscardSamples();
}
} }
} }