ao 0.6.1

Bindings to Xiph.org's libao

Crate ao [] [src]

Bindings to libao, a low-level library for audio output.

use ao::{AO, SampleFormat, Driver, Sample};
use ao::Endianness::Native;
use std::error::Error;
use std::num::Float;
use std::path::Path;

fn main() {
    let lib = AO::init();
    let format = SampleFormat::<i16, &'static str>::new(44100, 1, Native, None);
    let driver = match lib.get_driver("wav") {
        Some(d) => play_sinusoid(d, format),
        None => panic!("No such driver: \"wav\"")
    };
     
}

fn play_sinusoid<S: AsRef<str>>(driver: Driver, format: SampleFormat<i16, S>) {
    match driver.open_file(&format, &Path::new("out.wav"), false) {
        Ok(d) => {
            let samples: Vec<i16> = (0..44100).map(|i| {
                ((1.0 / 44100.0 / 440.0 * i as f32).sin() * 32767.0) as i16
            }).collect();
            d.play(&samples);
        }
        Err(e) => {
            println!("Failed to open output file: {}", e.description());
        }
    }
}

Modules

auto

Automatic device format adjustment.

Structs

AO

Library owner.

Device

An output device.

Driver

An output driver.

DriverInfo

Properties and metadata for a driver.

SampleFormat

Describes audio sample formats.

Enums

AoError

Result of (most) operations that may fail.

DriverType

The output type of a driver.

Endianness

Sample byte ordering.

Traits

Sample

Type bound for sample formats

Type Definitions

AoResult

Output for libao functions that may fail.