pub struct AudioHandle<T: AudioFormatNum + AudioSample> {
    pub sample_rate: u32,
    pub channels: u8,
    pub samples: u16,
    pub producer: AudioFrameProducer<T>,
    /* private fields */
}
Expand description

The struct for producing and controlling the audio playback.

It embeds the interconnected pair of carousel’s AudioFrameProducer with the AudioFrameConsumer directly exposing the producer to the user. The consumer lives in the SDL2 audio thread and is responsible for filling up the audio output buffer with sample data sent from the producer.

The T parameter should be one of the sample primitives.

Fields§

§sample_rate: u32

The audio sample frequency of the output stream.

§channels: u8

The number of audio channels in the output stream.

§samples: u16

The number of samples in the output audio buffer.

§producer: AudioFrameProducer<T>

The audio sample producer, interconnected with an audio consumer living in the audio thread.

Implementations§

Returns the status of the audio device playback.

Starts playback of the audio device.

Pauses playback of the audio device.

Closes audio playback and frees underlying resources. Returns the unwrapped frame consumer.

Creates an instance of the AudioHandle from the provided SDL2 context.

The audio parameters used by default are the sample rate of 44100, 2 channels, and the output buffer size adjusted to the requested latency.

  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the requested audio latency; the actual latency argument passed to the create_carousel may be larger but never smaller than the provided one.

Creates an instance of the AudioHandle from the provided SDL2 context with the desired audio parameters.

The audio parameters used by default are the sample rate of 44100, 2 channels, and the output buffer size adjusted to the requested latency.

  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the requested audio latency; the actual latency argument passed to the create_carousel may be larger but never smaller than the provided one.
  • desired_spec can be populated with the desired audio parameters.
Examples found in repository?
src/host/sdl2.rs (lines 107-112)
101
102
103
104
105
106
107
108
109
110
111
112
113
    pub fn create(
                sdl_context: &Sdl,
                frame_duration_nanos: u32,
                latency: usize
            ) -> Result<Self, AudioHandleError>
    {
        Self::create_with_specs(
                sdl_context,
                AudioSpecDesired { freq: None, channels: None, samples: None },
                frame_duration_nanos,
                latency
        )
    }

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Convert to S a sample type from self.
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.