Module ao::auto
[-]
[+]
[src]
Automatic device format adjustment.
Given a way to poll the properties of an incoming buffer of samples, this module provides a way
to automatically adjust the output SampleFormat
so all data being fed to the output need not
have the same format. This is particularly useful for situations where non-homogenous inputs
can be switched to the same output, without requiring resampling prior to output.
use ao::AO; use ao::auto::{SampleBuffer, AutoFormatDevice}; use std::error::Error; struct Stereo(u16, u16); impl<'z> SampleBuffer for &'z [Stereo] { fn channels(&self) -> usize { 2 } fn sample_rate(&self) -> usize { 44100 } fn endianness(&self) -> ao::Endianness { ao::Endianness::Native } fn sample_width(&self) -> usize { 16 } fn data<'a>(&self) -> &'a [u8] { unsafe { ::std::mem::transmute(::std::raw::Slice { data: self.as_ptr() as *const u8, len: self.len() * 4 }) } } } fn main() { let lib = AO::init(); let driver = lib.get_driver("").expect("No default driver available"); let mut device = AutoFormatDevice::new(driver, vec!["", "L", "L,R"]); let data = vec![Stereo(16383, -16383)]; match device.play(&data.as_slice()) { Ok(_) => (), Err(e) => println!("Playback failed: {}", e.description()) } }
Structs
AutoFormatDevice | Automatically adjusts the output format according to incoming buffers. |
Traits
SampleBuffer | A buffer containing samples. |