Skip to content
This repository has been archived by the owner on Aug 30, 2021. It is now read-only.

Commit

Permalink
VSU: Describe various clock periods in terms of sample clock period
Browse files Browse the repository at this point in the history
When calculating these numbers, I took the frequencies listed in the hw docs and calculated their periods in cycles, rounded to whole numbers. When looking at this again, it's clear that all of them work out to be simple multiples of the sample clock period, which is highly likely, assuming there's a single clock divider for all of these circuits, followed by even simpler/smaller counters.

This patch only changes how these constants are calculated; a more accurate/faithful implementation would update these counters only when the sample clock period occurs. I may implement this in a later patch.
  • Loading branch information
yupferris committed Oct 12, 2020
1 parent 0e68e0f commit c7e2729
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions rustual-boy-core/src/vsu/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ use self::mem_map::*;
// Note that the documentation rounds values in a lot of places, so that's probably what happened here.
pub const SAMPLE_RATE: u32 = 41667;

// 20mhz / 41.7khz = ~480 clocks
// 20mhz / 41.7khz
const SAMPLE_CLOCK_PERIOD: u32 = 480;

// 20mhz / 260.4hz = ~76805 clocks
const DURATION_CLOCK_PERIOD: u32 = 76805;
// 20mhz / 260.4hz
const DURATION_CLOCK_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 160;

// 20mhz / 65.1hz = ~307218 clocks
const ENVELOPE_CLOCK_PERIOD: u32 = 307218;
// 20mhz / 65.1hz
const ENVELOPE_CLOCK_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 640;

// 20mhz / 5mhz = 4 clocks
// 20mhz / 5mhz
const FREQUENCY_CLOCK_PERIOD: u32 = 4;

// 20mhz / 1041.6hz = ~19200 clocks
const SWEEP_MOD_SMALL_PERIOD: u32 = 19200;
// 20mhz / 1041.6hz
const SWEEP_MOD_SMALL_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 40;

// 20mhz / 130.2hz = ~153600 clocks
const SWEEP_MOD_LARGE_PERIOD: u32 = 153600;
// 20mhz / 130.2hz
const SWEEP_MOD_LARGE_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 320;

// 20mhz / 500khz = 40 clocks
const NOISE_CLOCK_PERIOD: u32 = 40;
Expand Down

0 comments on commit c7e2729

Please sign in to comment.