From 102dee962266c2e428a942d58a37e0cc12bb9a75 Mon Sep 17 00:00:00 2001 From: sverx Date: Thu, 27 Apr 2023 06:46:52 +0100 Subject: [PATCH] Fix some SMS audio inaccuracies (squashed PR #3602) * fix noise audio channel on SMS VDP * Update SN76489sms.cs also, white noise is generated by XORing bits 0 and 3, not 0 and 1, on an SMS/GG VDP * Update SN76489sms.cs reverting commit #7b857e7 --- .../Sound/SN76489sms.cs | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/src/BizHawk.Emulation.Cores/Sound/SN76489sms.cs b/src/BizHawk.Emulation.Cores/Sound/SN76489sms.cs index b1fdceee12..d751292594 100644 --- a/src/BizHawk.Emulation.Cores/Sound/SN76489sms.cs +++ b/src/BizHawk.Emulation.Cores/Sound/SN76489sms.cs @@ -24,8 +24,6 @@ namespace BizHawk.Emulation.Cores.Components public int noise_rate; public bool noise_bit; - public ushort tone_low; - public bool A_L, B_L, C_L, noise_L; public bool A_R, B_R, C_R, noise_R; @@ -90,8 +88,6 @@ namespace BizHawk.Emulation.Cores.Components ser.Sync(nameof(noise_clock), ref noise_clock); ser.Sync(nameof(noise_bit), ref noise_bit); - ser.Sync(nameof(tone_low), ref tone_low); - ser.Sync(nameof(psg_clock), ref psg_clock); ser.Sync(nameof(A_up), ref A_up); @@ -137,7 +133,8 @@ namespace BizHawk.Emulation.Cores.Components { if (chan_sel < 3) { - tone_low = (ushort)(value & 0xF); + Chan_tone[chan_sel] &= 0x3F0; + Chan_tone[chan_sel] |= (ushort)(value & 0xF); } else { @@ -159,7 +156,8 @@ namespace BizHawk.Emulation.Cores.Components { if (chan_sel < 3) { - Chan_tone[chan_sel] = (ushort)(((value & 0x3F) << 4) | tone_low); + Chan_tone[chan_sel] &= 0xF; + Chan_tone[chan_sel] |= (ushort)((value & 0x3F) << 4); } else { @@ -193,11 +191,11 @@ namespace BizHawk.Emulation.Cores.Components noise_bit = noise.Bit(0); if (noise_type) { - noise = (((noise & 1) ^ ((noise >> 1) & 1)) << 14) | (noise >> 1); + noise = (((noise & 1) ^ ((noise >> 3) & 1)) << 15) | (noise >> 1); } else { - noise = ((noise & 1) << 14) | (noise >> 1); + noise = ((noise & 1) << 15) | (noise >> 1); } if (noise_rate == 0) @@ -224,21 +222,18 @@ namespace BizHawk.Emulation.Cores.Components { A_up = !A_up; clock_A = Chan_tone[0] + 1; - if (clock_A == 1) { A_up = !A_up; } } if (clock_B == 0) { B_up = !B_up; clock_B = Chan_tone[1] + 1; - if (clock_B == 1) { B_up = !B_up; } } if (clock_C == 0) { C_up = !C_up; clock_C = Chan_tone[2] + 1; - if (clock_C == 1) { C_up = !C_up; } } // now calculate the volume of each channel and add them together @@ -260,4 +255,4 @@ namespace BizHawk.Emulation.Cores.Components } } } -} \ No newline at end of file +}