//! 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 --
[out.s16]
use wai::int_audio::{decode, pcm_fnv1a, AudioModel};
fn main() {
let dir = std::env::args().nth(1).expect("usage: int_audio_decode [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 = pcm.iter().flat_map(|s| s.to_le_bytes()).collect();
std::fs::write(out, bytes).unwrap();
}
}