pub trait AudioBackend: Sized {
type Enumerator;
type Config: Default;
type StartStreamError: Error;
type StreamError: Error;
type Instant: Send + Clone;
// Required methods
fn enumerator() -> Self::Enumerator;
fn start_stream(
config: Self::Config,
) -> Result<(Self, StreamInfo), Self::StartStreamError>;
fn set_processor(&mut self, processor: FirewheelProcessor<Self>);
fn poll_status(&mut self) -> Result<(), Self::StreamError>;
fn delay_from_last_process(
&self,
process_timestamp: Self::Instant,
) -> Option<Duration>;
// Provided methods
fn input_devices_simple(&mut self) -> Vec<DeviceInfoSimple> { ... }
fn output_devices_simple(&mut self) -> Vec<DeviceInfoSimple> { ... }
fn convert_simple_config(
&mut self,
config: &SimpleStreamConfig,
) -> Self::Config { ... }
}Expand description
A trait describing an audio backend.
When an instance is dropped, then it must automatically stop its corresponding audio stream.
All methods in this trait are only ever invoked from the main
thread (the thread where the crate::context::FirewheelCtx
lives).
Required Associated Types§
Sourcetype Enumerator
type Enumerator
The type used to retrieve the list of available audio devices on the system and their available ocnfigurations.
Sourcetype StartStreamError: Error
type StartStreamError: Error
An error when starting a new audio stream.
Sourcetype StreamError: Error
type StreamError: Error
An error that has caused the audio stream to stop.
Required Methods§
Sourcefn enumerator() -> Self::Enumerator
fn enumerator() -> Self::Enumerator
Get a struct used to retrieve the list of available audio devices on the system and their available ocnfigurations.
Sourcefn start_stream(
config: Self::Config,
) -> Result<(Self, StreamInfo), Self::StartStreamError>
fn start_stream( config: Self::Config, ) -> Result<(Self, StreamInfo), Self::StartStreamError>
Start the audio stream with the given configuration, and return a handle for the audio stream.
Sourcefn set_processor(&mut self, processor: FirewheelProcessor<Self>)
fn set_processor(&mut self, processor: FirewheelProcessor<Self>)
Send the given processor to the audio thread for processing.
Sourcefn poll_status(&mut self) -> Result<(), Self::StreamError>
fn poll_status(&mut self) -> Result<(), Self::StreamError>
Poll the status of the running audio stream. Return an error if the audio stream has stopped for any reason.
Sourcefn delay_from_last_process(
&self,
process_timestamp: Self::Instant,
) -> Option<Duration>
fn delay_from_last_process( &self, process_timestamp: Self::Instant, ) -> Option<Duration>
Return the amount of time that has elapsed from the instant
FirewheelProcessor::process_interleaved was last called and now.
The given process_timestamp is the Self::Instant that was passed
to the latest call to FirewheelProcessor::process_interleaved.
This can be used to calculate the delay if needed.
If for any reason the delay could not be determined, return None.
Provided Methods§
Sourcefn input_devices_simple(&mut self) -> Vec<DeviceInfoSimple>
fn input_devices_simple(&mut self) -> Vec<DeviceInfoSimple>
Get a list of available input audio devices (for the default API).
The first item in the list is the default device.
Sourcefn output_devices_simple(&mut self) -> Vec<DeviceInfoSimple>
fn output_devices_simple(&mut self) -> Vec<DeviceInfoSimple>
Get a list of available output audio devices (for the default API).
The first item in the list is the default device.
Sourcefn convert_simple_config(&mut self, config: &SimpleStreamConfig) -> Self::Config
fn convert_simple_config(&mut self, config: &SimpleStreamConfig) -> Self::Config
Convert the easy-to-use, backend-agnostic audio stream configuration into the corresponding backend-specific configuration.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.