diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs index a1ad3ae636..c67598fea6 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/APU.cs @@ -1076,6 +1076,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo } public List dlist = new List(); + /// only call in board.ClockCPU() + /// + public void ExternalQueue(int value) + { + // sampleclock is incremented right before board.ClockCPU() + dlist.Add(new Delta(sampleclock - 1, value)); + } + public uint sampleclock = 0; int oldmix = 0; diff --git a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs index ccda43d7d2..9eedc8008d 100644 --- a/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs +++ b/BizHawk.Emulation/Consoles/Nintendo/NES/Boards/VRC6.cs @@ -30,8 +30,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo base.Dispose(); prg_banks_8k.Dispose(); chr_banks_1k.Dispose(); - if (VRC6Sound != null) - VRC6Sound.Dispose(); + //if (VRC6Sound != null) + // VRC6Sound.Dispose(); } public override void SyncState(Serializer ser) @@ -96,7 +96,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo SyncPRG(); SetMirrorType(EMirrorType.Vertical); - VRC6Sound = new Sound.VRC6Alt((uint)NES.cpuclockrate); + if (NES.apu != null) // don't start up sound when in configurator + VRC6Sound = new Sound.VRC6Alt((uint)NES.cpuclockrate, NES.apu.ExternalQueue); return true; } @@ -273,8 +274,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo } } - public override void ApplyCustomAudio(short[] samples) - { + //public override void ApplyCustomAudio(short[] samples) + //{ /* short[] fmsamples = new short[samples.Length]; VRC6Sound.GetSamples(fmsamples); @@ -284,8 +285,8 @@ namespace BizHawk.Emulation.Consoles.Nintendo samples[i] = (short)((samples[i] >> 1) + (fmsamples[i] >> 1)); } */ - VRC6Sound.ApplyCustomAudio(samples); - } + // VRC6Sound.ApplyCustomAudio(samples); + //} } } \ No newline at end of file diff --git a/BizHawk.Emulation/Sound/VRC6Alt.cs b/BizHawk.Emulation/Sound/VRC6Alt.cs index 1a2e4e4124..86611408d6 100644 --- a/BizHawk.Emulation/Sound/VRC6Alt.cs +++ b/BizHawk.Emulation/Sound/VRC6Alt.cs @@ -5,19 +5,19 @@ using System.Text; namespace BizHawk.Emulation.Sound { - public class VRC6Alt : IDisposable + public class VRC6Alt// : IDisposable { // http://wiki.nesdev.com/w/index.php/VRC6_audio - - + /* + // the VRC6 now sends its blips back to the NES core, for simplicity + // (speed is the same) + #region blip-buf interface Sound.Utilities.BlipBuffer blip; - // yes, some of this is copy+pasted from the FDS, and more or less from the NES - // as soon as i decide that i like it and i use it a third time, i'll put it in a class struct Delta { @@ -38,6 +38,7 @@ namespace BizHawk.Emulation.Sound public void ApplyCustomAudio(short[] samples) { + int nsamp = samples.Length / 2; if (nsamp > blipsize) // oh well. nsamp = blipsize; @@ -61,29 +62,35 @@ namespace BizHawk.Emulation.Sound // nes audio is mono, so we can ignore the original value of samples[j+1] samples[j + 1] = samples[j]; } + } - #endregion + */ Pulse pulse1, pulse2; Saw saw; + Action enqueuer; + /// /// /// /// frequency of the M2 clock in hz - public VRC6Alt(uint freq) + /// a place to dump deltas to + public VRC6Alt(uint freq, Action enqueuer) { + this.enqueuer = enqueuer; + /* if (freq > 0) { blip = new Utilities.BlipBuffer(blipsize); blip.SetRates(freq, 44100); - } + }*/ pulse1 = new Pulse(PulseAddDiff); pulse2 = new Pulse(PulseAddDiff); saw = new Saw(SawAddDiff); } - + /* public void Dispose() { if (blip != null) @@ -91,18 +98,20 @@ namespace BizHawk.Emulation.Sound blip.Dispose(); blip = null; } - } + }*/ // the two pulse channels are about the same volume as 2a03 pulse channels. // everything is flipped, though; but that's taken care of in the classes void PulseAddDiff(int value) { - dlist.Add(new Delta(sampleclock, value * 360)); + //dlist.Add(new Delta(sampleclock, value * 360)); + enqueuer(value * 360); } // saw ends up being not that loud because of differences in implementation void SawAddDiff(int value) { - dlist.Add(new Delta(sampleclock, value * 360)); + //dlist.Add(new Delta(sampleclock, value * 360)); + enqueuer(value * 360); } // state @@ -151,7 +160,7 @@ namespace BizHawk.Emulation.Sound pulse2.Clock(); saw.Clock(); } - sampleclock++; + //sampleclock++; } class Saw