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 audio info and 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.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§

AifcReadInfo
Audio info returned by AifcReader.
AifcReader
AIFF / AIFF-C reader.
AifcWriteInfo
Audio info for AifcWriter.
AifcWriter
AIFF / AIFF-C writer.
ChunkRef
ChunkRef contains a chunk id, chunk start position and its size.
Chunks
Iterator to read chunks one by one.
Comment
Comment data.
Comments
Iterator to read comments from a slice of bytes.
Instrument
Instrument data.
Loop
Instrument loop values.
Marker
Marker data.
Markers
Iterator to read markers from a slice of bytes.
Samples
Iterator to read samples one by one.

Enums§

AifcError
Error values.
FileFormat
File format: AIFF or AIFF-C.
Sample
Sample data.
SampleFormat
Sample format.

Constants§

CHUNKID_AESD
The audio recording “AESD” chunk id.
CHUNKID_ANNO
The annotation “ANNO” chunk id. A stream may contain multiple ANNO chunks.
CHUNKID_APPL
The application specific “APPL” chunk id. A stream may contain multiple APPL chunks.
CHUNKID_AUTH
The author “AUTH” chunk id.
CHUNKID_COMM
The common (header) “COMM” chunk id.
CHUNKID_COMT
The comments “COMT” chunk id.
CHUNKID_COPY
The copyright “(c) “ chunk id.
CHUNKID_FVER
The format version “FVER” chunk id.
CHUNKID_ID3
The ID3 “ID3 “ data chunk id.
CHUNKID_INST
The instrument “INST” chunk id.
CHUNKID_MARK
The marker “MARK” chunk id.
CHUNKID_MIDI
The MIDI “MIDI” data chunk id. A stream may contain multiple MIDI chunks.
CHUNKID_NAME
The name “NAME” chunk id.
CHUNKID_SSND
The sound data “SSND” chunk id.

Functions§

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

Type Aliases§

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