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

Module mixer

Module mixer 

Source
Expand description

Voice lanes, priorities, stealing, and sound handles.

Ten programs on the demo disc each own a private way of sharing the SPU’s 24 voices: a voice per job, a round robin of four, a rotating pool of fifteen, first-free with strict priority. Mixer is the one version. The 24 voices are split once, at construction, into Lanes; each lane carries a Policy that decides what a new sound does when its lane is busy.

A Mixer is bookkeeping only. It never touches a register; every decision goes out through Hw, which on the host is a Recorder.

§Time

The mixer has a clock it does not own: call Mixer::tick once per frame (or per whatever unit the game’s sound durations are in) with a counter that only goes up. One-shot lifetimes, release tails and the wrap of that counter are all handled against it. An idle mixer pays two compares per tick.

§Example

use psx_sfx::hw::Recorder;
use psx_sfx::mixer::*;
use psx_sfx::Sample;
use psx_spu::SpuAddr;

// UI sounds get two voices, round robin; the world gets the rest.
let mut mixer = Mixer::new(
    [
        Lane::new(0x00_0003, Policy::RoundRobin),
        Lane::new(0xFF_FFFC, Policy::Smart),
    ],
    60,
);
let mut hw = Recorder::<32>::new();

let beep = Sound::one_shot(SoundId(1), Sample::resident(SpuAddr::new(0x1010), 22050, 40), 0);
mixer.tick(&mut hw, 0);
let h = mixer.play(&mut hw, &beep, Play::new(0x2000, 0x2000)).unwrap();
assert!(mixer.is_alive(h));

// 40 blocks at 22.05 kHz is 3 ticks of sound plus the 2 tick margin.
mixer.tick(&mut hw, 4);
assert!(mixer.is_alive(h));
mixer.tick(&mut hw, 5);
assert!(!mixer.is_alive(h));

Structs§

Handle
A claim on one playing sound, safe to hold across frames.
Lane
A set of voices and the policy that shares them.
Mixer
The voice allocator: lanes, policies, handles and lifetimes over the SPU’s 24 voices, for L lanes.
Play
How one play request should be voiced.
Sound
A sample together with how the mixer should treat it.
SoundId
A sound’s identity in the caller’s tables. The mixer carries it through and never interprets it.

Enums§

Class
How much a sound matters, most important first.
Policy
How the voices in a lane are shared out.

Constants§

ALL_VOICES
Mask of all 24 voices.
RELEASE_TICKS
Ticks a keyed-off voice is considered still ringing before the mixer treats it as free again.
VOICES
Voices on the SPU.