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 StereoBuffer(Vec<(i16, i16)>);
 
impl<'z> SampleBuffer for StereoBuffer {
    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::slice::from_raw_parts(self.0.as_ptr() as *const u8,
                                       self.0.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 = StereoBuffer(vec![(16383, -16383)]);
    match device.play(&data) {
        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.