pub trait AudioDevice {
// Required methods
fn configure(
&mut self,
config: &AudioConfig,
) -> Result<AudioConfig, AudioError>;
fn start(&mut self) -> Result<(), AudioError>;
fn stop(&mut self) -> Result<(), AudioError>;
fn write_frames(&mut self, data: &[u8]) -> Result<usize, AudioError>;
fn read_frames(&mut self, output: &mut [u8]) -> Result<usize, AudioError>;
fn capabilities(&self) -> &AudioDeviceCapabilities;
fn name(&self) -> &str;
fn is_playback(&self) -> bool;
fn is_capture(&self) -> bool;
}Expand description
Unified audio device trait for playback and capture backends
Provides a common interface across ALSA PCM devices, VirtIO Sound streams, USB Audio Class devices, and any future audio backends. Implementations adapt existing backend-specific APIs to this shared contract.
Required Methods§
Sourcefn configure(&mut self, config: &AudioConfig) -> Result<AudioConfig, AudioError>
fn configure(&mut self, config: &AudioConfig) -> Result<AudioConfig, AudioError>
Configure the device with desired parameters.
The device may adjust parameters to the nearest supported values. Returns the actual configuration that was applied.
Sourcefn start(&mut self) -> Result<(), AudioError>
fn start(&mut self) -> Result<(), AudioError>
Start playback or capture.
Sourcefn stop(&mut self) -> Result<(), AudioError>
fn stop(&mut self) -> Result<(), AudioError>
Stop playback or capture.
Sourcefn write_frames(&mut self, data: &[u8]) -> Result<usize, AudioError>
fn write_frames(&mut self, data: &[u8]) -> Result<usize, AudioError>
Write PCM samples for playback.
Returns the number of frames written. The data must be interleaved samples in the format specified by the current configuration.
Sourcefn read_frames(&mut self, output: &mut [u8]) -> Result<usize, AudioError>
fn read_frames(&mut self, output: &mut [u8]) -> Result<usize, AudioError>
Read PCM samples from capture.
Returns the number of frames read. The output buffer is filled with interleaved samples in the format specified by the current configuration.
Sourcefn capabilities(&self) -> &AudioDeviceCapabilities
fn capabilities(&self) -> &AudioDeviceCapabilities
Query device capabilities.
Sourcefn is_playback(&self) -> bool
fn is_playback(&self) -> bool
Returns true if this device supports playback.
Sourcefn is_capture(&self) -> bool
fn is_capture(&self) -> bool
Returns true if this device supports capture.