Use psx-seq to play music that is a program, not a recording. It runs the sequence bytecode that some Nintendo 64 games use: a 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, and read and write IO ports that the game reads and writes too, so a tune can follow the player: mute a channel, change with the time of day, or fade a part in with distance. That is why the bytecode runs at play time instead of being flattened to a list of notes.
How the crate is organized
Sequencer<P, N> runs P players, which are independent songs such as background music and a fanfare over it. They share N SPU voices and compete for them by note priority. Sequencer::new takes a mask of the voices it may use, with exactly N bits set. The sequencer is several kilobytes, so a game that keeps one in a static builds it in place with init_at. format defines the two containers: a song (PSQ1), which is the bytecode behind a short header, and a bank (PSQB), which carries instrument and drum tables, envelopes, a sample table and the SPU-ADPCM data in one block that goes to sound memory in a single transfer. NoteHandle addresses a note the game starts itself. tables holds the lookup tables the interpreter uses. The engine is no_std and uses no heap, floating point or 64-bit arithmetic.
Integration notes
Sound leaves through psx_sfx::hw::Hw, the same seam the psx-sfx mixer uses, so one hardware implementation serves both. On a host, Recorder captures every register write in order, which is how the engine is tested.
The engine advances in updates at UPDATE_HZ, which is 180 per second. The caller owns the clock: pump takes the number of updates that have elapsed on whatever clock the game has, such as a timer interrupt or a 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 instead of a burst of notes.
Load a bank with set_bank, passing the sound-memory address its samples were uploaded to, then start a song on a player. The song is patched in place by some sequences, so it needs a mutable buffer in RAM. set_player_io and set_channel_io write the ports the scripts read, set_channel_mute and fade_to shape the mix, and stop takes a fade length. Gains are Q15, pitch multipliers Q16 and envelopes Q24. The original squares most volume terms (velocity, channel volume, envelope level), and the crate keeps that curve because it shapes the dynamics. unsupported_ops counts bytecode the interpreter skipped, which is worth checking when a new song sounds wrong.
The hello-seq example plays a cooked song and reports what the sequencer costs per update. It needs a song and bank cooked with psx-seq-cook, which are not committed.
API, dependencies and source structure
SDK revision 80d1c329e977. Structure, dependencies and features below come from this revision.
The PS1 reference includes all Cargo features. The manifest below shows which features are enabled by default.
Dependencies
Cargo features
This crate declares no Cargo features.
Read the complete manifest and feature comments.
Source layout
The list includes internal implementation and test files. Public modules, types, functions and their signatures are indexed in the API reference above.
10 source and manifest files
Cargo.tomlsrc/engine.rs: The three script levels: sequence, channel, layer.src/format.rs: The two containers: a song (PSQ1) and a bank set (PSQB).src/lib.rs: Sequenced music for the PS1 SPU.src/live.rs: Notes the game plays itself, over the music: an ocarina, a jingle, asrc/note.rs: Notes: allocation, the software envelope, vibrato, portamento, and thesrc/script.rs: Reading operands and the control-flow opcodes shared by all three levels.src/tables.rs: Constant tables and fixed-point helpers.src/tests.rs: Tests drive hand-assembled songs over a one-instrument bank and read thesrc/types.rs: State records for the three levels and the note table.