Struct Mixer

Source
pub struct Mixer {
    pub channels: FixedVec<'static, ChannelSettings>,
    /* private fields */
}
Expand description

Holds currently playing audio tracks and their playback parameters.

Fields§

§channels: FixedVec<'static, ChannelSettings>

Configurable settings for the channels where audio clips are played.

Implementations§

Source§

impl Mixer

Source

pub fn new( arena: &'static LinearAllocator<'_>, channel_count: usize, max_playing_clips: usize, playback_buffer_length: usize, ) -> Option<Mixer>

Creates a new Mixer with the specified amount of channels, a cap for how many sounds can play at the same time, and a buffer length (in samples), returning None if the allocator doesn’t have enough memory.

Each channel has its own set of controllable parameters, for e.g. tuning the volume between music and sound effects separately.

The playback buffer’s length should be at least as long as the platform’s audio buffer, plus how many samples would be played back during one frame, to avoid choppy audio. A longer length will help with avoiding audio cutting out in case of lagspikes, at the cost of taking up more memory and slowing down Mixer::render_audio. This buffer length does not affect latency.

Source

pub fn play_clip( &mut self, channel: usize, clip: AudioClipHandle, important: bool, resources: &ResourceDatabase, ) -> bool

Plays the audio clip starting this frame, returning false if the sound can’t be played.

If the mixer is already playing the maximum amount of concurrent clips, and important is true, the clip with the least playback time left will be replaced with this sound. Note that this may cause popping audio artifacts, though on the other hand, with many other sounds playing, it may not be as noticeable. If important is false, this sound will not be played.

If the channel index is out of bounds, the sound will not be played.

Source

pub fn update_audio_sync( &mut self, frame_timestamp: Instant, platform: &dyn Platform, )

Synchronizes the mixer’s internal clock with the platform’s audio buffer.

Should be called at the start of the frame by the engine.

Source

pub fn render_audio( &mut self, thread_pool: &mut ThreadPool, platform: &dyn Platform, resources: &ResourceDatabase, resource_loader: &mut ResourceLoader, )

Mixes the currently playing tracks together and updates the platform’s audio buffer with the result.

Should be called at the end of the frame by the engine.

Auto Trait Implementations§

§

impl Freeze for Mixer

§

impl RefUnwindSafe for Mixer

§

impl Send for Mixer

§

impl Sync for Mixer

§

impl Unpin for Mixer

§

impl !UnwindSafe 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.