Crate claxon [] [src]

Claxon, a FLAC decoding library.

Examples

The following example computes the root mean square (RMS) of a FLAC file.

let mut reader = claxon::FlacReader::open("testsamples/pop.flac").unwrap();
let mut sqr_sum = 0.0;
let mut count = 0;
for sample in reader.samples() {
    let s = sample.unwrap() as f64;
    sqr_sum += s * s;
    count += 1;
}
println!("RMS is {}", (sqr_sum / count as f64).sqrt());

A simple way to decode a file to wav with Claxon and Hound:

let mut reader = claxon::FlacReader::open(fname).expect("failed to open FLAC stream");

let spec = hound::WavSpec {
    channels: reader.streaminfo().channels as u16,
    sample_rate: reader.streaminfo().sample_rate,
    bits_per_sample: reader.streaminfo().bits_per_sample as u16,
    sample_format: hound::SampleFormat::Int,
};

let fname_wav = fname.with_extension("wav");
let opt_wav_writer = hound::WavWriter::create(fname_wav, spec);
let mut wav_writer = opt_wav_writer.expect("failed to create wav file");

for opt_sample in reader.samples() {
    let sample = opt_sample.expect("failed to decode FLAC stream");
    wav_writer.write_sample(sample).expect("failed to write wav file");
}

For more examples, see the examples directory in the crate.

Reexports

pub use frame::Block;

Modules

frame

The frame module deals with the frames that make up a FLAC stream.

metadata

The metadata module deals with metadata at the beginning of a FLAC stream.

subframe

The subframe module deals with subframes that make up a frame of the FLAC stream.

Structs

FlacReader

A FLAC decoder that can decode the stream from the underlying reader.

FlacSamples

An iterator that yields samples read from a FlacReader.

Enums

Error

An error that prevents succesful decoding of the FLAC stream.

Type Definitions

Result

A type for results generated by Claxon where the error type is hard-wired.