Skip to main content

Crate rockbox_codecs

Crate rockbox_codecs 

Source
Expand description

Audio decoding with Rockbox’s codecs as a reusable library.

The actual decoders are the Rockbox firmware codecs (lib/rbcodec/codecs/ plus their vendored decoder libraries — libmad, libtremor, libffmpegFLAC, libfaad, …), compiled by build.rs and driven through Rockbox’s codec_api by a small C shim modeled on the upstream warble test player.

let mut dec = rockbox_codecs::Decoder::open("song.flac").unwrap();
println!("{} — {}", dec.metadata().artist, dec.metadata().title);
while let Some(chunk) = dec.next_chunk() {
    // chunk.pcm: interleaved stereo i16 at chunk.sample_rate Hz
}

All 29 codecs of Rockbox’s static-link set are feature-gated (flac, mpa, vorbis, alac, aac, opus, wma, ape, …) so you only compile the decoders you need.

§Concurrency

Rockbox codecs share one global codec_api instance, so one decode session runs at a time: Decoder::open blocks until any other live Decoder is dropped. Within a session, decoding runs on a dedicated thread and PCM is pulled through a bounded channel.

Structs§

Chunk
One buffer of decoded audio: interleaved stereo i16 frames.
DecodedBuffer
A fully-decoded audio buffer: interleaved-stereo i16 PCM plus its rate.
Decoder
A running decode session for one audio file.
Metadata
Parsed metadata for one audio file.

Enums§

Error
Errors returned by Decoder::open.

Traits§

SeekableSource
A seekable byte source for a streaming decode session (e.g. an HTTP file buffered on demand via range requests).

Functions§

decode_bytes_sync
Decode a self-contained encoded packet held in memory to PCM, fully synchronously on the calling thread (no codec thread, no file). Like decode_file_sync but the source is a byte buffer read through an in-memory cursor; format_ext names the container/codec ("mp3", "aac", "ogg", …) since there’s no filename to sniff. Ideal for decoding a live stream chunk-by-chunk in a host that just wants “bytes in, PCM out”.
decode_file_sync
Decode a whole self-contained audio file synchronously on the calling thread — unlike Decoder, no codec thread is spawned and nothing blocks on a channel. That makes it safe to call from a context where spawning/joining a thread or a blocking recv is unreliable (an Emscripten module’s main thread). Returns all the PCM at once, so prefer Decoder for large files where you want it incrementally.