nx_range_coder.nx
buildroot/runtime/nx_range_coder.nx
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
imports: nx_syscalls_x86_64.nx
imported by: nx_range_coef.nxnx_resid_entropy.nxnx_vcodec_entropy.nx
structs
| 38 | struct RcEnc |
| 50 | struct RcDec |
consts
| 31 | const NX_RC_VERDICT_UNKNOWN: i64 = 0 |
| 32 | const NX_RC_VERDICT_OK: i64 = 1 |
| 33 | const NX_RC_VERDICT_BUF_FULL: i64 = 2 |
| 34 | const NX_RC_VERDICT_BAD_INPUT: i64 = 3 |
| 35 | const NX_RC_VERDICT_N: i64 = 4 |
functions
| 59 | func nx_rc_enc_init(s: *RcEnc, out_buf: *u8, out_cap: i64) -> i64 |
| 72 | func _rc_enc_put_byte(s: *RcEnc, b: i64) -> i64 |
| 82 | func _rc_enc_renorm(s: *RcEnc) -> i64 |
| 122 | func nx_rc_enc_symbol(s: *RcEnc, fl: i64, fh: i64, ft: i64) -> i64 |
| 141 | func nx_rc_enc_done(s: *RcEnc) -> i64 |
| 178 | func nx_rc_dec_init(d: *RcDec, in_buf: *u8, in_len: i64) -> i64 |
| 200 | func _rc_dec_renorm(d: *RcDec) -> i64 called by 1: nx_rc_dec_update |
| 216 | func nx_rc_dec_get_target(d: *RcDec, ft: i64) -> i64 |
| 222 | func nx_rc_dec_update(d: *RcDec, fl: i64, fh: i64, ft: i64) -> i64 |
| 236 | func nx_rc_verdict_is_valid(v: i64) -> i64 |