From ae2936b9c3f8245e8dc7ab233bbe1af79cbdafe9 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Mon, 10 Nov 2025 22:35:13 -0500 Subject: [PATCH] Correct clock rate, triangle wave. --- Components/SID/SID.cpp | 5 ++++- Components/SID/SID.hpp | 5 +++-- Machines/Acorn/BBCMicro/BBCMicro.cpp | 6 +++--- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/Components/SID/SID.cpp b/Components/SID/SID.cpp index 7ce118e36..cbcf36f9c 100644 --- a/Components/SID/SID.cpp +++ b/Components/SID/SID.cpp @@ -35,7 +35,10 @@ void SID::write(const Numeric::SizedInt<5> address, const uint8_t value) { oscillator().pulse_width = (oscillator().pitch & 0xf0'00'00'00) | uint32_t(value << 20); break; case 0x03: case 0x0a: case 0x11: - oscillator().pulse_width = (oscillator().pitch & 0x0f'f0'00'00) | uint32_t(value << 28); + // The top bit of the phase counter is inverted; since it'll be compared directly with the + // pulse width, invert that bit too. + oscillator().pulse_width = + ((oscillator().pitch & 0x0f'f0'00'00) | uint32_t(value << 28)) ^ 0x8000'0000; break; case 0x04: case 0x0b: case 0x12: voice().control = value; diff --git a/Components/SID/SID.hpp b/Components/SID/SID.hpp index 0af6307f5..b31046d7d 100644 --- a/Components/SID/SID.hpp +++ b/Components/SID/SID.hpp @@ -116,8 +116,9 @@ private: uint16_t triangle_output(const Voice &prior) const { const uint16_t sawtooth = oscillator.sawtooth(); - const uint16_t xor_mask = - ((sawtooth ^ (ring_mod() && prior.sawtooth())) & 0x800) ? 0xfff : 0x000; + const uint16_t xor_mask1 = sawtooth; + const uint16_t xor_mask2 = ring_mod() ? prior.sawtooth() : 0; + const uint16_t xor_mask = (xor_mask1 ^ xor_mask2) ? 0xfff : 0x000; return ((sawtooth << 1) ^ xor_mask) & 0xfff; } diff --git a/Machines/Acorn/BBCMicro/BBCMicro.cpp b/Machines/Acorn/BBCMicro/BBCMicro.cpp index 7e043a2e1..ccde89530 100644 --- a/Machines/Acorn/BBCMicro/BBCMicro.cpp +++ b/Machines/Acorn/BBCMicro/BBCMicro.cpp @@ -128,13 +128,13 @@ private: public: Audio() : - sn76489_(TI::SN76489::Personality::SN76489, audio_queue_, 2), + sn76489_(TI::SN76489::Personality::SN76489, audio_queue_, 4), sid_(audio_queue_), compound_(sn76489_, sid_), speaker_(speaker_source()) { - // Combined with the additional divider specified above, implies this chip is clocked at 4Mhz. - speaker_.set_input_rate(2'000'000.0f); + // Combined with the additional divider specified above, implies the SN76489 is clocked at 4Mhz. + speaker_.set_input_rate(1'000'000.0f); } ~Audio() {