Documentation
¶
Overview ¶
Package fixedpoint contains integer CELT math helpers and the FIXED_POINT CELT encoder and decoder. The codec implementation is selected by the gopus_fixed_point build tag; with it enabled, gopus_qext and gopus_custom_modes select the QEXT and custom-mode paths. The untagged celt_math.go file also builds with the default configuration. Codec-domain arithmetic uses the integer widths and truncation rules of the matching libopus FIXED_POINT path; float32 analysis metadata remains at the boundary.
The port covers the whole FIXED_POINT CELT pipeline, each file naming the libopus translation unit it mirrors:
- integer math kernels (celt/mathops.h, celt/mathops.c): log2/exp2, sqrt, rcp, cos, ilog2 — see celt_math.go and celt_mathops.go;
- the MDCT and KISS-FFT (celt/mdct.c, celt/kiss_fft.c) plus the precomputed 48000/960 tables and optional 96000/1920 QEXT tables;
- band energy, normalisation, PVQ pulse search and the entropy-coupled band quantiser (celt/bands.c, celt/vq.c, celt/quant_bands.c);
- the encoder and decoder drivers, prefilter/comb filter, transient and dynalloc analysis, anti-collapse, de-emphasis and PLC (celt/celt_encoder.c, celt/celt_decoder.c, celt/celt.c).
Why the integer widths matter: in libopus' FIXED_POINT build celt_norm and opus_val32 are int32, opus_val16 is int16 and opus_val64/accumulators are int64. The macros that truncate an operand to int16 before a 16x16 or 16x32 multiply (MULT16_16, MULT16_16_Q15, MAC16_16, MULT16_32_Q15, ...) and the rounded/arithmetic shifts (PSHR32, VSHR32, ROUND16) are reproduced with those exact Go integer types. Widening codec-domain operands before the matching C truncation or shift would change the reference's wraparound and break bit-exactness, so these operand widths are load-bearing.
Q-notation used throughout matches libopus (1.0 represented as 1<<n):
Q10: 1.0 = 1<<10 = 1024 Q14: 1.0 = 1<<14 = 16384 Q15: 1.0 = 1<<15 = 32768 Q16: 1.0 = 1<<16 = 65536
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CeltExp2 ¶
CeltExp2 computes 2^x in fixed-point. Input x is Q10 (1.0 = 1024). Output is Q16 (1.0 = 65536). Matches libopus celt/mathops.h celt_exp2() (FIXED_POINT path).
func CeltExp2Frac ¶
CeltExp2Frac returns the fractional part of 2^x where x is in Q10. Only the fractional bits of x are used (x & 0x3FF in Q10 == x mod 1.0). Output is approximately Q14 (range ≈ [1.0, 2.0)). Matches libopus celt/mathops.h celt_exp2_frac() (FIXED_POINT path).
Constants:
D0=16383, D1=22804, D2=14819, D3=10204
func CeltLog2 ¶
CeltLog2 approximates log2(x) in fixed-point. Input x is Q14 (1.0 = 16384), must be > 0. Output is Q10 (1.0 = 1024). Matches libopus celt/mathops.h celt_log2() (FIXED_POINT path).
func CeltRsqrtNorm ¶
CeltRsqrtNorm computes 1/sqrt(x) for x in [0.25, 1.0) represented in Q16. Output is Q14. Matches libopus celt/mathops.c celt_rsqrt_norm() (FIXED_POINT path).
Types ¶
This section is empty.