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>
impl<const CAP: usize> Recorder<CAP>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
An empty recorder.
assert!(Recorder::<4>::new().events().is_empty());Sourcepub fn events(&self) -> &[Event]
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)]);Sourcepub const fn dropped(&self) -> u32
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);Sourcepub fn clear(&mut self)
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());Sourcepub fn keyed_on(&self) -> u32
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);Sourcepub fn keyed_off(&self) -> u32
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);Sourcepub fn last_volume(&self, voice: u8) -> Option<(i16, i16)>
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> Hw for Recorder<CAP>
impl<const CAP: usize> Hw for Recorder<CAP>
Source§fn configure(
&mut self,
voice: u8,
sample: &Sample,
looped: bool,
pitch_q12: u16,
)
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)
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).
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 Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)