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

LoopTable

Struct LoopTable 

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

Implementations§

Source§

impl<const M: usize> LoopTable<M>

Source

pub const fn new() -> Self

An empty table.

let t = LoopTable::<8>::new();
assert!(t.handle(0).is_none());
Source

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.

Source

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());
Source

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

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

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§

Source§

impl<const M: usize> Clone for LoopTable<M>

Source§

fn clone(&self) -> LoopTable<M>

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 M: usize> Debug for LoopTable<M>

Source§

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

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

impl<const M: usize> Default for LoopTable<M>

Source§

fn default() -> Self

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

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