Module chip

Module chip 

Source
Expand description

The HuC6280’s programmable sound generator: six wavetable channels, noise, LFO, DDA (psg/chip.py).

Written (in the reference) from Hudson’s HuC6280 PSG Manual (tier 3: “manual” below) and MacDonald’s pcetech §10 and §2.4 (tier 2); where those are silent the choice is named in a comment with a U/C number (docs/m4-record.md) and may be changed by a switch. There is no hardware audio reference anywhere: every output of this module is provisional, tier 5.

Time: one step is one PSG clock, master/6 = 3.58 MHz [pcetech 2.4; the manual’s “7.16 MHz” and its formulas’ factor 2 agree]. A channel’s waveform index advances every F steps (F = the 12-bit frequency, 0 meaning 4096) [pcetech 10: $000 is the lowest frequency; manual 2.2.1: f = fmaster / (2 x 32 x F)]. The model is event-driven: output is constant between index changes.

Within a step every channel’s output is taken from the state at the start of the step and the counters then advance together (the manual says nothing of an order): ch 1’s modulation of ch 0 therefore reads ch 2’s sample before ch 2 advances in the same step.

Differences forced by Rust: the class attributes are the fields of PsgSwitches (Psg::switches), with variant("mame") and variant("mednafen") for the reference’s VARIANTS; keyon_mode is an enum. The step-stream listeners (the reference’s referee comparison, Python-side tooling) are not carried over. The host-rate arithmetic is the reference’s, in f64, operation for operation.

Structs§

Channel
Psg
PsgSwitches
The points on which the manual and pcetech are silent or the two readable emulators differ (docs/m4-record.md, C13-C23). Each default below follows the manual or pcetech where they speak, else the larger share of the sources; variant flips them to one emulator’s way.

Enums§

KeyOnMode
C22: what key-on (ON 0 -> 1) does to a waveform channel.

Constants§

LEVEL_BITS
10 ** (-1.5 * u / 20) for u in 0..128, as the bits of each double: the reference’s level curve (psg/chip.py _levels). Written out because powf is the platform’s and is not the same everywhere: under wasm32 nine of these came out one unit in the last place away, so a state saved in a browser would not have had a native build’s bytes. A test checks this build’s powf against the table where the two are expected to agree.
NOISE_TAPS
PSG_CLOCK_DIVIDER
SILENT_UNITS