code wiki / _hdl_build / nx_perceptual.nx

nx_perceptual.nx

buildroot/runtime/_hdl_build/nx_perceptual.nx

5981 B105 linesdepth 4pulls 4 transitivereach 0 importersview sourcekind tooltopic perceptual
docsdependenciesstructsconstsfunctions

about

nx_perceptual.nx -- R2 of the codec ladder: a PERCEPTUAL audio quantizer on the MDCT (the MP3/AAC/Opus idea). Composes nx_mdct (R1) for the transform. Groups MDCT bins into widening (Bark-like) critical bands, derives a per-band MASKING threshold (band energy + simple spreading + an absolute-hearing floor), then allocates the quantizer step per band so the quantization NOISE sits AT the mask -- coarse where the signal hides it, fine where it doesn't. GATEABLE WITHOUT EARS via the noise-to-mask ratio: noise[b] <= mask[b] in every band = perceptually transparent. TEETH: uniform quantization that reaches the SAME transparency needs many more bits -- so perceptual transparency is provably cheaper. No-float (integer sqrt). license_tier: ORIGINAL expect_exit: 0

dependencies 3 imports · 0 importers

nx_mdct.nx nx_audio_osc.nx nx_syscalls.nx nx_perceptual.nx

imports: nx_mdct.nxnx_audio_osc.nxnx_syscalls.nx

imported by: nobody (leaf or entry point)

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

main pp sys_write sys_mmap mk_window osc_sin_unit osc_sin_s osc_qm osc_cos_s osc_qm ↻ osc_sin_unit ↻ mdct mbasis osc_sin_unit ↻ isqrt quantize bitlen ppn sys_mmap ↻ sys_write ↻ sys_exit

structs

none

consts

11const K_MAGIC_3840: i64 = 3840
12const K_MAGIC_9000: i64 = 9000
13const K_MAGIC_11520: i64 = 11520
14const K_MAGIC_2600: i64 = 2600
15const K_MAGIC_19200: i64 = 19200
17const N: i64 = 256
18const SMR: i64 = 16 // signal-to-mask ratio: a masker hides noise ~SMR x weaker (~12 dB). [config, not magic: psychoacoustics corpus]
19const ATH: i64 = 250000 // absolute-threshold-of-hearing floor (flat approximation; real ATH is frequency-dependent)

functions

21func pp(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 }
called by 1: main calls 1: sys_write
22func ppn(v: i64) -> i64
called by 1: main calls 2: sys_mmapsys_write
30func isqrt(n: i64) -> i64 { if n < 2 { return n } var x: i64=n; var y: i64=(x+1)/2; while y < x { x=y; y=(x + n/x)/2 } return x }
called by 1: main
31func bitlen(v: i64) -> i64 { var a: i64=v; if a<0 {a=0-a} var b: i64=2; while a>0 { b=b+1; a=a>>1 } return b } // sign + magnitude
called by 1: main
33func quantize(X: i64, st: i64) -> i64 { if st < 1 { return X } if X>=0 { return (X + st/2)/st } return 0 - ((0-X + st/2)/st) }
called by 1: main
35func main() -> i64