code wiki / _hdl_build / nx_bioacoustic_bench.nx

nx_bioacoustic_bench.nx

buildroot/runtime/_hdl_build/nx_bioacoustic_bench.nx

42012 B935 linesdepth 3pulls 4 transitivereach 1 importersview sourcekind bench
docsdependenciesstructsconstsfunctions

about

nx_bioacoustic_bench.nx -- THE RULER for ANIMAL-VOCALISATION REALISM. Operator 2026-07-25: "get nishi audio state of the art so we can generate animal sounds and a dog toy ball that makes the noise when compressed by a dog's mouth". Rung R0. BEFORE any synthesis claim we need a MEASURED NUMBER, because the only animal-sound organ that exists today (nx_audio_bark.nx) says in its own header "First-iteration timbre -- tune by ear". Tuned by ear is not a measurement, and a lane with no ruler cannot honestly say SOTA. This organ is that ruler. WHY THESE AXES. A dog ignores TV animal sound because the signal fails on several acoustic axes at once. Each axis below is one of those failure modes turned into a number that a real recording passes and a synthetic/looped/broadcast one fails: AX_BAND container bandwidth vs the DOG hearing band (dogs hear to ~60 kHz; 48 kHz media carries 24 kHz -- so a 48k file is PHYSICALLY INCAPABLE of >24 kHz no matter how good the synth). AX_ULTRA fraction of energy above 20 kHz -- content a human cannot hear and a dog can. AX_F0DYN pitch-contour movement (stddev of F0). Real calls sweep; a beep does not. AX_HNR harmonic-to-noise proxy (normalised autocorrelation peak). AX_NONLIN NONLINEAR PHENOMENA -- subharmonics, biphonation, deterministic chaos. This is the hallmark of real mammalian/avian vocal production (the source self-oscillates and jumps between regimes) and it is exactly what sample playback and hand-tuned oscillator banks do not reproduce. Highest weight. AX_NONREP non-repetition across successive segments. A looped sample cross-correlates ~1.0 with itself; a real animal never repeats exactly. This is the HABITUATION axis. AX_ATTACK envelope attack sharpness (transient realism). AX_CREST crest factor = peak/RMS. Broadcast compression crushes this. AX_RESON count of resonances (vocal-tract poles) in the long-term average spectrum. AX_FLUX spectral micro-dynamics frame to frame. A static tone has none. HONESTY DISCIPLINE. Every axis is reference-free and INTRINSIC -- it is a property of the signal itself, so no reference corpus is needed to run it and no axis can be satisfied by simply copying a reference. The ruler is only trustworthy if it REFUSES bad input, so nx_bioacoustic_bench_gate feeds it negative controls (pure sine, white noise, an exactly-looped sample, a band-limited 48k signal) and asserts each one scores LOW on the axes it should fail. A ruler that passes everything is a rubber stamp, not an instrument. See [[feedback-cynical-instruments-author-optimism-is-a-bug]]. ANTI-GAMING NOTE ON AX_NONLIN. "Loud but aperiodic" alone is NOT evidence of nonlinear vocal production -- white noise is loud and aperiodic. Real nonlinear phenomena are REGIME TRANSITIONS, so a chaotic frame only counts when the same utterance also contains periodic frames. White noise has no periodic frames, so it scores 0 here. That is the biology, and it is what makes the axis honest.

dependencies 3 imports · 1 importers

nx_syscalls.nx nx_audio_osc.nx nx_isqrt.nx nx_bioacoustic_bench.nx nx_squeaker_design.nx

imports: nx_syscalls.nxnx_audio_osc.nxnx_isqrt.nx

imported by: nx_squeaker_design.nx

call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown

main sys_mmap bb_cfg_load bb_cfg_defaults bb_load_ints sys_mmap ↻ sys_read_file sys_openat_rd sys_lseek sys_mmap ↻ sys_read sys_close bb_w sys_write bb_n sys_mmap ↻ sys_write ↻ bb_measure_file sys_mmap ↻ sys_read_file ↻ bb_wav_parse bb_tag4 bb_rd_u32 bb_rd_u16 bb_wav_decode bb_rd_u16 ↻ bb_analyze bb_axis sys_mmap ↻ bb_iabs nx_isqrt bb_bands bb_goertzel osc_sin_unit osc_sin_s osc_qm osc_cos_s osc_qm ↻ bb_acorr nx_isqrt ↻

structs

none

consts

55const BB_MAGIC_8000: i64 = 8000
56const BB_MAGIC_20000: i64 = 20000
57const BB_MAGIC_60000: i64 = 60000
58const BB_MAGIC_65536: i64 = 65536
59const BB_MAGIC_16777216: i64 = 16777216
60const BB_MAGIC_32768: i64 = 32768
61const BB_MAGIC_8388608: i64 = 8388608
62const BB_MAGIC_1024: i64 = 1024
63const BB_MAGIC_4096: i64 = 4096
64const BB_MAGIC_8192: i64 = 8192
65const BB_MAGIC_2000: i64 = 2000
66const BB_MAGIC_3000: i64 = 3000
69const BB_R_RATE: i64 = 0
70const BB_R_NSAMP: i64 = 1
71const BB_R_NCH: i64 = 2
72const BB_R_BITS: i64 = 3
73const BB_R_AX_BAND: i64 = 4
74const BB_R_AX_ULTRA: i64 = 5
75const BB_R_AX_F0DYN: i64 = 6
76const BB_R_AX_HNR: i64 = 7
77const BB_R_AX_NONLIN: i64 = 8
78const BB_R_AX_NONREP: i64 = 9
79const BB_R_AX_ATTACK: i64 = 10
80const BB_R_AX_CREST: i64 = 11
81const BB_R_AX_RESON: i64 = 12
82const BB_R_AX_FLUX: i64 = 13
83const BB_R_AX_VOCAL: i64 = 14
84const BB_R_SCORE: i64 = 15
85const BB_R_F0_MEAN: i64 = 16
86const BB_R_F0_SD: i64 = 17
87const BB_R_VOICED: i64 = 18
88const BB_R_FRAMES: i64 = 19
89const BB_R_ULTRAFRAC: i64 = 20
90const BB_R_CRESTX100: i64 = 21
91const BB_R_NRESON: i64 = 22
92const BB_R_XCORR: i64 = 23
93const BB_R_NL_SUBH: i64 = 24
94const BB_R_NL_BIPH: i64 = 25
95const BB_R_NL_CHAOS: i64 = 26
96const BB_R_NL_PERIOD: i64 = 27
97const BB_R_N: i64 = 28
100const BB_C_F0_MIN: i64 = 0 // Hz lowest tracked fundamental
101const BB_C_F0_MAX: i64 = 1 // Hz highest tracked fundamental (mouse squeak fundamentals reach 8k)
102const BB_C_VOICE_FLOOR: i64 = 2 // per-mille of peak frame energy above which a frame is "sounding"
103const BB_C_F0SD_REF: i64 = 3 // Hz F0 stddev that scores 1000
104const BB_C_SUBH_LO: i64 = 4 // per-mille min correlation at P/2 to call it a subharmonic
105const BB_C_SUBH_HI: i64 = 5 // per-mille max correlation at P/2 before it is just the true period
106const BB_C_CHAOS_R: i64 = 6 // per-mille peak correlation below this = aperiodic regime
107const BB_C_BIPH_R: i64 = 7 // per-mille min correlation for a second incommensurate peak
108const BB_C_ULTRA_HZ: i64 = 8 // Hz boundary of the "human cannot hear, dog can" band
109const BB_C_DOG_HZ: i64 = 9 // Hz upper edge of canine hearing -- the bandwidth target
110const BB_C_ULTRA_REF: i64 = 10 // per-mille energy above ULTRA_HZ that scores 1000
111const BB_C_ATTACK_REF: i64 = 11 // per-mille envelope rise per frame that scores 1000
112const BB_C_CREST_FLOOR: i64 = 12 // crest x100 at which the axis starts scoring
113const BB_C_CREST_REF: i64 = 13 // crest x100 that scores 1000
114const BB_C_RESON_REF: i64 = 14 // resonance count that scores 1000
115const BB_C_FLUX_REF: i64 = 15 // per-mille spectral flux that scores 1000
116const BB_C_PROM: i64 = 16 // per-mille of spectral max a peak must clear to count as a resonance
117const BB_C_NSEG: i64 = 17 // segments compared for the non-repetition axis
118const BB_C_W_BAND: i64 = 18
119const BB_C_W_ULTRA: i64 = 19
120const BB_C_W_F0DYN: i64 = 20
121const BB_C_W_HNR: i64 = 21
122const BB_C_W_NONLIN: i64 = 22
123const BB_C_W_NONREP: i64 = 23
124const BB_C_W_ATTACK: i64 = 24
125const BB_C_W_CREST: i64 = 25
126const BB_C_W_RESON: i64 = 26
127const BB_C_W_FLUX: i64 = 27
128const BB_C_W_VOCAL: i64 = 28
129const BB_C_N: i64 = 29
131const BB_MAXBAND: i64 = 64
132const BB_BANDRATIO: i64 = 77936 // 2^(1/4) in Q16 -- quarter-octave band bank
133const BB_BAND_LO: i64 = 50 // Hz, lowest band centre (dog hearing floor is ~40 Hz)
134const BB_Q: i64 = 65536
454const BB_MAXFRAME: i64 = 512
455const BB_ADJ: i64 = 2 // frames either side that count as "the same utterance" for regime switching
459const BB_REG_SILENT: i64 = 0
460const BB_REG_PERIOD: i64 = 1
461const BB_REG_SUBH: i64 = 2
462const BB_REG_BIPH: i64 = 3
463const BB_REG_CHAOS: i64 = 4

functions

137func bb_w(s: *u8) -> i64 { var n: i64 = 0; while s[n] != (0 as u8) { n = n + 1 } sys_write(1, s, n); return 0 }
138func bb_n(v: i64) -> i64
152func bb_kvpair(k: *u8, v: i64) -> i64 { bb_w(k); bb_n(v); bb_w(" " as *u8); return 0 }
called by 1: bb_report calls 2: bb_wbb_n
153func bb_iabs(v: i64) -> i64 { if v < 0 { return 0 - v } return v }
154func bb_min(a: i64, b: i64) -> i64 { if a < b { return a } return b }
155func bb_max(a: i64, b: i64) -> i64 { if a > b { return a } return b }
157func bb_axis(num: i64, ref: i64) -> i64
called by 1: bb_analyze
168func bb_cfg_defaults(c: *i64) -> i64
called by 1: bb_cfg_load
208func bb_load_ints(dst: *i64, cap: i64, path: *u8) -> i64
called by 1: bb_cfg_load calls 2: sys_mmapsys_read_file
236func bb_cfg_load(c: *i64, path: *u8) -> i64
called by 1: main calls 2: bb_cfg_defaultsbb_load_ints
246func bb_rd_u16(b: *u8, o: i64) -> i64 { return (b[o] & 0xff) + ((b[o+1] & 0xff) * 256) }
247func bb_rd_u32(b: *u8, o: i64) -> i64
called by 1: bb_wav_parse
254func bb_tag4(b: *u8, o: i64, a: i64, c2: i64, c3: i64, c4: i64) -> i64
called by 1: bb_wav_parse
261func bb_wav_parse(buf: *u8, flen: i64, meta: *i64) -> i64
299func bb_wav_decode(buf: *u8, meta: *i64, out: *i64, cap: i64) -> i64
called by 1: bb_measure_file calls 1: bb_rd_u16
329func bb_bands(rate: i64, centres: *i64) -> i64
called by 1: bb_analyze
343func bb_goertzel(x: *i64, s: i64, m: i64, f: i64, rate: i64) -> i64
called by 1: bb_analyze calls 1: osc_sin_unit
374func bb_acorr(x: *i64, s: i64, fn: i64, lag: i64, mean: i64) -> i64
called by 1: bb_analyze calls 1: nx_isqrt
417func bb_biph_frame(fpow: *i64, base: i64, centres: *i64, nb: i64, biph_r: i64) -> i64
called by 1: bb_analyze calls 1: bb_iabs
467func bb_analyze(x: *i64, n: i64, rate: i64, nch: i64, bits: i64, c: *i64, res: *i64) -> i64
864func bb_measure_file(path: *u8, c: *i64, res: *i64) -> i64
881func bb_report(label: *u8, res: *i64) -> i64
called by 1: main calls 2: bb_wbb_kvpair
914func main(argc: i64, argv: *i64) -> i64