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

Commit c7e2729

Browse files
committedOct 12, 2020
VSU: Describe various clock periods in terms of sample clock period
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.
1 parent 0e68e0f commit c7e2729

File tree

1 file changed

+10
-10
lines changed
  • rustual-boy-core/src/vsu

1 file changed

+10
-10
lines changed
 

‎rustual-boy-core/src/vsu/mod.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -9,23 +9,23 @@ use self::mem_map::*;
99
// Note that the documentation rounds values in a lot of places, so that's probably what happened here.
1010
pub const SAMPLE_RATE: u32 = 41667;
1111

12-
// 20mhz / 41.7khz = ~480 clocks
12+
// 20mhz / 41.7khz
1313
const SAMPLE_CLOCK_PERIOD: u32 = 480;
1414

15-
// 20mhz / 260.4hz = ~76805 clocks
16-
const DURATION_CLOCK_PERIOD: u32 = 76805;
15+
// 20mhz / 260.4hz
16+
const DURATION_CLOCK_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 160;
1717

18-
// 20mhz / 65.1hz = ~307218 clocks
19-
const ENVELOPE_CLOCK_PERIOD: u32 = 307218;
18+
// 20mhz / 65.1hz
19+
const ENVELOPE_CLOCK_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 640;
2020

21-
// 20mhz / 5mhz = 4 clocks
21+
// 20mhz / 5mhz
2222
const FREQUENCY_CLOCK_PERIOD: u32 = 4;
2323

24-
// 20mhz / 1041.6hz = ~19200 clocks
25-
const SWEEP_MOD_SMALL_PERIOD: u32 = 19200;
24+
// 20mhz / 1041.6hz
25+
const SWEEP_MOD_SMALL_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 40;
2626

27-
// 20mhz / 130.2hz = ~153600 clocks
28-
const SWEEP_MOD_LARGE_PERIOD: u32 = 153600;
27+
// 20mhz / 130.2hz
28+
const SWEEP_MOD_LARGE_PERIOD: u32 = SAMPLE_CLOCK_PERIOD * 320;
2929

3030
// 20mhz / 500khz = 40 clocks
3131
const NOISE_CLOCK_PERIOD: u32 = 40;

0 commit comments

Comments
 (0)
This repository has been archived.