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
impl Mixer
Sourcepub fn new(
arena: &'static LinearAllocator<'_>,
channel_count: usize,
max_playing_clips: usize,
playback_buffer_length: usize,
) -> Option<Mixer>
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.
Sourcepub fn play_clip(
&mut self,
channel: usize,
clip: AudioClipHandle,
important: bool,
resources: &ResourceDatabase,
) -> bool
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.
Sourcepub fn update_audio_sync(
&mut self,
frame_timestamp: Instant,
platform: &dyn Platform,
)
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.
Sourcepub fn render_audio(
&mut self,
thread_pool: &mut ThreadPool,
platform: &dyn Platform,
resources: &ResourceDatabase,
resource_loader: &mut ResourceLoader,
)
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.