Skip to main content

Crate flac_io

Crate flac_io 

Source
Expand description

A pure-Rust FLAC decoder and encoder with no unsafe code and no C dependency.

FLAC (Free Lossless Audio Codec) stores audio so that decoding returns the exact original samples, bit for bit. This crate reads a FLAC byte stream into its raw integer samples and writes raw samples back into a valid FLAC stream, without any lossy intermediate.

It exists for steganography, watermarking, forensic analysis, and any audio work that needs the decoded sample plane with a guarantee that a decode followed by an encode preserves the data exactly.

§Quick start

use flac_io::{decode, encode};

let bytes = std::fs::read("song.flac").unwrap();
let audio = decode(&bytes).unwrap();
println!("{} Hz, {} ch, {} bit", audio.sample_rate, audio.channels, audio.bits_per_sample);

let out = encode(&audio).unwrap();
std::fs::write("song_reencoded.flac", out).unwrap();

§Sample layout

FlacAudio::samples holds one inner vector per channel, each the same length (the number of samples per channel). Samples are signed integers in the stream’s native bit depth, sign-extended into i32. For stereo, index 0 is the left channel and index 1 is the right.

Structs§

FlacAudio
Decoded FLAC audio: the stream parameters plus the samples, one vector per channel.
StreamInfo
The contents of the STREAMINFO metadata block.

Enums§

FlacError
Errors returned when decoding or encoding a FLAC stream.

Functions§

decode
Decode a FLAC byte stream into its samples and parameters.
encode
Encode samples into a valid native FLAC byte stream (the .flac form).
encode_ogg
Encode samples into a FLAC stream wrapped in the Ogg container (the .oga form).
info
Read just the stream metadata (sample rate, channels, bit depth, total samples, MD5) without decoding any audio.