code wiki / _hdl_build / nx_ns.nx
nx_ns.nx
buildroot/runtime/_hdl_build/nx_ns.nx
about
nx_ns.nx -- R4b: sovereign single-channel Noise Suppressor (the other reserved nx_ns slot).
Integer 3-band Wiener-gain suppressor (NO-FLOAT). A moving-average filterbank splits the
signal into low / mid / high subbands (perfect reconstruction: low+mid+high == input); a
noise-only lead-in estimates per-band noise power; each frame attenuates a band by a Wiener
gain g = max(floor, (band_power - noise_power)/band_power). Bands dominated by noise (e.g.
broadband hiss in the high band where speech has little energy) collapse toward the floor;
speech-bearing bands pass -> noise down, speech preserved -> SNR up.
MEASURED metric = SNR improvement: distance of the OUTPUT to the clean reference vs distance
of the NOISY INPUT to the clean reference. Negative control: gains forced to 1 (suppressor
OFF) -> output == input -> no improvement (the gains are load-bearing).
HONEST SCOPE: in-band noise under speech is NOT removed (single-channel limit -- same as the
classic spectral-subtraction tradeoff); a perceptual/DNN suppressor + musical-noise control =
deeper rung. main() is the SELF-VALIDATING GATE. Evidence -> knowledge/status/ns.log.
license_tier: ORIGINAL
dependencies 1 imports · 0 importers
imports: nx_syscalls.nx
imported by: nobody (leaf or entry point)
call flow from main pre-order; caps 40 nodes / depth 6 declared; ↻ = already shown
structs
| none |
consts
| 18 | const NS_MAGIC_6000: i64 = 6000 |
| 19 | const NS_MAGIC_8000: i64 = 8000 |
| 20 | const NS_MAGIC_1500: i64 = 1500 |
| 21 | const NS_MAGIC_3000: i64 = 3000 |
| 22 | const NS_MAGIC_99991: i64 = 99991 |
| 23 | const NS_MAGIC_1103515245: i64 = 1103515245 |
| 24 | const NS_MAGIC_12345: i64 = 12345 |
| 25 | const NS_MAGIC_6001: i64 = 6001 |
| 27 | const NS_LOG: *u8 = "knowledge/status/ns.log" |
| 28 | const QG: i64 = 12 // gain fixed-point (4096 = 1.0) |
| 29 | const GFLOOR: i64 = 256 // minimum gain ~0.0625 (residual-noise floor, avoids musical noise) |
| 30 | const FR: i64 = 256 // frame length |
functions
| 32 | func nw(fd: i64, s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(fd,s,n); return 0 } |
| 33 | func nwn(fd: i64, v: i64) -> i64 { let bb: *u8=sys_mmap(28); var m: i64=v; if m<0{m=0-m;sys_write(fd,"-" as *u8,1)} let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} var i: i64=0; while i<k{bb[i]=t[k-1-i];i=i+1} sys_write(fd,bb,k); return 0 } |
| 36 | func ma(x: *i64, out: *i64, N: i64, W: i64) -> i64 called by 1: ns_run |
| 47 | func powwin(a: *i64, start: i64, n: i64) -> i64 { var s: i64=0; var i: i64=start; while i<start+n { s=s+a[i]*a[i]; i=i+1 } return s } called by 1: main |
| 48 | func powdiff(a: *i64, b: *i64, start: i64, n: i64) -> i64 { var s: i64=0; var i: i64=start; while i<start+n { let d: i64=a[i]-b[i]; s=s+d*d; i=i+1 } return s } called by 1: main |
| 49 | func bandval(which: i64, L: i64, Lm: i64, xv: i64) -> i64 { if which==0 { return L } if which==1 { return Lm - L } return xv - Lm } called by 1: ns_run |
| 52 | func wiener(fp: i64, np: i64) -> i64 called by 1: ns_run |
| 61 | func ns_run(x: *i64, y: *i64, L: *i64, Lm: *i64, N: i64, P: i64, enable: i64) -> i64 |
| 87 | func tri(i: i64) -> i64 { let ph: i64=i % 256; if ph>=128 { return NS_MAGIC_6000 - (ph-128)*94 } return ph*94 - NS_MAGIC_6000 } called by 1: main |
| 89 | func main() -> i64 |