fixedpoint

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 23, 2026 License: BSD-3-Clause Imports: 1 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package fixedpoint is the gopus FIXED_POINT CELT codec: a pure-integer port of libopus' CELT encoder and decoder for the static 48000/960 mode. Everything runs in the integer domain with no floating-point and reproduces the libopus integer arithmetic bit-for-bit. The package is not part of the default float build; it is compiled only behind the gopus_fixed_point build tag, so its consumers select the integer codec at build time.

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 twiddle/window 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. Using a wider type anywhere would skip the truncation or overflow wraparound the reference depends on and break bit-exactness, so the operand widths in this package are load-bearing, not incidental.

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

func CeltExp2(x int16) int32

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

func CeltExp2Frac(x int16) int16

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 CeltILog2

func CeltILog2(x int32) int16

CeltILog2 returns floor(log2(x)) for x > 0. Equivalent to EC_ILOG(x)-1 in libopus.

func CeltLog2

func CeltLog2(x int32) int16

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

func CeltRsqrtNorm(x int32) int16

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).

func CeltSqrt

func CeltSqrt(x int32) int32

CeltSqrt approximates sqrt(x) for a Q16 input, returning a Q16 result. x must satisfy 0 <= x; values >= 2^30 saturate to 32767. Matches libopus celt/mathops.c celt_sqrt() (FIXED_POINT path) bit-for-bit.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL