2 releases

0.5.1 Apr 26, 2024
0.5.0 Apr 16, 2024

#94 in Audio

Download history 121/week @ 2024-04-14 112/week @ 2024-04-21 19/week @ 2024-04-28

252 downloads per month

MIT/Apache

120KB
2K SLoC

Ausnd

Cross-platform tests

Rust library to read and write Sun/Next AU audio format. Features:

  • read AU files
  • write AU files
  • reading infinite AU streams
  • no heap memory allocations
  • no unsafe code
  • no panicking
  • supports uncompressed integer and floating point samples
  • supports compression types: μ-law and A-law
  • supports audio streams larger than 4 gigabytes

Out of scope:

  • conversion between different sample formats (e.g., i16 to f32). There's so many ways to do the conversion that it's better that this crate doesn't do it.

Usage

Reading an AU audio file:

let mut bufrd = std::io::BufReader::new(std::fs::File::open("test.au").expect("File error"));
let mut reader = ausnd::AuReader::new(&mut bufrd).expect("Read error");
let info = reader.read_info().expect("Invalid header");
for sample in reader.samples().expect("Can't read samples") {
    println!("Got sample {:?}", sample.expect("Sample error"));
}

Writing an AU audio file (with the default 2 channels, 16-bit signed integer samples, sample rate 44100):

let mut bufwr = std::io::BufWriter::new(std::fs::File::create("test.au").expect("File error"));
let winfo = ausnd::AuWriteInfo::default();
let mut writer = ausnd::AuWriter::new(&mut bufwr, &winfo).expect("Write header error");
writer.write_samples_i16(&[ 1, 2, 3, 4 ]).expect("Write sample error");
writer.finalize().expect("Finalize error");

See the ausnd API documentation for details.

Examples

A simple AU player using ausnd::AuReader and tinyaudio:

cd examples/ausnd-tinyaudio
cargo run filename.au

A simple audio processor for volume and noise effects using AuStreamParser and AuWriter:

cargo run --example ausnd-piper v0.8 n0.1 < input.au > out.au

The same audio processor piped from/to ffmpeg. ffmpeg converts mp3 to AU for ausnd-piper, which writes AU for ffmpeg to convert it to mp3.

ffmpeg -i music.mp3 -f au - | cargo run --example ausnd-piper v1.5 n0.2 | ffmpeg -i - -y out.mp3

Testing

Toisto AU Test Suite is a submodule and needs to be fetched before running the integration tests.

cd ausnd
git submodule update --init
./tools/test.sh

The test should end with --- All tests OK..

Performance testing:

cargo bench

There is a GitHub Action called "Cross-platform tests" (cross-test.yml), which automatically runs ./tools/test.sh for little-endian 64-bit x64_86 and big-endian 32-bit PowerPC.

References

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies