pub struct LoopTable<const M: usize> { /* private fields */ }Expand description
A table of M loop emitters sharing the voices of one lane.
§Example
use psx_sfx::hw::Recorder;
use psx_sfx::mixer::*;
use psx_sfx::vloop::LoopTable;
use psx_sfx::Sample;
use psx_spu::SpuAddr;
// Two voices for ambient loops, three loops competing for them.
let mut mixer = Mixer::new([Lane::new(0b11, Policy::FirstFree)], 60);
let mut hw = Recorder::<64>::new();
let wind = Sound::looped(SoundId(1), Sample::resident(SpuAddr::new(0x2000), 11025, 8), 0);
let mut loops = LoopTable::<3>::new();
loops.set(0, &wind, 4000, 4000);
loops.set(1, &wind, 2000, 2000);
loops.set(2, &wind, 500, 500);
loops.update(&mut mixer, &mut hw, 4);
assert!(loops.handle(0).is_some() && loops.handle(1).is_some());
assert!(loops.handle(2).is_none()); // the quietest waitsImplementations§
Source§impl<const M: usize> LoopTable<M>
impl<const M: usize> LoopTable<M>
Sourcepub const fn new() -> Self
pub const fn new() -> Self
An empty table.
let t = LoopTable::<8>::new();
assert!(t.handle(0).is_none());Sourcepub fn set(&mut self, index: usize, sound: &Sound, left: i16, right: i16)
pub fn set(&mut self, index: usize, sound: &Sound, left: i16, right: i16)
Register loop index, or refresh the levels it would have. The levels
are what the loop would sound like with a voice; a loop at or below the
mixer’s cull threshold gives its voice up at the next
update.
Sourcepub fn handle(&self, index: usize) -> Option<Handle>
pub fn handle(&self, index: usize) -> Option<Handle>
The handle of the voice loop index currently holds, if any.
assert!(LoopTable::<2>::new().handle(1).is_none());Sourcepub fn clear<H: Hw, const L: usize>(
&mut self,
mixer: &mut Mixer<L>,
hw: &mut H,
index: usize,
)
pub fn clear<H: Hw, const L: usize>( &mut self, mixer: &mut Mixer<L>, hw: &mut H, index: usize, )
Remove loop index, stopping its voice if it has one.
let mut loops = LoopTable::<1>::new();
loops.set(0, &sound, 900, 900);
loops.update(&mut mixer, &mut NullHw, 1);
loops.clear(&mut mixer, &mut NullHw, 0);
assert_eq!(mixer.playing(), 0);Sourcepub fn clear_all<H: Hw, const L: usize>(
&mut self,
mixer: &mut Mixer<L>,
hw: &mut H,
)
pub fn clear_all<H: Hw, const L: usize>( &mut self, mixer: &mut Mixer<L>, hw: &mut H, )
Remove every loop, stopping the voices they hold.
let mut loops = LoopTable::<4>::new();
loops.clear_all(&mut mixer, &mut NullHw);Sourcepub fn update<H: Hw, const L: usize>(
&mut self,
mixer: &mut Mixer<L>,
hw: &mut H,
max_changes: usize,
)
pub fn update<H: Hw, const L: usize>( &mut self, mixer: &mut Mixer<L>, hw: &mut H, max_changes: usize, )
Refresh the levels of loops that hold a voice, release the voices of
loops that fell silent, and hand free or weakly held voices to waiting
loops, at most max_changes hand-overs per call.
Cost is linear in M plus a scan per hand-over; call it every second
to fourth frame rather than every frame.
Trait Implementations§
Auto Trait Implementations§
impl<const M: usize> Freeze for LoopTable<M>
impl<const M: usize> RefUnwindSafe for LoopTable<M>
impl<const M: usize> Send for LoopTable<M>
impl<const M: usize> Sync for LoopTable<M>
impl<const M: usize> Unpin for LoopTable<M>
impl<const M: usize> UnsafeUnpin for LoopTable<M>
impl<const M: usize> UnwindSafe for LoopTable<M>
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)