NES: namcot 163: clean up and rework audio slightly. about 5% speedup in King of Kings and えりかとさとるの夢冒険

also clean up some old junk in FDS audio, no code changes
This commit is contained in:
goyuken 2013-12-28 17:06:57 +00:00
parent 4ccc31da44
commit e673062d0f
3 changed files with 11 additions and 158 deletions

View File

@ -33,11 +33,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
prg_banks_8k.Dispose();
chr_banks_1k.Dispose();
nt_banks_1k.Dispose();
if (audio != null)
{
audio.Dispose();
audio = null;
}
}
public override void SyncState(Serializer ser)
@ -78,7 +73,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
//hydelide 3 *this is a good test of more advanced features
Cart.vram_size = 8; //not many test cases of this, but hydelide 3 needs it.
AssertPrg(128,256); AssertChr(128,256); AssertVram(8); AssertWram(0,8);
audio = new Namco163Audio();
if (NES.apu != null)
audio = new Namco163Audio(NES.apu.ExternalQueue);
break;
//mapper 210:
@ -321,11 +317,5 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
}
}
public override void ApplyCustomAudio(short[] samples)
{
if (audio != null)
audio.ApplyCustomAudio(samples);
}
}
}

View File

@ -6,21 +6,12 @@ using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Nintendo.NES
{
// http://wiki.nesdev.com/w/index.php/Namco_163_audio
public sealed class Namco163Audio : IDisposable
public sealed class Namco163Audio
{
//ByteBuffer ram = new ByteBuffer(0x80);
byte[] ram = new byte[0x80];
int addr;
bool autoincrement;
public void Dispose()
{
//ram.Dispose();
ram = null;
resampler.Dispose();
resampler = null;
}
/// <summary>
/// F800:FFFF
/// </summary>
@ -66,8 +57,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
int ch;
// output buffer; not savestated
//short[] samplebuff = new short[2048];
//int samplebuffpos;
int latchout = 0;
/// <summary>
/// 119318hz (CPU / 15)
@ -80,11 +70,10 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ch = 8;
byte samp = ClockChannel(ch);
//samplebuff[samplebuffpos++] = samp;
//samplebuffpos &= 2047;
short ss = (short)(samp * 150 - 18000);
resampler.EnqueueSample(ss, ss);
int s = samp * 150;
int delta = latchout - s;
latchout = s;
enqueuer(delta);
}
byte ClockChannel(int ch)
@ -118,62 +107,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
ser.Sync("ch", ref ch);
}
SpeexResampler resampler;
DCFilter dc;
MetaspuAsync metaspu;
Action<int> enqueuer;
public Namco163Audio()
public Namco163Audio(Action<int> enqueuer)
{
resampler = new SpeexResampler(2, 119318, 44100, 119318, 44100, null, null);
dc = DCFilter.DetatchedMode(4096);
metaspu = new MetaspuAsync(resampler, ESynchMethod.ESynchMethod_V);
this.enqueuer = enqueuer;
}
public void ApplyCustomAudio(short[] samples)
{
short[] tmp = new short[samples.Length];
metaspu.GetSamples(tmp);
for (int i = 0; i < samples.Length; i++)
{
int samp = samples[i] + tmp[i];
if (samp > 32767)
samples[i] = 32767;
else if (samp < -32768)
samples[i] = -32768;
else
samples[i] = (short)samp;
}
dc.PushThroughSamples(samples, samples.Length);
}
// the same junk used in FDSAudio
// the problem here is, the raw 120khz output contains significant amounts of crap that gets
// massively garbaged up by this resampling
/*
public void ApplyCustomAudio(short[] samples)
{
for (int i = 0; i < samples.Length; i += 2)
{
// worst imaginable resampling
int pos = i * samplebuffpos / samples.Length;
int samp = samplebuff[pos] * 50 - 12096;
samp += samples[i];
if (samp > 32767)
samples[i] = 32767;
else if (samp < -32768)
samples[i] = -32768;
else
samples[i] = (short)samp;
// NES audio is mono, so this should be identical anyway
samples[i + 1] = samples[i];
}
samplebuffpos = 0;
dc.PushThroughSamples(samples, samples.Length);
}
*/
}
}

View File

@ -8,7 +8,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
{
public void SyncState(Serializer ser)
{
// no need to sync the DCFilter or the samplebuff
ser.Sync("waveram", ref waveram, false);
ser.Sync("waverampos", ref waverampos);
@ -152,28 +151,8 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
public FDSAudio(Action<int> SendDiff)
{
this.SendDiff = SendDiff;
/*
// minor hack: due to the way the initialization sequence goes, this might get called
// with m2rate = 0. such an instance will never be asked for samples, though
if (m2rate > 0)
{
blip = new Sound.Utilities.BlipBuffer(blipsize);
blip.SetRates(m2rate, 44100);
}
*/
}
/*
public void Dispose()
{
if (blip != null)
{
blip.Dispose();
blip = null;
}
}
*/
void CalcMod()
{
// really don't quite get this...
@ -206,7 +185,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
if (latchedoutput != tmp)
{
//dlist.Add(new Delta(sampleclock, tmp - latchedoutput));
SendDiff((tmp - latchedoutput) * 6);
latchedoutput = tmp;
}
@ -284,7 +262,6 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
CalcOut();
}
}
//sampleclock++;
}
public void WriteReg(int addr, byte value)
@ -384,57 +361,5 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES
}
return ret;
}
/*
Sound.Utilities.BlipBuffer blip;
struct Delta
{
public uint time;
public int value;
public Delta(uint time, int value)
{
this.time = time;
this.value = value;
}
}
List<Delta> dlist = new List<Delta>();
uint sampleclock = 0;
const int blipsize = 4096;
short[] mixout = new short[blipsize];
public void ApplyCustomAudio(short[] samples)
{
int nsamp = samples.Length / 2;
if (nsamp > blipsize) // oh well.
nsamp = blipsize;
uint targetclock = (uint)blip.ClocksNeeded(nsamp);
foreach (var d in dlist)
{
// original deltas are in -2016..2016
blip.AddDelta(d.time * targetclock / sampleclock, d.value * 6);
}
//Console.WriteLine("sclock {0} tclock {1} ndelta {2}", sampleclock, targetclock, dlist.Count);
dlist.Clear();
blip.EndFrame(targetclock);
sampleclock = 0;
blip.ReadSamples(mixout, nsamp, false);
for (int i = 0, j = 0; i < nsamp; i++, j += 2)
{
int s = mixout[i] + samples[j];
if (s > 32767)
samples[j] = 32767;
else if (s <= -32768)
samples[j] = -32768;
else
samples[j] = (short)s;
// nes audio is mono, so we can ignore the original value of samples[j+1]
samples[j + 1] = samples[j];
}
}
*/
}
}