Struct spectrusty_audio::host::cpal::AudioHandle
source · pub struct AudioHandle<T: Sample + AudioSample> {
pub sample_rate: u32,
pub channels: u8,
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
cpal 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.
producer: AudioFrameProducer<T>
The audio sample producer, interconnected with an audio consumer living in the audio thread.
Implementations§
source§impl<T: Sample + AudioSample> AudioHandle<T>
impl<T: Sample + AudioSample> AudioHandle<T>
sourcepub fn play(&self) -> Result<(), AudioHandleError>
pub fn play(&self) -> Result<(), AudioHandleError>
Starts playback of the audio device.
sourcepub fn pause(&self) -> Result<(), AudioHandleError>
pub fn pause(&self) -> Result<(), AudioHandleError>
Pauses playback of the audio device.
sourcepub fn create_with_device_and_config(
device: &Device,
config: &StreamConfig,
frame_duration_nanos: u32,
latency: usize
) -> Result<Self, AudioHandleError>
pub fn create_with_device_and_config(
device: &Device,
config: &StreamConfig,
frame_duration_nanos: u32,
latency: usize
) -> Result<Self, AudioHandleError>
Creates an instance of the AudioHandle from the provided cpal device
with the
desired audio parameters.
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?
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172
pub fn create_with_device_and_config(
device: &cpal::Device,
config: &cpal::StreamConfig,
frame_duration_nanos: u32,
latency: usize,
) -> Result<Self, AudioHandleError>
{
Ok(match device.default_output_config()?.sample_format() {
SampleFormat::I16 => AudioHandleAnyFormat::I16(
AudioHandle::<i16>::create_with_device_and_config(device, config, frame_duration_nanos, latency)?
),
SampleFormat::U16 => AudioHandleAnyFormat::U16(
AudioHandle::<u16>::create_with_device_and_config(device, config, frame_duration_nanos, latency)?
),
SampleFormat::F32 => AudioHandleAnyFormat::F32(
AudioHandle::<f32>::create_with_device_and_config(device, config, frame_duration_nanos, latency)?
)
})
}
Auto Trait Implementations§
impl<T> !RefUnwindSafe for AudioHandle<T>
impl<T> !Send for AudioHandle<T>
impl<T> !Sync for AudioHandle<T>
impl<T> Unpin for AudioHandle<T>where
T: Unpin,
impl<T> !UnwindSafe for AudioHandle<T>
Blanket Implementations§
source§impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
impl<S, T> IntoSample<S> for Twhere
S: FromSample<T>,
source§fn into_sample(self) -> S
fn into_sample(self) -> S
S
a sample type from self
.