Skip to main content

smoke/
smoke.rs

1//! Decode a FLAC file and print its parameters.
2//!
3//! Usage: `cargo run --example smoke -- path/to/file.flac`
4//! With no argument it decodes the bundled stereo test fixture.
5
6fn main() {
7    let path = std::env::args()
8        .nth(1)
9        .unwrap_or_else(|| "tests/fixtures/stereo16.flac".to_string());
10
11    let bytes = match std::fs::read(&path) {
12        Ok(b) => b,
13        Err(e) => {
14            eprintln!("could not read {path}: {e}");
15            std::process::exit(1);
16        }
17    };
18
19    match flac_io::decode(&bytes) {
20        Ok(audio) => {
21            println!(
22                "{path}: {} Hz, {} channel(s), {} bit, {} samples/channel",
23                audio.sample_rate,
24                audio.channels,
25                audio.bits_per_sample,
26                audio.samples_per_channel()
27            );
28        }
29        Err(e) => {
30            eprintln!("decode failed: {e}");
31            std::process::exit(1);
32        }
33    }
34}