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

Player

Struct Player 

Source
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>

Source

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).

Source

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.

Source

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.

Source

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.

Source

pub fn silence_all(&mut self)

Silence every voice now, whatever it was doing.

Source

pub const fn voice(&self, slot: usize) -> Voice

The voice in slot.

Auto Trait Implementations§

§

impl<const N: usize> Freeze for Player<N>

§

impl<const N: usize> RefUnwindSafe for Player<N>

§

impl<const N: usize> Send for Player<N>

§

impl<const N: usize> Sync for Player<N>

§

impl<const N: usize> Unpin for Player<N>

§

impl<const N: usize> UnsafeUnpin for Player<N>

§

impl<const N: usize> UnwindSafe for Player<N>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.