code wiki / (root) / nx_lpc.nx

nx_lpc.nx

buildroot/runtime/nx_lpc.nx

6463 B180 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic lpc
docsdependenciesstructsconstsfunctions

about

nx_lpc.nx -- Linear Predictive Coding (LPC) analysis via the Levinson-Durbin recursion. Pure integer Q15 fixed-point; no floats; tier-0 ready (runs on MCUs without an FPU). Phase 4a of the Nishi voice codec (docs/NISHI_COMMS_ROADMAP.md). LPC is the spectral-envelope estimator the codec wraps around the excitation signal. Order 10 covers 8 kHz speech; order 16 covers 16 kHz; order 20 for 24 kHz. Q15 convention: - signed coefficients in [-1.0, +1.0) map to int16 in [-32768, +32767] - multiply: (a * b) >> 15 keeps the Q15 invariant - the LPC reflection coefficients k[i] are bounded |k| < 1 in a stable filter; the recursion's stability check is k^2 < 1 We store everything as i64 to give headroom for autocorrelation sums (which can be O(N) where N is samples in a frame, ~320 at 16 kHz / 20 ms). Output coefficients are bounded to Q15 range. Algorithm (standard Levinson-Durbin): R[k] = autocorr(s, k) for k in 0..M e[0] = R[0] for i in 1..M: k_i = -(R[i] + sum(a[j] * R[i-j] for j in 1..i-1)) / e[i-1] a[i] = k_i for j in 1..i-1: a'[j] = a[j] + k_i * a[i-j] a = a' e[i] = (1 - k_i^2) * e[i-1] genealogy_id: levinson_1947 + durbin_1960 + rfc_3951_ilbc + opus_silk_lpc_tables lineage_id: nishi_voice_lpc_q15

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_lpc.nx nx_voice_codec.nx

imports: nx_syscalls.nx

imported by: nx_voice_codec.nx

structs

none

consts

44const NX_LPC_VERDICT_UNKNOWN: i64 = 0
45const NX_LPC_VERDICT_OK: i64 = 1
46const NX_LPC_VERDICT_BAD_ORDER: i64 = 2
47const NX_LPC_VERDICT_ZERO_ENERGY: i64 = 3
48const NX_LPC_VERDICT_UNSTABLE: i64 = 4
49const NX_LPC_VERDICT_N: i64 = 5
51const NX_LPC_Q15_ONE: i64 = 32768 // 1.0 in Q15 (clamped to 32767 in storage)
52const NX_LPC_Q15_MASK: i64 = 0x7fff

functions

55func _q15_mul(a: i64, b: i64) -> i64
called by 1: nx_lpc_levinson
66func nx_lpc_autocorrelate(samples: *i64, n: i64, R: *i64, order: i64) -> i64
called by 1: nx_lpc_analyze
93func nx_lpc_levinson(
called by 1: nx_lpc_analyze calls 1: _q15_mul
165func nx_lpc_analyze(
176func nx_lpc_verdict_is_valid(v: i64) -> i64