#audio-samples #decoder #sound #encoding #file-format

bin+lib creak

Lightweight audio decoder. Converts popular formats to raw 32-bit float samples.

3 releases (breaking)

0.3.0 Dec 4, 2020
0.2.0 Oct 30, 2020
0.1.0 Oct 30, 2020
0.0.0 Oct 29, 2020

#647 in Audio

Download history 10/week @ 2024-06-08 17/week @ 2024-06-15 18/week @ 2024-06-22 3/week @ 2024-06-29 4/week @ 2024-07-06 37/week @ 2024-07-13 38/week @ 2024-07-20 24/week @ 2024-07-27 15/week @ 2024-08-03 14/week @ 2024-08-10 7/week @ 2024-08-17 8/week @ 2024-08-24 16/week @ 2024-08-31 16/week @ 2024-09-07 13/week @ 2024-09-14 32/week @ 2024-09-21

78 downloads per month
Used in 2 crates

MIT/Apache

40KB
757 lines

Creak

Crates.io

A barebones, opinionated Rust crate for decoding audio files into raw 32-bit float samples.

Supported formats

Format Feature flag Backend Status
WAV wav hound
Vorbis vorbis lewton
MP3 mp3 minimp3
FLAC flac claxon
Raw N/A built-in

(✅ = Implemented; 🛠 = WIP)

Building Creak with partial format support

Creak compiles with support for all formats by default, but this may not be desirable to everyone. To enable support for only specific formats, you'll need to manually specify the desired feature flags in your Cargo.toml like this:

[dependencies]

# Only include support for WAV and Vorbis
creak = { version = "*", default-features = false, features = ["wav", "vorbis"] }

Example

// Simple program that reads an audio file and dumps its samples in 32-bit float to stdout

use std::{env, io, io::Write};
use creak;

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Get a file name from the cmdline args
    let file_name = match env::args().nth(1) {
        Some(arg) => arg,
        None => {
            eprintln!("No audio file specified!");
            return Ok(())
        }
    };

    // Open an audio file of any supported format with one function call
    let decoder = creak::Decoder::open(&file_name)?;

    // Print basic audio info to stderr
    let info = decoder.info();
    eprintln!("Format: {}; Channels: {}; Sample Rate: {}Hz", 
        info.format(), 
        info.channels(), 
        info.sample_rate()
    );

    let mut stdout = io::stdout();
    let mut num_samples: usize = 0;

    // Dump all samples to stdout
    for sample in decoder.into_samples()? {
        stdout.write(&sample?.to_le_bytes())?;
        num_samples += 1;
    }

    eprintln!("{} samples(s) read.", num_samples);
    Ok(())
}

Limitations

Creak only outputs f32 samples (because they're good). If you don't want f32 samples, I'm afraid this isn't the crate for you!

Creak cannot handle certain types of audio data, namely:

  • MP3 files with variable sample rate or channel count will cause an error while decoding.
  • WAV files with "exotic" sample formats are not supported. I don't know who is using 64-bit float samples, but they're too powerful for poor Creak. Have mercy.

Changelog

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0–530KB