Skip to main content

AudioHandler

Struct AudioHandler 

Source
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.

Source

pub fn input_device(&self) -> &Device

Get field input_device from instance of AudioHandler.

Source

pub fn output_device(&self) -> &Device

Get field output_device from instance of AudioHandler.

Source

pub fn input_config(&self) -> &StreamConfig

Get field input_config from instance of AudioHandler.

Source

pub fn output_config(&self) -> &StreamConfig

Get field output_config from instance of AudioHandler.

Source

pub fn input_sample_rate(&self) -> &u32

Get field input_sample_rate from instance of AudioHandler.

Source

pub fn output_sample_rate(&self) -> &u32

Get field output_sample_rate from instance of AudioHandler.

Source§

impl AudioHandler

Source

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.
Source

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 of f32 samples the ring buffer can hold.
Source

pub fn set_output_device(&mut self, output_device: Device)

Replaces the current output device.

§Arguments
  • output_device - The new CPAL output device.
Source

pub fn set_input_device(&mut self, input_device: Device)

Replaces the current input device.

§Arguments
  • input_device - The new CPAL input device.

Trait Implementations§

Source§

impl AudioHandlerTrait for AudioHandler

Source§

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>

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

Returns a reference to the CPAL input device used by this handler.
Source§

fn output_device(&self) -> &Device

Returns a reference to the CPAL output device used by this handler.
Source§

fn input_config(&self) -> &StreamConfig

Returns the [StreamConfig] used for the input stream.
Source§

fn output_config(&self) -> &StreamConfig

Returns the [StreamConfig] used for the output stream.
Source§

fn input_sample_rate(&self) -> u32

Returns the configured input sample rate in Hz.
Source§

fn output_sample_rate(&self) -> u32

Returns the configured output sample rate in Hz.
Source§

impl Clone for AudioHandler

Source§

fn clone(&self) -> AudioHandler

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Any for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

§

fn type_name(&self) -> &'static str

§

impl<T> AnySync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Sync + Send>

Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,