devela::_dep::kira::sound

Trait Sound

pub trait Sound: Send {
    // Required methods
    fn process(&mut self, out: &mut [Frame], dt: f64, info: &Info<'_>);
    fn finished(&self) -> bool;

    // Provided methods
    fn on_start_processing(&mut self) { ... }
    fn process_one(&mut self, dt: f64, info: &Info<'_>) -> Frame { ... }
}
Available on crate feature dep_kira only.
Expand description

An actively playing sound.

For performance reasons, the methods of this trait should not allocate or deallocate memory.

Required Methods§

fn process(&mut self, out: &mut [Frame], dt: f64, info: &Info<'_>)

Produces the next Frames of audio. This should overwrite the entire out slice with new audio.

dt is the time between each frame (in seconds).

fn finished(&self) -> bool

Returns true if the sound is finished and can be unloaded.

For finite sounds, this will typically be when playback has reached the end of the sound. For infinite sounds, this will typically be when the handle for the sound is dropped.

Provided Methods§

fn on_start_processing(&mut self)

Called whenever a new batch of audio samples is requested by the backend.

This is a good place to put code that needs to run fairly frequently, but not for every single audio sample.

fn process_one(&mut self, dt: f64, info: &Info<'_>) -> Frame

Processes a single Frame. Mostly useful for testing.

dt is the time elapsed since the previous frame (in seconds).

Implementors§