pub enum AudioHandleAnyFormat {
    I16(AudioHandle<i16>),
    U16(AudioHandle<u16>),
    F32(AudioHandle<f32>),
}
Expand description

The enum for producing and controlling the audio playback regardless of the sample format used.

Variants§

Implementations§

Returns the sample format of the current variant.

Returns the audio sample frequency of the output stream.

Returns the number of audio channels in the output stream.

Starts playback of the audio device.

Pauses playback of the audio device.

Closes audio playback and frees underlying resources.

Calls the underlying AudioFrameProducer::send_frame.

Creates an instance of the AudioHandleAnyFormat from the provided cpal host with the default output device and the default audio parameters.

  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the audio latency passed to the create_carousel.

Creates an instance of the AudioHandleAnyFormat from the provided cpal device with the default audio parameters.

  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the audio latency passed to the create_carousel.
Examples found in repository?
src/host/cpal.rs (line 127)
118
119
120
121
122
123
124
125
126
127
128
    pub fn create(
            host: &cpal::Host,
            frame_duration_nanos: u32,
            latency: usize
        ) -> Result<Self, AudioHandleError>
    {
        let device = host.default_output_device()
                     .ok_or_else(|| ("no default output device".to_string(),
                                    AudioHandleErrorKind::AudioSubsystem))?;
        Self::create_with_device(&device, frame_duration_nanos, latency)
    }

Creates an instance of the AudioHandleAnyFormat from the provided cpal device with the desired audio parameters and sample format.

  • config specifies the desired audio parameters.
  • frame_duration_nanos is the duration in nanoseconds of the standard emulation frame.
  • latency is the audio latency passed to the create_carousel.
Examples found in repository?
src/host/cpal.rs (lines 141-146)
134
135
136
137
138
139
140
141
142
143
144
145
146
147
    pub fn create_with_device(
            device: &cpal::Device,
            frame_duration_nanos: u32,
            latency: usize
        ) -> Result<Self, AudioHandleError>
    {
        let config = device.default_output_config()?.config();
        Self::create_with_device_and_config(
            device,
            &config,
            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.