Skip to main content

AudioHandlerTrait

Trait AudioHandlerTrait 

Source
pub trait AudioHandlerTrait: Send + Sync {
    // Required methods
    fn build_input_stream(&self, prod: HeapProd<f32>) -> Box<dyn PlayableStream>;
    fn build_output_stream(
        &self,
        cons: HeapCons<f32>,
    ) -> Box<dyn PlayableStream>;
    fn input_device(&self) -> &Device;
    fn output_device(&self) -> &Device;
    fn input_config(&self) -> &StreamConfig;
    fn output_config(&self) -> &StreamConfig;
    fn input_sample_rate(&self) -> u32;
    fn output_sample_rate(&self) -> u32;
}
Expand description

Abstraction over the audio I/O handler used by AudioService.

Using the MockAudioHandlerTrait generated by mockall allows the audio pipeline to be tested without real hardware.

Required Methods§

Source

fn build_input_stream(&self, prod: HeapProd<f32>) -> Box<dyn PlayableStream>

Builds and returns a started-ready input stream that pushes captured samples into prod (producer).

§Arguments
  • prod - The ring-buffer producer that receives raw f32 audio samples.
Source

fn build_output_stream(&self, cons: HeapCons<f32>) -> Box<dyn PlayableStream>

Builds and returns a started-ready output stream that drains samples from cons (consumer) and sends them to the output device.

Slots in the output buffer that have no corresponding sample are filled with silence (0.0).

§Arguments
  • cons - The ring-buffer consumer that supplies processed f32 audio samples.
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.

Implementors§

Source§

impl AudioHandlerTrait for AudioHandler

Source§

impl AudioHandlerTrait for MockAudioHandlerTrait

Abstraction over the audio I/O handler used by AudioService.

Using the MockAudioHandlerTrait generated by mockall allows the audio pipeline to be tested without real hardware.