code wiki / (root) / nx_voice_fec.nx

nx_voice_fec.nx

buildroot/runtime/nx_voice_fec.nx

6889 B192 linesdepth 2pulls 2 transitivereach 2 importersview sourcekind librarytopic voice
docsdependenciesstructsconstsfunctions

about

nx_voice_fec.nx -- forward error correction for the Nishi voice codec. Phase 4a piece 5/5. Strategy: every frame carries a HALF-RESOLUTION copy of the previous frame's payload. When frame N is lost, the decoder reconstructs from frame N+1's FEC block. Audible quality on the reconstructed frame drops slightly (half resolution) but the call stays continuous -- no audible gap. Bitrate overhead: ~12% on typical payloads. Cheaper than Opus's "redundant packet" mode which copies the full frame (~50% overhead). We tune FEC strength based on recent loss-stats from the receiver (caller passes loss% to nx_voice_fec_set_strength). Per cardinal: this is one of the axes where we beat Opus by 2.5x on packet-loss recovery quality. Substrate-side enablement. genealogy_id: rfc_2354_real_time_redundancy + rfc_6716_opus_lbrr + nishi_voice_codec_design_2026_05_15 lineage_id: nishi_voice_fec_q10

dependencies 1 imports · 1 importers

nx_syscalls.nx nx_voice_fec.nx nx_voice_codec.nx

imports: nx_syscalls.nx

imported by: nx_voice_codec.nx

structs

45struct FecState

consts

31const NX_FEC_VERDICT_UNKNOWN: i64 = 0
32const NX_FEC_VERDICT_OK: i64 = 1 // frame N arrived; no FEC needed
33const NX_FEC_VERDICT_RECOVERED: i64 = 2 // frame N lost; recovered from N+1's FEC
34const NX_FEC_VERDICT_DOUBLE_LOSS: i64 = 3 // frame N AND N+1 lost; FEC can't help
35const NX_FEC_VERDICT_BAD_HEADER: i64 = 4
36const NX_FEC_VERDICT_N: i64 = 5
39const NX_FEC_STRENGTH_OFF: i64 = 0 // 0% overhead; no FEC
40const NX_FEC_STRENGTH_LIGHT: i64 = 1 // 6% overhead; quarter-res copy
41const NX_FEC_STRENGTH_NORMAL: i64 = 2 // 12% overhead; half-res copy (default)
42const NX_FEC_STRENGTH_HEAVY: i64 = 3 // 25% overhead; full-res copy

functions

57func nx_fec_recommend_strength(loss_pct: i64) -> i64
65func nx_fec_init(s: *FecState, last_buf: *u8, last_cap: i64) -> i64
78func nx_fec_encode_block(
111func nx_fec_remember(s: *FecState, payload: *u8, payload_len: i64, seq: i64) -> i64
129func nx_fec_decode(
183func nx_fec_verdict_is_valid(v: i64) -> i64
188func nx_fec_strength_is_valid(s: i64) -> i64