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

Recorder

Struct Recorder 

Source
pub struct Recorder<const CAP: usize> { /* private fields */ }
Expand description

An Hw that logs every call into a fixed buffer, in order.

It needs no heap, so it also runs on the console, where a golden test can compare the trace of two builds. When more than CAP calls arrive the extra ones are counted in dropped and not stored.

§Example

use psx_sfx::hw::{Event, Hw, Recorder};

let mut rec = Recorder::<8>::new();
rec.set_volume(3, 100, -100);
rec.key_on(1 << 3);
assert_eq!(
    rec.events(),
    &[
        Event::Volume { voice: 3, left: 100, right: -100 },
        Event::KeyOn(1 << 3),
    ]
);

Implementations§

Source§

impl<const CAP: usize> Recorder<CAP>

Source

pub const fn new() -> Self

An empty recorder.

assert!(Recorder::<4>::new().events().is_empty());
Source

pub fn events(&self) -> &[Event]

Everything logged so far, oldest first.

let mut r = Recorder::<4>::new();
r.key_off(2);
assert_eq!(r.events(), &[Event::KeyOff(2)]);
Source

pub const fn dropped(&self) -> u32

Calls that arrived after the buffer filled and were not stored.

let mut r = Recorder::<1>::new();
r.key_on(1);
r.key_on(2);
assert_eq!(r.dropped(), 1);
Source

pub fn clear(&mut self)

Forget everything logged so far.

let mut r = Recorder::<4>::new();
r.key_on(1);
r.clear();
assert!(r.events().is_empty());
Source

pub fn keyed_on(&self) -> u32

Union of every voice that was keyed on since the last clear.

let mut r = Recorder::<4>::new();
r.key_on(0b01);
r.key_on(0b10);
assert_eq!(r.keyed_on(), 0b11);
Source

pub fn keyed_off(&self) -> u32

Union of every voice that was keyed off since the last clear.

let mut r = Recorder::<4>::new();
r.key_off(0b100);
assert_eq!(r.keyed_off(), 0b100);
Source

pub fn last_volume(&self, voice: u8) -> Option<(i16, i16)>

The most recent volume written to voice, if any.

let mut r = Recorder::<4>::new();
r.set_volume(5, 10, 20);
assert_eq!(r.last_volume(5), Some((10, 20)));
assert_eq!(r.last_volume(6), None);

Trait Implementations§

Source§

impl<const CAP: usize> Clone for Recorder<CAP>

Source§

fn clone(&self) -> Recorder<CAP>

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<const CAP: usize> Debug for Recorder<CAP>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<const CAP: usize> Default for Recorder<CAP>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<const CAP: usize> Hw for Recorder<CAP>

Source§

fn configure( &mut self, voice: u8, sample: &Sample, looped: bool, pitch_q12: u16, )

Point voice at sample without starting it. looped selects the hardware-loop setup; a one-shot also gets its repeat address written so it parks on silence. pitch_q12 is a multiplier of the cooked rate (4096 plays it as recorded).
Source§

fn set_volume(&mut self, voice: u8, left: i16, right: i16)

Write a voice’s left and right volume (signed SPU levels, already scaled by the master volume).
Source§

fn set_pitch(&mut self, voice: u8, pitch_q12: u16)

Change a playing voice’s pitch multiplier (4096 = as cooked).
Source§

fn key_on(&mut self, mask: u32)

Key on every voice in mask.
Source§

fn key_off(&mut self, mask: u32)

Key off (release) every voice in mask.

Auto Trait Implementations§

§

impl<const CAP: usize> Freeze for Recorder<CAP>

§

impl<const CAP: usize> RefUnwindSafe for Recorder<CAP>

§

impl<const CAP: usize> Send for Recorder<CAP>

§

impl<const CAP: usize> Sync for Recorder<CAP>

§

impl<const CAP: usize> Unpin for Recorder<CAP>

§

impl<const CAP: usize> UnsafeUnpin for Recorder<CAP>

§

impl<const CAP: usize> UnwindSafe for Recorder<CAP>

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> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.