pub struct Player<const N: usize> { /* private fields */ }Expand description
Plays one-shots across a fixed set of voices, silencing each when its sample has run out.
N voices are driven round-robin by Player::play, or addressed
directly by Player::play_on when a sound wants a voice of its own.
Implementations§
Source§impl<const N: usize> Player<N>
impl<const N: usize> Player<N>
Sourcepub const fn new(voices: [Voice; N], ticks_hz: u32) -> Self
pub const fn new(voices: [Voice; N], ticks_hz: u32) -> Self
Drive voices from a clock running at ticks_hz (60 for NTSC frames,
50 for PAL).
Sourcepub fn tick(&mut self, now: u32)
pub fn tick(&mut self, now: u32)
Silence any voice whose sample has ended. Call once per tick, before anything that might start a new sound.
Sourcepub fn play_on(&mut self, slot: usize, shot: &OneShot, now: u32)
pub fn play_on(&mut self, slot: usize, shot: &OneShot, now: u32)
Fire shot on a specific voice slot.
A shot whose sample has no recorded length gets no cutoff: the voice runs until its envelope finishes it, which is what every one-shot did before this crate existed.
Sourcepub fn play(&mut self, shot: &OneShot, now: u32) -> usize
pub fn play(&mut self, shot: &OneShot, now: u32) -> usize
Fire shot on the next voice in the rotation, and return which slot
took it.
Round-robin rather than picking an idle voice: finding the idle one costs a scan, and a rotation of a few voices means a new sound rarely lands on one that is still sounding anyway.
Sourcepub fn silence_all(&mut self)
pub fn silence_all(&mut self)
Silence every voice now, whatever it was doing.