The audio analog of int_hyper — a LEARNED audio codec whose decode is byte-exact,
extending "conformance is a hash" to audio. A neural audio codec (SoundStream /
EnCodec family) decodes through a float network, so ~1e-5 round-off makes the
waveform — and its hash — diverge between machines: never receiptable. Here the
synthesis is a stack of integer 1-D transposed convolutions + integer IGDN over a
per-channel factorized-rANS latent, all i64, so the int16 PCM is byte-identical on
every machine (NeuralIntegerExact; sample-equivalence, a portable PCM hash).
- decoder: src/int_audio.rs — WAM1 model parse (int12 transposed-conv weights as
i16, IGDN gamma as i32), 1-D conv_t + integer IGDN (reuses int_transform::igdn)
over the factorized-rANS latent (y_q = s·2^afrac + median_q) → int16 PCM. Pure
i64, no float/ONNX; compiles to wasm32. Feature audio_int = ["neural_int"].
- encoder: tools/wai_int_audio_export.py — trains a small 1-D transform codec
(Conv1d+GDN / ConvTranspose1d+IGDN) on real captured audio (float; only the
DECODE must be integer), PTQs g_s, factorized-codes the latent (data-fit CDF +
CompressAI rANS, the byte-exact match of the Rust RansDecoder), and runs an
INTEGER reference decode mirroring the Rust arithmetic → PCM FNV-1a.
- capability: wai.audio.int_codec registered (Lossy tier, NeuralIntegerExact
replicate class; nie set now {int_synth, int_hyper, video.int_hyper, audio}).
- conformance: tests/vectors/int_audio/ (a tiny 8192-sample C=16 clip) +
int_audio.rs never-skips. The Rust 1-D conv / IGDN / rANS / PCM-quantization
reproduce the Python integer reference sample-for-sample.
- web: wai-web::decodeIntAudio (audio_int feature) — the same pure-i64 decode in
the browser; reuses fnv1aHex over the LE PCM bytes for the in-page receipt check.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
21 lines
1.1 KiB
Rust
21 lines
1.1 KiB
Rust
//! Decode a learned-audio bitstream dir (`audio_model.bin` + `audio_bitstream.json`,
|
|
//! from `tools/wai_int_audio_export.py`) → int16 PCM, print the sample count + the
|
|
//! FNV-1a PCM hash, and optionally dump the raw s16le. Proves the Rust integer
|
|
//! decode reproduces the Python integer reference byte-for-byte.
|
|
//!
|
|
//! cargo run --release --example int_audio_decode --features audio_int -- <dir> [out.s16]
|
|
|
|
use wai::int_audio::{decode, pcm_fnv1a, AudioModel};
|
|
|
|
fn main() {
|
|
let dir = std::env::args().nth(1).expect("usage: int_audio_decode <dir> [out.s16]");
|
|
let model = AudioModel::from_bytes(&std::fs::read(format!("{dir}/audio_model.bin")).unwrap()).unwrap();
|
|
let bs: serde_json::Value =
|
|
serde_json::from_slice(&std::fs::read(format!("{dir}/audio_bitstream.json")).unwrap()).unwrap();
|
|
let pcm = decode(&model, &bs).expect("decode");
|
|
println!("samples {} pcm_hash {:016x}", pcm.len(), pcm_fnv1a(&pcm));
|
|
if let Some(out) = std::env::args().nth(2) {
|
|
let bytes: Vec<u8> = pcm.iter().flat_map(|s| s.to_le_bytes()).collect();
|
|
std::fs::write(out, bytes).unwrap();
|
|
}
|
|
}
|