Crate ao[stability] [-]  [+] [src]

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

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

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) => d,
        None => panic!("No such driver: \"wav\"")
    };
     
    match driver.open_file(&format, Path::new("out.wav"), false) {
        Ok(d) => {
            let samples: Vec<i16> = range(0, 44100).map(|i| {
                ((1.0 / 44100.0 / 440.0 * i as f32).sin() * 32767.0) as i16
            }).collect();
            d.play(samples.as_slice());
        }
        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.