code wiki / _hdl_build / nx_audio_dred_gate.nx

nx_audio_dred_gate.nx source

↩ module page · 63 lines · 4147 B

1// nx_audio_dred_gate.nx -- proves + MEASURES the deep-redundancy keystone (nx_audio_dred): a K-frame redundancy tail 2// recovers a BURST of lost frames with NO retransmit, where 1-frame FEC (our current voice-FEC) leaves a long gap. Also 3// shows the honest depth limit (a burst longer than K leaves B-K gaps -> deeper K needed) + the coarse-frame fidelity + 4// the overhead cost. Cited research: Opus 1.5 DRED recovers up to 1s of loss for 12-32 kb/s at ~1% CPU. 5import "nx_syscalls.nx" 6import "nx_gate_emit_lib.nx" 7import "nx_audio_dred.nx" 8import "nx_gate_verdict.nx" 9 10func g_abs(v: i64) -> i64 { if v < 0 { return 0 - v } return v } 11// set a burst of B lost frames starting at L into the bitmap (rest = received) 12func mk_burst(lost: *i64, n: i64, L: i64, B: i64) -> i64 { 13 var i: i64 = 0; while i < n { lost[i] = 0; i = i + 1 } 14 i = L; while i < L + B { if i < n { lost[i] = 1 } i = i + 1 } 15 return 0 16} 17 18func main() -> i64 { 19 g_puts("nx_audio_dred gate (deep-redundancy burst recovery, no retransmit, MEASURED)\n" as *u8) 20 var pass: i64 = 0; var total: i64 = 0 21 let n: i64 = 50; let order: i64 = 10 22 let lost: *i64 = sys_mmap(n*8) as *i64 23 24 // a burst of B=8 consecutive frames lost (160ms @ 20ms frames) -- the classic bad-cellular dropout 25 let B: i64 = 8; let L: i64 = 10 26 mk_burst(lost, n, L, B) 27 28 let dred_gaps10: i64 = dred_gaps(lost, n, 10) // DRED depth K=10 (>= burst) 29 let dred_rec10: i64 = dred_recovered(lost, n, 10) 30 let fec_gaps1: i64 = dred_gaps(lost, n, 1) // baseline: 1-frame FEC (our current voice-FEC) 31 let fec_rec1: i64 = dred_recovered(lost, n, 1) 32 33 g_puts(" [measure] burst of " as *u8); g_pn(B); g_puts(" lost frames: DRED(K=10) recovered=" as *u8); g_pn(dred_rec10); g_puts(" gaps=" as *u8); g_pn(dred_gaps10); g_puts(" vs 1-frame-FEC recovered=" as *u8); g_pn(fec_rec1); g_puts(" gaps=" as *u8); g_pn(fec_gaps1); g_puts("\n" as *u8) 34 35 pass = pass + g_check("DRED recovers the WHOLE burst (0 gaps, no retransmit)" as *u8, dred_gaps10 == 0); total=total+1 36 pass = pass + g_check("DRED beats 1-frame FEC (FEC leaves B-1 gap frames = a freeze)" as *u8, fec_gaps1 == B - 1); total=total+1 37 38 // honest depth limit: a burst LONGER than K leaves B-K gaps -> deeper redundancy needed (K=50 ~= 1s) 39 mk_burst(lost, n, L, 15) 40 let deep_gaps: i64 = dred_gaps(lost, n, 10) 41 g_puts(" [measure] honest limit: burst=15 > K=10 -> gaps=" as *u8); g_pn(deep_gaps); g_puts(" (= B-K; recover ~1s by setting K~50)\n" as *u8) 42 pass = pass + g_check("burst > K leaves exactly B-K gaps (depth bounds the recoverable burst)" as *u8, deep_gaps == 15 - 10); total=total+1 43 44 // coarse-frame fidelity: a reflection coeff round-trips Q15->Q7->Q15 with bounded error (envelope preserved) 45 let k_q15: i64 = 22937 // ~0.70 in Q15 46 let err: i64 = g_abs(k_q15 - dred_coarse_dq(dred_coarse_q(k_q15))) 47 // overhead: coarse frame = order i8 + 1 energy byte; tail = K * that 48 let coarse_bytes: i64 = order + 1 49 let tail_bytes: i64 = 10 * coarse_bytes 50 g_puts(" [measure] coarse-coeff Q15->Q7 err=" as *u8); g_pn(err); g_puts(" (<256 = i8 step) tail=" as *u8); g_pn(tail_bytes); g_puts("B/packet (~" as *u8); g_pn(tail_bytes*50*8/1000); g_puts(" kb/s @50fps; neural codebook -> 12-32 kb/s is the moonshot)\n" as *u8) 51 pass = pass + g_check("coarse envelope preserved (Q7 reflection err < 256)" as *u8, err < 256); total=total+1 52 53 g_puts("---- audio dred gate: passed " as *u8); g_pn(pass); g_puts(" / " as *u8); g_pn(total); g_puts(" ----\n" as *u8) 54 // MIGRATED onto nx_gate_verdict by nx_gate_dry_apply (D001, minimal form): every check 55 // row above is untouched, so the PASS/FAIL vector cannot change; only the hand-rolled 56 // verdict emission is replaced by the ONE shared base class. Proven by nx_gate_migrate verify. 57 let ctr__dry: *i64 = gv_ctr() 58 ctr__dry[0] = pass 59 ctr__dry[1] = total 60 let rc__dry: i64 = gv_verdict("AUDIO-DRED-GATE" as *u8, ctr__dry, "teeth unchanged; verdict emission migrated onto the shared base class" as *u8) 61 sys_exit(rc__dry) 62 return rc__dry 63}