- Rust 100%
| Filename | Latest commit message | Latest commit date |
|---|---|---|
Add examples/turbo_sweep.rs, a reproducible corpus harness that runs every registered filter against every residual profile plus a classic four-bit VADPCM baseline and measures SNR, segmental SNR, worst-decile segmental SNR, log-spectral distance, high-band SNR, quiet-passage error, clipping, rate, residual distributions, and predictor usage in the original PCM domain, with quantizer-independent round-trip, delay, short-input, and synthesis-cost diagnostics alongside. Measured over eleven 44.1 kHz music sources, select L53R as the version 1 filter and L4H3 as the version 1 residual allocation, and record both decisions with their evidence in the design notes. HAAR stays supported as the cheapest bank, L97F supported but experimental, and D6QF is rejected. All four profiles stay supported, so no profile ID, FourCC, or macroframe size changes. Expose both codecs on the command line. encode and bulk gain --codec classic|turbo plus Turbo-only --filter, --profile, --high-predictors, --high-assignment, and --high-dither; supplying a Turbo-only flag under --codec classic is an argument error. Decoding dispatches on the container's own compression type and reads the filter and profile from the file, with no decode-side override. Listening criteria remain open for TASK-13.9 and TASK-13.10, and the corpus is music only. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_012EhxTfkM5X6ubzBDb3oSat |
||
| backlog | ||
| docs | ||
| examples | ||
| src | ||
| tests | ||
| .gitignore | ||
| AGENTS.md | ||
| Cargo.lock | ||
| Cargo.toml | ||
| CLAUDE.md | ||
| README.md | ||
VADPCM Turbo
VADPCM Turbo is an experimental audio-codec project based on the order-2 VADPCM codec used by Nintendo 64 games. The repository currently contains a Rust implementation of the raw VADPCM encoder, decoder, predictor trainer, the proposed Turbo macroframe packing, and four two-band filter-bank candidates: Haar, reversible Le Gall 5/3, fixed-point CDF 9/7, and fixed-point 12-tap Daubechies D6 QMF, plus the versioned Turbo AIFF-C container layer and an end-to-end Turbo file encoder and decoder reachable from the command line.
The byte layout that exists today and the remaining codec proposal are documented separately in the codec design notes.
Build and test
The project uses the stable Rust toolchain and Cargo:
cargo build
cargo test
RUSTDOCFLAGS="-D warnings" cargo doc --no-deps
The last command builds the library API documentation and treats broken links and other rustdoc warnings as errors.
Command-line program
The command-line program encodes and decodes classic Nintendo VADPCM and the experimental two-band Turbo codec, both in an AIFF-C container. Encode an audio file with:
cargo run -- encode --input path/to/audio.wav --output path/to/audio.aifc
The output uses the established VAPC compression ID, stock nine-byte VADPCM
frames, and an embedded VADPCMCODES predictor codebook. The input's valid
sample count is preserved in the AIFF-C common chunk; up to fifteen zero
samples are added internally to complete the final codec frame. On success,
the program prints the sample rate, frame and padding counts, predictor count,
output size, and destination. Failures print an error and return a nonzero
status. The input and output paths must differ.
The enabled input formats are FLAC and PCM audio in WAV, AIFF, or CAF containers. Mono input is preserved; stereo input with front-left and front-right channels is averaged to mono. Other channel layouts, missing channel or sample-rate metadata, and sample-rate changes within a stream are rejected. Containers with zero tracks, no audio track, or multiple tracks are rejected before decoding; the encoder accepts exactly one supported audio track.
Use vadpcm-turbo --help to see the available workflows and
vadpcm-turbo encode --help for encoding options. --predictors selects a
codebook size from 1 through 16, --assignment chooses the codebook-training
search, and --dither chooses residual quantization behavior. The former bare
encoding invocation is no longer accepted; use the encode subcommand.
Turbo encoding
--codec turbo encodes the two-band Turbo format instead. Its output is not
valid VAPC data and no stock N64 VADPCM decoder can read it; the Turbo
container uses the VPTC identifier and versioned metadata.
cargo run -- encode --codec turbo --filter l53r --profile l4h3 \
--input path/to/audio.wav --output path/to/audio.turbo.aifc
--filter selects the subband filter bank: haar, l53r (the default),
l97f, or d6qf. --profile selects the residual bit allocation and so the
bitrate: l4h2 at 3.5, l4h3 (the default) and l5h2 at 4.0, and l5h3 at
4.5 bits per PCM sample, against 4.5 for classic VADPCM. --predictors,
--assignment, and --dither apply to the low band; --high-predictors,
--high-assignment, and --high-dither control the high band independently.
All six flags are rejected with an argument error under --codec classic.
Turbo adds no algorithmic delay: every filter bank is stateless and codes each
32-sample block independently.
The l53r filter and the l4h3 profile are the measured version 1 defaults;
l97f and d6qf are experimental. The measurements behind those choices, and
the harness that reproduces them, are in
the codec design notes.
Decoding
Decode a VAPC or Turbo AIFF-C file to 16-bit mono PCM by selecting the output
container explicitly with --format:
cargo run -- decode --input path/to/audio.aifc --output path/to/audio.wav --format wav
cargo run -- decode --input path/to/audio.aifc --output path/to/audio.aiff --format aiff
Decoding is self-describing: the codec is chosen from the file's compression
type, and a Turbo file's filter and residual profile come from its own
metadata. There is deliberately no decode-side --codec, --filter, or
--profile flag to contradict them. The decoder preserves the encoded sample
rate and valid sample count, dropping any zero padding from the final frame.
Malformed containers and input/output path collisions are rejected before an
output file is written.
Bulk evaluation
Evaluate a collection of source files with the bulk command. Sources can be
given as positional paths, one per line in --input-list, or both:
cargo run -- bulk path/to/one.wav path/to/two.wav --input-list sources.txt
Bulk evaluation always encodes and decodes every source. It writes no files by
default; request inspection artifacts explicitly with --save-encoded and/or
--save-decoded. Decoded artifacts use WAV by default and can be written as
AIFF with --format aiff:
cargo run -- bulk --input-list sources.txt --save-encoded --save-decoded \
--format wav --output-dir ./bulk-artifacts --csv ./bulk-snr.csv
Bulk accepts the same encoding options as encode, so --codec turbo with any
filter, profile, and per-band controls can be evaluated the same way.
Without --output-dir, encoded files are named <source>.vapc.aifc, or
<source>.turbo.aifc under --codec turbo, and decoded files <source>.decoded.wav or <source>.decoded.aiff beside each
source. With an output directory, these deterministic names are flattened
directly into that directory. Existing files and flattened-name collisions are
reported as errors rather than overwritten; relative paths in a list are
resolved from the current working directory. --csv report.csv adds the stable
source,snr_db header and one row for each successfully evaluated source. SNR
uses 10 * log10(sum(original squared) / sum(error squared)) over the valid,
unpadded samples. Exact reconstruction, including silence reconstructed as
silence, is written as inf; a zero-energy source with nonzero error is
written as -inf. Failed inputs are omitted from the report.
Library usage
The library works with signed 16-bit PCM in complete 16-sample frames. This
example trains a codebook, encodes raw frames, and decodes them again. It is
also available as a runnable example with cargo run --example readme.
use vadpcm_turbo::codec::{
CodecConfig, DecoderState, FRAME_SAMPLE_COUNT, decode_frames, encode_raw,
};
fn main() -> Result<(), Box<dyn std::error::Error>> {
let samples = [0_i16; FRAME_SAMPLE_COUNT * 2];
let encoded = encode_raw(&samples, &CodecConfig::default())?;
let mut decoded = vec![0_i16; samples.len()];
let mut decoder_state = DecoderState::new();
decode_frames(
&encoded.frames,
&encoded.codebook,
&mut decoder_state,
&mut decoded,
)?;
assert_eq!(decoded.len(), samples.len());
Ok(())
}
codec::analysis and codec::assignment expose the lower-level predictor
training operations. bitstream packs and unpacks one low/high pair of raw
frames using a selected residual-width profile. filter exposes the common
32-to-16+16 analysis/synthesis contract through the closed registered
HAAR, L53R, L97F, and D6QF set and the evaluation harness. FilterBank
is sealed because a third-party bank cannot be selected by TurboConfig or
serialized into a Turbo stream. AnalysisStream::push retains complete blocks,
and finish returns them together with the one canonical valid-sample count;
callers remain responsible for asset headers, codebooks, and end-to-end stream
framing.