code wiki / _hdl_build / nx_gamemusic.nx
nx_gamemusic.nx
buildroot/runtime/_hdl_build/nx_gamemusic.nx
about
nx_gamemusic.nx -- the SOVEREIGN MUSIC/SEQUENCER PART, completing the `audio-sfx-music` capability.
nx_game_audio_gate already PROVES the SFX half (nx_audio_sfx + nx_audio_wav: coin/laser/explosion,
real WAV + waveform, 3/3 GREEN) and says in-band that audio "needs WIRING to games". What was genuinely
missing was MUSIC: nothing turned a SONG into audio, so claiming the full capability would have been an
overclaim on the strength of the SFX gate alone.
COMPOSES rather than rebuilds (DRY / no-proliferation law): note oscillation reuses `sfx_tone` from
nx_audio_sfx, output reuses `wav_render_stereo`/`wav_save` from nx_audio_wav. This part adds only what was
absent -- pitch, envelope, sequencing and mixing.
CERTIFIED PROPERTIES (each a gate tooth):
1. EXACT INTEGER EQUAL-TEMPERAMENT. Pitch comes from a 12-note table with octave shifts by doubling or
halving, so A4=440 -> A5=880 is EXACT. No float, no pow(), no drift between builds or machines.
2. DETERMINISTIC RENDER -- the same song data yields byte-identical audio, so a soundtrack is
reproducible and diffable (the determinism exceed, carried into audio).
3. DATA-DRIVEN SONGS (rule 11) -- a song is an array of (semitone, octave, ticks); melodies are DATA,
never code. Rest is encoded as semitone -1.
4. SATURATING MIX -- layering tracks cannot wrap the sample and produce the click/crack of integer
overflow; it clamps at the sample ceiling instead.
5. PER-NOTE ENVELOPE -- notes attack and decay rather than clicking on/off at full amplitude.
LIB ONLY -- no main() by ecosystem convention.
license_tier: ORIGINAL expect_exit: 0
dependencies 2 imports · 3 importers
imports: nx_syscalls.nxnx_audio_sfx.nx
imported by: nx_gamemusic_gate.nxnx_wire_diablo2_gate.nxnx_wire_endlesssky_gate.nx
structs
| none |
consts
| 26 | const MUS_SAMPMAX: i64 = 32000 // i16 headroom for the WAV writer |
| 27 | const MUS_REST: i64 = 0-1 |
functions
| 30 | func mus_base_hz(semi: i64) -> i64 called by 1: mus_note_freq |
| 46 | func mus_note_freq(semi: i64, octave: i64) -> i64 |
| 56 | func mus_env(i: i64, n: i64, attack: i64) -> i64 |
| 67 | func mus_mixadd(a: i64, b: i64) -> i64 called by 1: mus_render |
| 76 | func mus_render(out: *i64, nsamp: i64, song: *i64, nnotes: i64, called by 3: maind2_render_themee_render_theme calls 5: sys_mmapmus_note_freqsfx_tonemus_envmus_mixadd |
| 109 | func mus_song_samples(song: *i64, nnotes: i64, tick_samples: i64) -> i64 called by 1: main |