Skip to main content
← PSoXide SDK guides and examples · SDK 80d1c329e977 · All Cargo features enabled; check feature gates before use.

Crate psx_seq

Crate psx_seq 

Source
Expand description

Sequenced music for the PS1 SPU.

psx-seq plays songs written in the bytecode that Nintendo 64 games such as Ocarina of Time use for their music: one sequence script starts up to sixteen channel scripts, each channel starts up to four layer scripts, and the layers hold the notes. Scripts branch, loop, call, read and write IO ports the game also reads and writes, and so can follow the player: mute a channel, change the tune with the time of day, fade a part in with distance. That interactivity is why the bytecode runs at play time instead of being flattened to a list of notes.

The engine is no_std, has no heap, no floating point and no 64-bit arithmetic. Sound goes out through psx_sfx::hw::Hw, the same seam the sound-effect mixer uses, so on a host a Recorder captures every register write in order.

§Time

The engine advances in updates at UPDATE_HZ (180 per second). The caller owns the clock: Sequencer::pump takes the number of updates that have elapsed on whatever clock it has (a timer interrupt, the HBlank counter polled from a wait loop) and runs the ones that are due. After a long stall it runs at most MAX_CATCH_UP and drops the rest, so a slow frame sounds like a gap in the music, not a stampede of notes.

§Fixed point

Gains are Q15 (32768 = 1.0), pitch multipliers Q16 (65536 = 1.0), the envelope Q24. The original squares most volume terms (note velocity, channel volume, envelope level); that curve is kept because it is what shapes the dynamics.

§Example

A one-channel song (a hand-assembled sequence: initchan, ldchan, tempo, vol, then a channel that picks instrument 0, plays a note on layer 0 and ends) over an empty bank plays no sound but runs without error:

use psx_seq::Sequencer;
use psx_sfx::hw::Recorder;

let mut hw = Recorder::<64>::new();
let mut seq: Sequencer<'_, 1, 4> = Sequencer::new(0b1111);
seq.update(&mut hw);
assert!(hw.events().is_empty());

Modules§

format
The two containers: a song (PSQ1) and a bank set (PSQB).
tables
Constant tables and fixed-point helpers.

Structs§

NoteHandle
A note started by Sequencer::note_on. A stale handle (the note ended and its voice was reused) is harmless: every call on it returns false.
Sequencer
The sequencer: P players sharing N voices.

Enums§

StartError
Why a song would not start.

Constants§

CHANNELS
Channels per player.
IO_NONE
IO port value meaning “never written”.
IO_PORTS
IO ports per player and per channel.
LAYERS
Layers per channel.
MAX_CATCH_UP
Largest number of updates Sequencer::pump runs in one call.
UPDATE_HZ
Updates per second.