Trait jumpy::prelude::kira::sound::Sound

pub trait Sound: Send {
    // Required methods
    fn output_destination(&mut self) -> OutputDestination;
    fn process(
        &mut self,
        dt: f64,
        clock_info_provider: &ClockInfoProvider<'_>,
        modulator_value_provider: &ModulatorValueProvider<'_>,
    ) -> Frame;
    fn finished(&self) -> bool;

    // Provided method
    fn on_start_processing(&mut self) { ... }
}
Expand description

An actively playing sound.

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

Required Methods§

fn output_destination(&mut self) -> OutputDestination

Returns the destination that this sound’s audio should be routed to.

This will typically be set by the user with a settings struct that’s passed to the SoundData implementor.

fn process( &mut self, dt: f64, clock_info_provider: &ClockInfoProvider<'_>, modulator_value_provider: &ModulatorValueProvider<'_>, ) -> Frame

Produces the next Frame of audio.

dt is the time that’s elapsed since the previous round of processing (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.

Implementors§