Coleco: Fix audio quality

This commit is contained in:
alyosha-tas 2018-03-13 16:31:21 -04:00
parent d481624f9e
commit 42131c5d57
5 changed files with 34 additions and 54 deletions

View File

@ -8,7 +8,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{ {
public sealed class AY_3_8910_SGM public sealed class AY_3_8910_SGM
{ {
public short[] _sampleBuffer = new short[4096];
private short current_sample; private short current_sample;
public AY_3_8910_SGM() public AY_3_8910_SGM()
@ -31,18 +30,11 @@ namespace BizHawk.Emulation.Cores.ColecoVision
Register[i] = 0x0000; Register[i] = 0x0000;
} }
sync_psg_state(); sync_psg_state();
DiscardSamples();
} }
public void DiscardSamples() public short Sample()
{ {
_sampleClock = 0; return current_sample;
}
public void Sample()
{
_sampleBuffer[_sampleClock] = current_sample;
_sampleClock++;
} }
private static readonly int[] VolumeTable = private static readonly int[] VolumeTable =
@ -51,10 +43,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
0x03C5, 0x0555, 0x078B, 0x0AAB, 0x0F16, 0x1555, 0x1E2B, 0x2AAA 0x03C5, 0x0555, 0x078B, 0x0AAB, 0x0F16, 0x1555, 0x1E2B, 0x2AAA
}; };
private int _sampleClock;
private int TotalExecutedCycles;
private int PendingCycles;
private int psg_clock; private int psg_clock;
private int sq_per_A, sq_per_B, sq_per_C; private int sq_per_A, sq_per_B, sq_per_C;
private int clock_A, clock_B, clock_C; private int clock_A, clock_B, clock_C;
@ -79,8 +67,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
ser.BeginSection("PSG"); ser.BeginSection("PSG");
ser.Sync("Register", ref Register, false); ser.Sync("Register", ref Register, false);
ser.Sync("Toal_executed_cycles", ref TotalExecutedCycles);
ser.Sync("Pending_Cycles", ref PendingCycles);
ser.Sync("psg_clock", ref psg_clock); ser.Sync("psg_clock", ref psg_clock);
ser.Sync("clock_A", ref clock_A); ser.Sync("clock_A", ref clock_A);
@ -296,9 +282,9 @@ namespace BizHawk.Emulation.Cores.ColecoVision
} }
else else
{ {
v = (short)(sound_out_A ? VolumeTable[env_E] : 0); v = (short)(sound_out_A ? VolumeTable[vol_A] : 0);
} }
if (env_vol_B == 0) if (env_vol_B == 0)
{ {
v += (short)(sound_out_B ? VolumeTable[vol_B] : 0); v += (short)(sound_out_B ? VolumeTable[vol_B] : 0);
@ -317,7 +303,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{ {
v += (short)(sound_out_C ? VolumeTable[env_E] : 0); v += (short)(sound_out_C ? VolumeTable[env_E] : 0);
} }
current_sample = (short)v; current_sample = (short)v;
} }
} }

View File

@ -73,6 +73,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision
int changes_1 = change1 > 0 ? (int)Math.Floor(change1) : (int)Math.Ceiling(change1); int changes_1 = change1 > 0 ? (int)Math.Floor(change1) : (int)Math.Ceiling(change1);
int changes_2 = change2 > 0 ? (int)Math.Floor(change2) : (int)Math.Ceiling(change2); int changes_2 = change2 > 0 ? (int)Math.Floor(change2) : (int)Math.Ceiling(change2);
for (int scanLine = 0; scanLine < 262; scanLine++) for (int scanLine = 0; scanLine < 262; scanLine++)
{ {
_vdp.RenderScanline(scanLine); _vdp.RenderScanline(scanLine);
@ -92,11 +94,20 @@ namespace BizHawk.Emulation.Cores.ColecoVision
_cpu.ExecuteOne(); _cpu.ExecuteOne();
// pick out sound samples from the sound devies twice per scanline // pick out sound samples from the sound devies twice per scanline
if ((i==76) || (i==152)) int v = PSG.Sample();
if (use_SGM)
{ {
PSG.Sample(); v += SGM_sound.Sample();
if (use_SGM) { SGM_sound.Sample(); }
} }
if (v != _latchedSample)
{
_blip.AddDelta((uint)_sampleClock, v - _latchedSample);
_latchedSample = v;
}
_sampleClock++;
} }
// starting from scanline 20, changes to the wheel are added once per scanline (up to 144) // starting from scanline 20, changes to the wheel are added once per scanline (up to 144)
@ -163,6 +174,8 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public bool enable_SGM_low = false; public bool enable_SGM_low = false;
public byte port_0x53, port_0x7F; public byte port_0x53, port_0x7F;
public int _sampleClock = 0;
public int _latchedSample = 0;
public int Frame => _frame; public int Frame => _frame;

View File

@ -11,12 +11,12 @@ namespace BizHawk.Emulation.Cores.ColecoVision
private SN76489col PSG; private SN76489col PSG;
private AY_3_8910_SGM SGM_sound; private AY_3_8910_SGM SGM_sound;
private short[] _sampleBuffer = new short[0]; private readonly BlipBuffer _blip = new BlipBuffer(4096);
public void DiscardSamples() public void DiscardSamples()
{ {
SGM_sound.DiscardSamples(); _blip.Clear();
PSG.DiscardSamples(); _sampleClock = 0;
} }
public void GetSamplesAsync(short[] samples) public void GetSamplesAsync(short[] samples)
@ -38,26 +38,18 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public void GetSamplesSync(out short[] samples, out int nsamp) public void GetSamplesSync(out short[] samples, out int nsamp)
{ {
nsamp = 524; _blip.EndFrame((uint)_sampleClock);
_sampleClock = 0;
nsamp = _blip.SamplesAvailable();
samples = new short[nsamp * 2]; samples = new short[nsamp * 2];
for (int i = 0; i < nsamp; i++) _blip.ReadSamples(samples, nsamp, true);
{
samples[i * 2] = PSG._sampleBuffer[i];
samples[i * 2 + 1] = PSG._sampleBuffer[i];
}
if (use_SGM) for (int i = 0; i < nsamp * 2; i += 2)
{ {
for (int i = 0; i < nsamp; i++) samples[i + 1] = samples[i];
{ }
samples[i * 2] += SGM_sound._sampleBuffer[i];
samples[i * 2 + 1] += SGM_sound._sampleBuffer[i];
}
}
DiscardSamples();
} }
public void GetSamples(short[] samples) public void GetSamples(short[] samples)

View File

@ -35,6 +35,7 @@ namespace BizHawk.Emulation.Cores.ColecoVision
PSG = new SN76489col(); PSG = new SN76489col();
SGM_sound = new AY_3_8910_SGM(); SGM_sound = new AY_3_8910_SGM();
_blip.SetRates(3579545, 44100);
ControllerDeck = new ColecoVisionControllerDeck(_syncSettings.Port1, _syncSettings.Port2); ControllerDeck = new ColecoVisionControllerDeck(_syncSettings.Port1, _syncSettings.Port2);

View File

@ -9,7 +9,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
{ {
public sealed class SN76489col public sealed class SN76489col
{ {
public short[] _sampleBuffer = new short[4096];
private short current_sample; private short current_sample;
public SN76489col() public SN76489col()
@ -26,8 +25,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
public int noise_rate; public int noise_rate;
public bool noise_bit; public bool noise_bit;
private int _sampleClock;
private int psg_clock; private int psg_clock;
private int clock_A, clock_B, clock_C; private int clock_A, clock_B, clock_C;
@ -47,19 +44,11 @@ namespace BizHawk.Emulation.Cores.ColecoVision
// reset the shift register // reset the shift register
noise = 0x40000; noise = 0x40000;
DiscardSamples();
} }
public void DiscardSamples() public int Sample()
{ {
_sampleClock = 0; return current_sample;
}
public void Sample()
{
_sampleBuffer[_sampleClock] = current_sample;
_sampleClock++;
} }
public void SyncState(Serializer ser) public void SyncState(Serializer ser)
@ -81,7 +70,6 @@ namespace BizHawk.Emulation.Cores.ColecoVision
ser.Sync("noise_bit", ref noise_bit); ser.Sync("noise_bit", ref noise_bit);
ser.Sync("psg_clock", ref psg_clock); ser.Sync("psg_clock", ref psg_clock);
ser.Sync("sample_clock", ref _sampleClock);
ser.Sync("A_up", ref A_up); ser.Sync("A_up", ref A_up);
ser.Sync("B_up", ref B_up); ser.Sync("B_up", ref B_up);