code wiki / (root) / nx_range_coder.nx

nx_range_coder.nx

buildroot/runtime/nx_range_coder.nx

7389 B240 linesdepth 3pulls 3 transitivereach 7 importersview sourcekind librarytopic range
docsdependenciesstructsconstsfunctions

about

nx_range_coder.nx -- arithmetic (range) coder for the Nishi voice codec. Phase 4a building block. Pure integer; tier-0 ready. What it does: takes a stream of symbols, each with a probability distribution, and emits a near-optimal-entropy byte stream. The decoder reverses. This is what makes the codec hit its target bitrate -- LPC + ACE produce VALUES; range-coder packs them into BYTES with near-Shannon-optimal density. Algorithm: standard binary arithmetic coder operating on 32-bit integer range. Range starts at [0, 2^32). Each symbol narrows the range proportional to its cumulative probability. When the top byte is determined we emit it. RFC 6716 (Opus) section 4 has the same shape; we re-derive from the algorithm, not the bytes. State is i64 to give headroom on the multiplications. genealogy_id: rissanen_1976_arithmetic_coding + opus_range_coder_4 + rfc_6716_section_4 lineage_id: nishi_range_coder_q10

dependencies 1 imports · 3 importers

nx_syscalls_x86_64.nx nx_range_coder.nx nx_range_coef.nx nx_resid_entropy.nx nx_vcodec_entropy.nx

imports: nx_syscalls_x86_64.nx

imported by: nx_range_coef.nxnx_resid_entropy.nxnx_vcodec_entropy.nx

structs

38struct RcEnc
50struct RcDec

consts

31const NX_RC_VERDICT_UNKNOWN: i64 = 0
32const NX_RC_VERDICT_OK: i64 = 1
33const NX_RC_VERDICT_BUF_FULL: i64 = 2
34const NX_RC_VERDICT_BAD_INPUT: i64 = 3
35const NX_RC_VERDICT_N: i64 = 4

functions

59func nx_rc_enc_init(s: *RcEnc, out_buf: *u8, out_cap: i64) -> i64
72func _rc_enc_put_byte(s: *RcEnc, b: i64) -> i64
82func _rc_enc_renorm(s: *RcEnc) -> i64
called by 1: nx_rc_enc_symbol calls 1: _rc_enc_put_byte
122func nx_rc_enc_symbol(s: *RcEnc, fl: i64, fh: i64, ft: i64) -> i64
141func nx_rc_enc_done(s: *RcEnc) -> i64
178func nx_rc_dec_init(d: *RcDec, in_buf: *u8, in_len: i64) -> i64
200func _rc_dec_renorm(d: *RcDec) -> i64
called by 1: nx_rc_dec_update
216func nx_rc_dec_get_target(d: *RcDec, ft: i64) -> i64
222func nx_rc_dec_update(d: *RcDec, fl: i64, fh: i64, ft: i64) -> i64
236func nx_rc_verdict_is_valid(v: i64) -> i64