From 65c5cdc3f59b7d5efe54c9fe09e28e4bd931d4c4 Mon Sep 17 00:00:00 2001 From: alyosha-tas Date: Tue, 7 Feb 2017 19:59:59 -0500 Subject: [PATCH] Intellivision more sound work Emualtion should be correct now, but it sounds off for the first 1 second after the emualtor starts, or when you pause and unpause it. Also sounds awful when recording a movie. Not sure what is happeneing. --- .../Consoles/Intellivision/PSG.cs | 41 ++++++++++--------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs b/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs index eefcd0d8c9..29b958db13 100644 --- a/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs +++ b/BizHawk.Emulation.Cores/Consoles/Intellivision/PSG.cs @@ -13,9 +13,10 @@ namespace BizHawk.Emulation.Cores.Intellivision public void Reset() { - sq_per_A = sq_per_B = sq_per_C = clock_A = clock_B = clock_C = 0x1000; + sq_per_A = sq_per_B = sq_per_C = clock_A = clock_B = clock_C = 0x1; noise_per = noise_clock = 64; - env_per = 0x20000; + env_per = 0x1; + DiscardSamples(); } public void DiscardSamples() @@ -54,18 +55,17 @@ namespace BizHawk.Emulation.Cores.Intellivision public void GetSamplesSync(out short[] samples, out int nsamp) { - short[] ret = new short[932 * 2]; + short[] ret = new short[(sample_count) * 2]; GetSamples(ret); samples = ret; - nsamp = 932; + nsamp = (sample_count); } public void GetSamples(short[] samples) { for (int i = 0; i < samples.Length / 2; i++) { - //samples[i * 2] = (short)(audio_samples[(int)Math.Floor(3.7904 * i)]); - samples[i * 2] = (short)(audio_samples[(4 * i)]); + samples[i * 2] = (short)(audio_samples[i]); samples[(i * 2) + 1] = samples[i * 2]; } } @@ -145,26 +145,26 @@ namespace BizHawk.Emulation.Cores.Intellivision sq_per_A = (Register[0] & 0xFF) | (((Register[4] & 0xF) << 8)); if (sq_per_A == 0) - sq_per_A = 0x1000; + sq_per_A = 0x1; sq_per_B = (Register[1] & 0xFF) | (((Register[5] & 0xF) << 8)); if (sq_per_B == 0) - sq_per_B = 0x1000; + sq_per_B = 0x1; sq_per_C = (Register[2] & 0xFF) | (((Register[6] & 0xF) << 8)); if (sq_per_C == 0) - sq_per_C = 0x1000; + sq_per_C = 0x1; env_per = (Register[3] & 0xFF) | (((Register[7] & 0xFF) << 8)); if (env_per == 0) - env_per = 0x20000; + env_per = 0x1; - A_on = Register[8].Bit(0); - B_on = Register[8].Bit(1); - C_on = Register[8].Bit(2); - A_noise = Register[8].Bit(3); - B_noise = Register[8].Bit(4); - C_noise = Register[8].Bit(5); + A_on = !Register[8].Bit(0); + B_on = !Register[8].Bit(1); + C_on = !Register[8].Bit(2); + A_noise = !Register[8].Bit(3); + B_noise = !Register[8].Bit(4); + C_noise = !Register[8].Bit(5); noise_per = Register[9] & 0x1F; if (noise_per == 0) @@ -325,9 +325,9 @@ namespace BizHawk.Emulation.Cores.Intellivision clock_C = sq_per_C; } - sound_out_A = (noise.Bit(0) | A_noise) & (A_on | A_up); - sound_out_B = (noise.Bit(0) | B_noise) & (B_on | B_up); - sound_out_C = (noise.Bit(0) | C_noise) & (C_on | C_up); + sound_out_A = (noise.Bit(0) & A_noise) | (A_on & A_up); + sound_out_B = (noise.Bit(0) & B_noise) | (B_on & B_up); + sound_out_C = (noise.Bit(0) & C_noise) | (C_on & C_up); //now calculate the volume of each channel and add them together if (env_vol_A == 0) @@ -340,6 +340,7 @@ namespace BizHawk.Emulation.Cores.Intellivision if (shift_A < 0) shift_A = 0; audio_samples[sample_count] = (short)(sound_out_A ? (volume_table[env_E]>>shift_A) : 0); + //Console.WriteLine("using env volume"); } if (env_vol_B == 0) @@ -352,6 +353,7 @@ namespace BizHawk.Emulation.Cores.Intellivision if (shift_B < 0) shift_B = 0; audio_samples[sample_count] += (short)(sound_out_B ? (volume_table[env_E] >> shift_B) : 0); + //Console.WriteLine("using env volume"); } if (env_vol_C == 0) @@ -364,6 +366,7 @@ namespace BizHawk.Emulation.Cores.Intellivision if (shift_C < 0) shift_C = 0; audio_samples[sample_count] += (short)(sound_out_C ? (volume_table[env_E] >> shift_C) : 0); + //Console.WriteLine("using env volume"); } sample_count++; }