8 releases (4 breaking)

Uses old Rust 2015

0.6.1 Apr 13, 2015
0.6.0 Apr 13, 2015
0.5.1 Mar 23, 2015
0.4.1 Jan 24, 2015
0.2.1 Nov 20, 2014

#799 in Audio

Download history 2/week @ 2023-10-22 19/week @ 2023-10-29 9/week @ 2023-11-05 13/week @ 2023-11-12 4/week @ 2023-11-19 26/week @ 2023-11-26 1/week @ 2023-12-03 9/week @ 2023-12-10 2/week @ 2023-12-17 20/week @ 2023-12-24 9/week @ 2023-12-31 2/week @ 2024-01-07 1/week @ 2024-01-14 13/week @ 2024-01-21 35/week @ 2024-01-28 2/week @ 2024-02-04

52 downloads per month
Used in pure_vorbis

BSD-2-Clause

195KB
793 lines

Rust-AO

libao bindings for Rust.

Usage

Build with cargo:

cargo build

Build documentation with rustdoc, rooted at doc/ao/index.html:

cargo doc

Run tests. Tests must not be run in parallel because libao may only be instantiated once in a given process. Running tests concurrently can cause race conditions on library initialization, causing spurious test failure:

REST_TEST_TASKS=1 cargo test

Examples are included in the documentation.


lib.rs:

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());
        }
    }
}

Dependencies