nx_voice_fec.nx
buildroot/runtime/nx_voice_fec.nx
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
imports: nx_syscalls.nx
imported by: nx_voice_codec.nx
structs
| 45 | struct FecState |
consts
| 31 | const NX_FEC_VERDICT_UNKNOWN: i64 = 0 |
| 32 | const NX_FEC_VERDICT_OK: i64 = 1 // frame N arrived; no FEC needed |
| 33 | const NX_FEC_VERDICT_RECOVERED: i64 = 2 // frame N lost; recovered from N+1's FEC |
| 34 | const NX_FEC_VERDICT_DOUBLE_LOSS: i64 = 3 // frame N AND N+1 lost; FEC can't help |
| 35 | const NX_FEC_VERDICT_BAD_HEADER: i64 = 4 |
| 36 | const NX_FEC_VERDICT_N: i64 = 5 |
| 39 | const NX_FEC_STRENGTH_OFF: i64 = 0 // 0% overhead; no FEC |
| 40 | const NX_FEC_STRENGTH_LIGHT: i64 = 1 // 6% overhead; quarter-res copy |
| 41 | const NX_FEC_STRENGTH_NORMAL: i64 = 2 // 12% overhead; half-res copy (default) |
| 42 | const NX_FEC_STRENGTH_HEAVY: i64 = 3 // 25% overhead; full-res copy |
functions
| 57 | func nx_fec_recommend_strength(loss_pct: i64) -> i64 |
| 65 | func nx_fec_init(s: *FecState, last_buf: *u8, last_cap: i64) -> i64 called by 1: nx_voice_codec_state_init |
| 78 | func nx_fec_encode_block( called by 1: nx_voice_codec_encode |
| 111 | func nx_fec_remember(s: *FecState, payload: *u8, payload_len: i64, seq: i64) -> i64 called by 1: nx_voice_codec_encode |
| 129 | func nx_fec_decode( |
| 183 | func nx_fec_verdict_is_valid(v: i64) -> i64 |
| 188 | func nx_fec_strength_is_valid(s: i64) -> i64 |