Skip to main content

Instances

Struct Instances 

Source
pub struct Instances {
    pub key: u64,
    pub max: u16,
    pub min_gap: f64,
    pub policy: OverLimit,
}
Expand description

Limits for one sound: at most max voices with the same key play at once, and a new one starts no sooner than min_gap seconds after the last, so that ten coins collected together do not sum into distortion.

When max voices already play, policy decides: refuse the new voice, or stop the oldest or the quietest one with a 5 ms fade. A refused start reports MixerEvent::Limited; a start within the gap is always refused. Limits are judged with the mixer’s bound on voices and its priorities when the start is applied, so scheduled starts are judged at their own frame, and a start refused for any reason stops no voice and does not begin a gap. Only instances of no higher priority than the new voice give way to it. Each start is checked against its own gap, from the sound’s last start. The mixer remembers the last starts of up to 1024 limited sounds within any 60 seconds; a limited start beyond that is refused.

Fields§

§key: u64

Voices with the same key share the limits. Instances::of keys a sound by its identity, so every voice of that audio counts, also through clones and Arcs. Keys you pick yourself should be below 2^63; internal audio and event identities occupy the upper half of the key space.

§max: u16

Most voices playing at once; 0 for no limit.

§min_gap: f64

Seconds from one start to the next, 0..=60.

§policy: OverLimit

Implementations§

Source§

impl Instances

Source

pub const fn new(key: u64) -> Self

Limits keyed by key, with no limit set yet.

Source

pub fn of(sound: &Audio) -> Self

Limits keyed by a decoded sound’s identity, which no other audio value shares, even after this one is freed.

Source

pub const fn max(self, max: u16) -> Self

Source

pub const fn min_gap(self, seconds: f64) -> Self

Source

pub const fn policy(self, policy: OverLimit) -> Self

Trait Implementations§

Source§

impl Clone for Instances

Source§

fn clone(&self) -> Instances

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for Instances

Source§

impl Debug for Instances

Source§

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

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

impl PartialEq for Instances

Source§

fn eq(&self, other: &Instances) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for Instances

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

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

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.