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§
Sourcefn build_input_stream(&self, prod: HeapProd<f32>) -> Box<dyn PlayableStream>
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 rawf32audio samples.
Sourcefn build_output_stream(&self, cons: HeapCons<f32>) -> Box<dyn PlayableStream>
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 processedf32audio samples.
Sourcefn input_device(&self) -> &Device
fn input_device(&self) -> &Device
Returns a reference to the CPAL input device used by this handler.
Sourcefn output_device(&self) -> &Device
fn output_device(&self) -> &Device
Returns a reference to the CPAL output device used by this handler.
Sourcefn input_config(&self) -> &StreamConfig
fn input_config(&self) -> &StreamConfig
Returns the [StreamConfig] used for the input stream.
Sourcefn output_config(&self) -> &StreamConfig
fn output_config(&self) -> &StreamConfig
Returns the [StreamConfig] used for the output stream.
Sourcefn input_sample_rate(&self) -> u32
fn input_sample_rate(&self) -> u32
Returns the configured input sample rate in Hz.
Sourcefn output_sample_rate(&self) -> u32
fn output_sample_rate(&self) -> u32
Returns the configured output sample rate in Hz.
Implementors§
impl AudioHandlerTrait for AudioHandler
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.