#aiff #audio-samples #codec #reader-writer #read-write #floating-point

aifc

Reader and writer for the AIFF and AIFF-C audio format

1 unstable release

0.5.3 Jul 30, 2024

#334 in Multimedia

MIT/Apache

200KB
3.5K SLoC

AIFC

Cross-platform tests

Rust library to read and write AIFF and AIFF-C (AIFC) audio format.

Features:

  • reading AIFF and AIFF-C
  • writing AIFF and AIFF-C
  • no heap memory allocations
  • no unsafe code
  • no panicking
  • supports uncompressed integer and floating point samples
  • supports compression types: μ-law, A-law and IMA ADPCM ("ima4")
  • supports audio files up to 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 AIFF/AIFF-C file:

let mut stream = std::io::BufReader::new(std::fs::File::open("test.aiff").expect("Open failed"));
let mut reader = aifc::AifcReader::new(&mut stream).expect("Can't create reader");
let info = reader.read_info().expect("Can't read header");
for sample in reader.samples().expect("Can't iterate samples") {
    println!("Got sample {:?}", sample.expect("Sample read error"));
}

Writing AIFF-C file with the default 2 channels, 16 bits/sample and sample rate 44100:

let mut stream = std::io::BufWriter::new(std::fs::File::create("test.aiff").expect("Open failed"));
let info = aifc::AifcWriteInfo::default();
let mut writer = aifc::AifcWriter::new(&mut stream, &info).expect("Can't create writer");
writer.write_samples_i16(&[ 1, 2, 3, 4 ]).expect("Can't write samples");
writer.finalize().expect("Can't finalize");

See the AIFC API documentation for details.

Examples

A simple AIFF player using aifc::AifcReader and tinyaudio:

cd examples/aifc-tinyaudio
cargo run filename.aiff

Testing

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

cd aifc
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