VRC6 audio: restructure to send deltas directly to the NES apu, simplifying some things. This would be pointless masturbation by itself, but this method will also lead to easier emulation of MMC5 audio.
This commit is contained in:
parent
3bcb00f9b9
commit
4e0796814d
|
@ -1076,6 +1076,14 @@ namespace BizHawk.Emulation.Consoles.Nintendo
|
|||
}
|
||||
public List<Delta> dlist = new List<Delta>();
|
||||
|
||||
/// <summary>only call in board.ClockCPU()</summary>
|
||||
/// <param name="value"></param>
|
||||
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;
|
||||
|
|
|
@ -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);
|
||||
//}
|
||||
|
||||
}
|
||||
}
|
|
@ -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<int> enqueuer;
|
||||
|
||||
/// <summary>
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="freq">frequency of the M2 clock in hz</param>
|
||||
public VRC6Alt(uint freq)
|
||||
/// <param name="enqueuer">a place to dump deltas to</param>
|
||||
public VRC6Alt(uint freq, Action<int> 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
|
||||
|
|
Loading…
Reference in New Issue