pub struct AudioHandler { /* private fields */ }Expand description
Concrete implementation of AudioHandlerTrait backed by real CPAL devices.
AudioHandler owns the input device, output device, and stream configuration
required to build CPAL streams. It is cheaply cloneable so that it can be
shared across threads via Arc.
Implementations§
Source§impl AudioHandler
Auto-generated by derive_getters::Getters.
impl AudioHandler
Auto-generated by derive_getters::Getters.
Sourcepub fn input_device(&self) -> &Device
pub fn input_device(&self) -> &Device
Get field input_device from instance of AudioHandler.
Sourcepub fn output_device(&self) -> &Device
pub fn output_device(&self) -> &Device
Get field output_device from instance of AudioHandler.
Sourcepub fn input_config(&self) -> &StreamConfig
pub fn input_config(&self) -> &StreamConfig
Get field input_config from instance of AudioHandler.
Sourcepub fn output_config(&self) -> &StreamConfig
pub fn output_config(&self) -> &StreamConfig
Get field output_config from instance of AudioHandler.
Sourcepub fn input_sample_rate(&self) -> &u32
pub fn input_sample_rate(&self) -> &u32
Get field input_sample_rate from instance of AudioHandler.
Sourcepub fn output_sample_rate(&self) -> &u32
pub fn output_sample_rate(&self) -> &u32
Get field output_sample_rate from instance of AudioHandler.
Source§impl AudioHandler
impl AudioHandler
Sourcepub fn new(
input_device: Device,
output_device: Device,
input_config: StreamConfig,
output_config: StreamConfig,
) -> Self
pub fn new( input_device: Device, output_device: Device, input_config: StreamConfig, output_config: StreamConfig, ) -> Self
Creates a new AudioHandler with the given CPAL devices and stream config.
§Arguments
input_device- The CPAL device used to capture audio.output_device- The CPAL device used to play back audio.input_config- The [StreamConfig] used for the input stream.output_config- The [StreamConfig] used for the output stream.
Sourcepub fn create_ringbuffer(size: usize) -> (HeapProd<f32>, HeapCons<f32>)
pub fn create_ringbuffer(size: usize) -> (HeapProd<f32>, HeapCons<f32>)
Creates a lock-free ring buffer of f32 samples with the given capacity.
Returns a (producer, consumer) pair that can be moved into separate
threads for wait-free, single-producer/single-consumer audio transfer.
§Arguments
size- The number off32samples the ring buffer can hold.
Sourcepub fn set_output_device(&mut self, output_device: Device)
pub fn set_output_device(&mut self, output_device: Device)
Sourcepub fn set_input_device(&mut self, input_device: Device)
pub fn set_input_device(&mut self, input_device: Device)
Trait Implementations§
Source§impl AudioHandlerTrait for AudioHandler
impl AudioHandlerTrait for AudioHandler
Source§fn build_input_stream(&self, producer: HeapProd<f32>) -> Box<dyn PlayableStream>
fn build_input_stream(&self, producer: HeapProd<f32>) -> Box<dyn PlayableStream>
Builds a CPAL input stream that forwards every captured sample into the provided ring-buffer producer.
Samples that cannot be pushed (i.e. the ring buffer is full) are silently dropped. Input errors are added to logs as error.
§Panics
Panics if CPAL fails to build the input stream.
Source§fn build_output_stream(
&self,
consumer: HeapCons<f32>,
) -> Box<dyn PlayableStream>
fn build_output_stream( &self, consumer: HeapCons<f32>, ) -> Box<dyn PlayableStream>
Builds a CPAL output stream that drains samples from the provided ring-buffer consumer into the hardware output buffer.
Any output slot that has no corresponding sample is filled with 0.0
(silence). Output errors are printed to stderr.
§Panics
Panics if CPAL fails to build the output stream.
Source§fn input_device(&self) -> &Device
fn input_device(&self) -> &Device
Source§fn output_device(&self) -> &Device
fn output_device(&self) -> &Device
Source§fn input_config(&self) -> &StreamConfig
fn input_config(&self) -> &StreamConfig
StreamConfig] used for the input stream.Source§fn output_config(&self) -> &StreamConfig
fn output_config(&self) -> &StreamConfig
StreamConfig] used for the output stream.Source§fn input_sample_rate(&self) -> u32
fn input_sample_rate(&self) -> u32
Source§fn output_sample_rate(&self) -> u32
fn output_sample_rate(&self) -> u32
Source§impl Clone for AudioHandler
impl Clone for AudioHandler
Source§fn clone(&self) -> AudioHandler
fn clone(&self) -> AudioHandler
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more