Skip to main content

PlaybackParams

Struct PlaybackParams 

Source
pub struct PlaybackParams {
    pub volume: f32,
    pub rate: f32,
    pub pan: f32,
    pub bus: AudioBus,
}
Expand description

How one voice should sound.

Build with the chained setters — PlaybackParams::new().volume(0.4).pan(-0.3) reads like the named arguments a Compose call site would use.

Fields§

§volume: f32

Linear gain. 1.0 is the clip’s recorded level.

§rate: f32

Playback rate, which shifts pitch with it. 1.0 is the recorded pitch, 2.0 is an octave up.

§pan: f32

Stereo position from -1.0 (hard left) through 0.0 to 1.0.

§bus: AudioBus

The mix bus this voice belongs to.

Implementations§

Source§

impl PlaybackParams

Source

pub const DEFAULT: PlaybackParams

The neutral parameters: unity gain, recorded pitch, centred, effects bus.

Source

pub const MIN_RATE: f32 = 0.05

The slowest rate a backend honours.

Source

pub const MAX_RATE: f32 = 8.0

The fastest rate a backend honours.

Source

pub const MAX_VOLUME: f32 = 4.0

The loudest gain a backend honours, leaving room to amplify a quiet clip.

Source

pub const fn new() -> PlaybackParams

The neutral parameters. Same as PlaybackParams::DEFAULT.

Source

pub fn volume(self, volume: f32) -> PlaybackParams

Sets the linear gain.

Source

pub fn rate(self, rate: f32) -> PlaybackParams

Sets the playback rate (and with it the pitch).

Source

pub fn pan(self, pan: f32) -> PlaybackParams

Sets the stereo position.

Source

pub fn bus(self, bus: AudioBus) -> PlaybackParams

Sets the mix bus.

Source

pub fn pitch_semitones(self, semitones: f32) -> PlaybackParams

Sets the rate from a pitch offset in equal-tempered semitones.

A rising combo counter reads better as pitch_semitones(combo as f32) than as a hand-computed ratio.

Source

pub fn sanitized(self) -> PlaybackParams

Clamps every field into the range backends honour and scrubs NaN.

Backends call this before handing parameters to the audio thread, which is why a NaN rate from app arithmetic cannot wedge a voice.

Source

pub fn gains(self) -> (f32, f32)

Constant-power left/right gains for these parameters, volume included.

Computed on the caller’s thread so the audio callback only multiplies.

Trait Implementations§

Source§

impl Clone for PlaybackParams

Source§

fn clone(&self) -> PlaybackParams

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 PlaybackParams

Source§

impl Debug for PlaybackParams

Source§

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

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

impl Default for PlaybackParams

Source§

fn default() -> PlaybackParams

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

impl PartialEq for PlaybackParams

Source§

fn eq(&self, other: &PlaybackParams) -> 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 PlaybackParams

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.