// wai-conformance: int-kernels //! `wai.audio.int_codec` — **sample-equivalence**: a LEARNED 1-D audio transform //! codec whose integer synthesis (transposed convs + IGDN) decodes a factorized //! rANS latent to int16 PCM byte-identically on every machine, so the PCM hash is //! portable — the audio analog of int_hyper. Committed tiny vector under //! `tests/vectors/int_audio/`; never skips. #![cfg(feature = "audio_int")] use std::path::PathBuf; use wai::int_audio::{decode, pcm_fnv1a, AudioModel}; fn dir() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("tests/vectors/int_audio") } #[test] fn decodes_the_learned_audio_clip_sample_for_sample() { // The committed integer model (WAM1) + factorized bitstream decode — no float, // no ML runtime — to the SAME int16 PCM the Python integer reference produced. // If the Rust 1-D conv / IGDN / rANS / PCM-quantization disagreed with the // exporter by a single sample, this FNV-1a would diverge. let model = AudioModel::from_bytes(&std::fs::read(dir().join("audio_model.bin")).unwrap()) .expect("parse WAM1 model"); let bs: serde_json::Value = serde_json::from_slice(&std::fs::read(dir().join("audio_bitstream.json")).unwrap()).unwrap(); let conf: serde_json::Value = serde_json::from_slice(&std::fs::read(dir().join("audio.json")).unwrap()).unwrap(); let pcm = decode(&model, &bs).expect("decode"); assert_eq!(pcm.len(), conf["n_samples"].as_u64().unwrap() as usize, "sample count"); let got = format!("{:016x}", pcm_fnv1a(&pcm)); assert_eq!(got, conf["pcm_fnv1a"].as_str().unwrap(), "PCM must reproduce its committed hash"); println!( "int_audio: {} samples @ {} Hz -> sample-exact, pcm_hash {got}", pcm.len(), conf["sample_rate"].as_u64().unwrap() ); }