From 7814c26d9da7973bc7cb9ab5442d188c7a2e3887 Mon Sep 17 00:00:00 2001 From: nattthebear Date: Wed, 5 Apr 2017 17:24:48 -0400 Subject: [PATCH] possibly make intellivision sound worse --- .../Intellivision/Intellivision.IEmulator.cs | 3 - .../Consoles/Intellivision/PSG.cs | 100 +++++++++++------- 2 files changed, 61 insertions(+), 42 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs index f76fb92bbd..f6efe84e1c 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/Intellivision.IEmulator.cs @@ -21,9 +21,6 @@ namespace BizHawk.Emulation.Cores.Intellivision else _cpu.TraceCallback = null; - //reset the count of audio samples - _psg.sample_count = 0; - _frame++; stic_row = -1; // read the controller state here for now diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs index cc1194388a..cbbf4909bf 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs @@ -7,16 +7,25 @@ namespace BizHawk.Emulation.Cores.Intellivision { public sealed class PSG : ISoundProvider { + private BlipBuffer _blip = new BlipBuffer(4096); + private short[] _sampleBuffer = new short[0]; + + + public PSG() + { + _blip.SetRates(894866 / 4.0, 44100); + } + public ushort[] Register = new ushort[16]; - public int total_clock; + public int total_clock; // TODO: what is this uaed for? public void Reset() { clock_A = clock_B = clock_C = 0x1000; noise_clock = 0x20; - for (int i=0;i<16;i++) + for (int i = 0; i < 16; i++) { Register[i] = 0x0000; } @@ -26,7 +35,8 @@ namespace BizHawk.Emulation.Cores.Intellivision public void DiscardSamples() { - sample_count = 0; + _blip.Clear(); + _sampleClock = 0; } public void GetSamplesAsync(short[] samples) @@ -54,28 +64,33 @@ namespace BizHawk.Emulation.Cores.Intellivision public void GetSamplesSync(out short[] samples, out int nsamp) { - short[] ret = new short[736 * 2]; - GetSamples(ret); - samples = ret; - nsamp = 736; + _blip.EndFrame((uint)_sampleClock); + _sampleClock = 0; + + nsamp = _blip.SamplesAvailable(); + int targetLength = nsamp * 2; + if (_sampleBuffer.Length != targetLength) + _sampleBuffer = new short[targetLength]; + + _blip.ReadSamplesLeft(_sampleBuffer, nsamp); + for (int i = 0; i < _sampleBuffer.Length; i += 2) + { + _sampleBuffer[i + 1] = _sampleBuffer[i]; + } + + samples = _sampleBuffer; } public void GetSamples(short[] samples) { - for (int i = 0; i < samples.Length / 2; i++) - { - samples[i * 2] = (short)(audio_samples[(int)Math.Floor(5.072*i)]); - samples[(i * 2) + 1] = samples[i * 2]; - } + throw new Exception(); } - // There is one audio clock for every 4 cpu clocks, and ~15000 cycles per frame - public short[] audio_samples = new short[4000]; - public static int[] volume_table = new int[16] {0x0000, 0x0055, 0x0079, 0x00AB, 0x00F1, 0x0155, 0x01E3, 0x02AA, 0x03C5, 0x0555, 0x078B, 0x0AAB, 0x0F16, 0x1555, 0x1E2B, 0x2AAA}; - public int sample_count; + private int _sampleClock; + private int _latchedSample; public int TotalExecutedCycles; public int PendingCycles; @@ -98,7 +113,7 @@ namespace BizHawk.Emulation.Cores.Intellivision public int noise_clock; public int noise_per; - public int noise=0x1; + public int noise = 0x1; public Func ReadMemory; public Func WriteMemory; @@ -111,7 +126,6 @@ namespace BizHawk.Emulation.Cores.Intellivision ser.Sync("Toal_executed_cycles", ref TotalExecutedCycles); ser.Sync("Pending_Cycles", ref PendingCycles); - ser.Sync("sample_count", ref sample_count); ser.Sync("psg_clock", ref psg_clock); ser.Sync("clock_A", ref clock_A); ser.Sync("clock_B", ref clock_B); @@ -220,12 +234,12 @@ namespace BizHawk.Emulation.Cores.Intellivision { env_E = 15; E_up_down = -1; - } + } else { env_E = 0; E_up_down = 1; - } + } } return true; } @@ -239,11 +253,11 @@ namespace BizHawk.Emulation.Cores.Intellivision bool sound_out_B; bool sound_out_C; - for (int i=0;i>shift_A) : 0); + v = (short)(sound_out_A ? (volume_table[env_E] >> shift_A) : 0); } - + if (env_vol_B == 0) { - audio_samples[sample_count] += (short)(sound_out_B ? volume_table[vol_B] : 0); - + v += (short)(sound_out_B ? volume_table[vol_B] : 0); + } else { int shift_B = 3 - env_vol_B; if (shift_B < 0) shift_B = 0; - audio_samples[sample_count] += (short)(sound_out_B ? (volume_table[env_E] >> shift_B) : 0); + v += (short)(sound_out_B ? (volume_table[env_E] >> shift_B) : 0); } - + if (env_vol_C == 0) { - audio_samples[sample_count] += (short)(sound_out_C ? volume_table[vol_C] : 0); + v += (short)(sound_out_C ? volume_table[vol_C] : 0); } else { int shift_C = 3 - env_vol_C; if (shift_C < 0) shift_C = 0; - audio_samples[sample_count] += (short)(sound_out_C ? (volume_table[env_E] >> shift_C) : 0); + v += (short)(sound_out_C ? (volume_table[env_E] >> shift_C) : 0); } - - sample_count++; + + if (v != _latchedSample) + { + _blip.AddDelta((uint)_sampleClock, v - _latchedSample); + _latchedSample = v; + } + + _sampleClock++; } }