Crate aifc

source ·
Expand description

§AIFF and AIFF-C Audio Format Reader and Writer

This crate contains AifcReader and AifcWriter for Audio Interchange File Formats AIFF and AIFF-C. This crate supports uncompressed sample data, μ-law, A-law and IMA ADPCM (“ima4”) compressed sample data.

These audio formats are made of chunks, which contain header data (the COMM chunk), audio sample data (the SSND chunk) and other data, such as marker data (the MARK chunk).

§Examples

Reading samples:

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

Writing AIFF-C with the default 2 channels, sample rate 44100 and signed 16-bit integer samples:

let mut stream = std::io::BufWriter::new(std::fs::File::create("test.aiff")?);
let info = aifc::AifcWriteInfo::default();
let mut writer = aifc::AifcWriter::new(&mut stream, &info)?;
writer.write_samples_i16(&[ 0, 10, -10, 0 ])?;
writer.finalize()?;

§Text decoding

AIFF and AIFF-C originally support ASCII only text in their metadata chunks (NAME, ANNO, etc.). In addition to ASCII, older apps may have used ISO-8859-1 and newer apps may have used UTF-8.

A text decoder could try to decode UTF-8 first with String::from_utf8() and if it fails, try to decode ISO-8859-1, and if it fails, decode ASCII. Or it could just assume that everything is UTF-8 and call String::from_utf8_lossy().

When writing new files, the ID3 chunk has proper support for UTF-8 text and can be used as a replacement for most metadata chunks.

Structs§

Enums§

Constants§

Functions§

  • Checks if the given data is the start of AIFF or AIFF-C.

Type Aliases§

  • Library Result type.
  • A chunk id is a four byte identifier.
  • Marker id, which should be a positive number.