Skip to main content

Mixer

Struct Mixer 

Source
pub struct Mixer { /* private fields */ }
Expand description

The mix (module docs).

Implementations§

Source§

impl Mixer

Source

pub fn new(config: Config) -> Self

A mixer for config, with all the memory it will ever use.

Source

pub const fn config(&self) -> Config

Its output’s format.

Source

pub fn remote(&self, commands: usize) -> (Remote, Inbox)

The two ends for commanding this mixer from another thread, with room for commands commands waiting (queue).

Source

pub fn put_sound(&mut self, sound: SoundId, pcm: SharedPcm) -> Option<SharedPcm>

Puts pcm in the place of the bank Remote::reserve_sound named, and gives back what was there for the caller to free. It neither allocates nor frees, so a backend’s hand-over can call it on the audio thread.

Source

pub fn put_stream( &mut self, stream: StreamId, source: Box<dyn Source + Send>, ) -> Option<Box<dyn Source + Send>>

Holds source in the stream slot Remote::reserve_stream named, and gives back what was there for the caller to free. It neither allocates nor frees.

Source

pub fn take_stream( &mut self, stream: StreamId, ) -> Option<Box<dyn Source + Send>>

Takes stream out of its slot, ending what is playing it, for the caller to free where it may. A mix never frees one.

Source

pub fn add_sound(&mut self, pcm: SharedPcm) -> Result<SoundId, Full>

Puts pcm in the bank.

Source

pub fn remove_sound(&mut self, sound: SoundId) -> Option<SharedPcm>

Takes sound out of the bank and stops what is playing it. The caller frees it, on a thread that may.

Source

pub fn add_stream( &mut self, source: Box<dyn Source + Send>, ) -> Result<StreamId, Full>

Holds source ready to play. A slot that a finished stream still holds is freed for it; a backend with its mixer on the audio thread takes those out first (take_finished_stream).

Source

pub fn take_finished_stream(&mut self) -> Option<Box<dyn Source + Send>>

A source whose voice has finished with it, for the caller to free where it may. A mix never frees one.

Source

pub fn play(&mut self, sound: SoundId, params: Params) -> Result<VoiceId, Full>

Plays sound, or says Full. A sound no longer in the bank plays as one with no frames.

Source

pub fn stream( &mut self, source: impl Source + Send + 'static, params: Params, ) -> Result<VoiceId, Full>

Plays source, a stream that has its frames ready, or says Full.

Source

pub fn play_stream( &mut self, stream: StreamId, params: Params, ) -> Result<VoiceId, Full>

Plays a stream add_stream holds, or says Full. A stream plays once: one that was played, or is gone, plays as one with no frames.

Source

pub fn set_volume(&mut self, voice: VoiceId, volume: u16)

Jumps to volume, in 1/4096, ending any fade.

Source

pub fn fade_to(&mut self, voice: VoiceId, volume: u16, millis: u64)

Goes to volume, in 1/4096, in a straight line, over millis. A fade to nothing leaves the voice playing silently, for the caller to stop.

Source

pub fn set_balance(&mut self, voice: VoiceId, left: u16, right: u16)

Sets the left and right gains, in 1/4096.

Source

pub fn stop(&mut self, voice: VoiceId)

Ends voice now.

Source

pub fn pause(&mut self, voice: VoiceId)

Holds voice where it is, its fade too: it sounds nothing until resume.

Source

pub fn resume(&mut self, voice: VoiceId)

Goes on from where pause held it.

Source

pub fn is_playing(&self, voice: VoiceId) -> bool

Whether voice hasn’t ended. A paused voice is playing.

Source

pub fn is_paused(&self, voice: VoiceId) -> bool

Whether voice is held by pause.

Source

pub fn volume(&self, voice: VoiceId) -> Option<u16>

voice’s volume now, in 1/4096, if it is playing.

Source

pub fn playing(&self) -> usize

How many voices are playing.

Source

pub const fn underrun_frames(&self) -> u64

How many frames, added over every stream so far, had nothing to play yet because a worker hadn’t got there. A voice stops where it is for those: a stream is delayed, never skipped.

Source

pub fn render(&mut self, out: &mut [i16])

Mixes every voice into out, whole frames of interleaved samples (a part of a frame at its end is silence), then removes those that finished. No lock, no allocation, nothing freed.

Trait Implementations§

Source§

impl Debug for Mixer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for Mixer

§

impl !Sync for Mixer

§

impl !UnwindSafe for Mixer

§

impl Freeze for Mixer

§

impl Send for Mixer

§

impl Unpin for Mixer

§

impl UnsafeUnpin for Mixer

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