code wiki / _hdl_build / nx_nv1_lpc.nx
nx_nv1_lpc.nx
buildroot/runtime/_hdl_build/nx_nv1_lpc.nx
about
nx_nv1_lpc.nx -- NishiLossless v1 LPC rung: FLAC-class lossless PCM
compression INSIDE the NLC1 container (the named next rung in
knowledge/specs/2026-06-10-nishilossless-nv1-container.md).
New chunk kind 0x4C 'L' = compressed Int16 PCM block. Payload:
u8 mode 0..3 = fixed predictor order; 255 = verbatim escape
u8 k Rice parameter (0..30; 0 when verbatim)
u32 nsamples decoded Int16 sample count (little-endian)
mode==255 : nsamples*2 bytes raw LE Int16
mode 0..3 : mode*2 bytes warmup raw LE Int16, then the Rice bitstream
(LSB-first within each byte), zero-padded to a byte edge.
Fixed predictors (FLAC's fixed mode, exact integer math = zero loss):
o0: pred = 0 o1: pred = x[i-1]
o2: pred = 2x[i-1] - x[i-2]
o3: pred = 3x[i-1] - 3x[i-2] + x[i-3]
Residual r = x[i] - pred, zigzag u = (r<0 ? -2r-1 : 2r), Rice(u,k) =
(u>>k) one-bits, a zero bit, then the k low bits of u LSB-first.
The ENCODER costs every (order, k<16) pair EXACTLY plus the verbatim
escape and writes whichever is smallest -- so the payload is NEVER
larger than 6 + 2*nsamples (noise degrades to verbatim, not expansion).
The DECODER is a validator too: every malformation returns a named
negative (tamper-evidence doctrine), including out-of-range
reconstruction (-7) so a tampered stream cannot decode silently.
Scratch is sys_mmap'd per encode call (no munmap helper exists; the
team-side callers are gates and one-shot transcoders).
license_tier: ORIGINAL
dependencies 1 imports · 10 importers
imports: nx_nv1.nx
imported by: _nv1l_rtgate.nx_nv1l_rtgate_sa.nxnx_audio_codec_pack.nxnx_audio_wire_exceed.nxnx_frame_codec.nxnx_frame_codec_adaptive.nxnx_listen_player.nxnx_nv1_lpc_gate.nxnx_nv1_transcode.nxnx_vc_gate.nx
structs
| none |
consts
| none |
functions
| 33 | func nv1l_rd_i16(b: *u8, off: i64) -> i64 |
| 40 | func nv1l_wr_i16(b: *u8, idx: i64, v: i64) -> i64 called by 1: nv1l_decode |
| 49 | func nv1l_bit_put(b: *u8, pos: i64, bit: i64) -> i64 called by 1: nv1l_rice_put |
| 58 | func nv1l_bit_get(b: *u8, cur: *i64, lim: i64) -> i64 called by 1: nv1l_rice_get |
| 65 | func nv1l_rice_put(b: *u8, pos: i64, u: i64, k: i64) -> i64 |
| 79 | func nv1l_rice_get(b: *u8, cur: *i64, lim: i64, k: i64) -> i64 |
| 99 | func nv1l_residuals(x: *i64, n: i64, o: i64, u: *i64) -> i64 called by 1: nv1l_encode |
| 115 | func nv1l_cost_bits(u: *i64, m: i64, k: i64) -> i64 called by 1: nv1l_best_k |
| 126 | func nv1l_best_k(u: *i64, m: i64, kout: *i64) -> i64 |
| 142 | func nv1l_encode(pcm: *u8, nsamples: i64, out: *u8, outcap: i64) -> i64 |
| 194 | func nv1l_decode(pl: *u8, plen: i64, out: *u8, outcap: i64) -> i64 |