Documentation
¶
Overview ¶
Package dsp provides digital signal processing utilities for the Opus codec.
Index ¶
- Constants
- func Abs(x float64) float64
- func ApplyWindow(signal []float64, window []float64)
- func BitReverse(n, bits int) int
- func Clamp(val, min, max int) int
- func ClampFloat(val, min, max float64) float64
- func Cos(x float64) float64
- func Dot(a, b []float64) float64
- func Energy(x []float64) float64
- func IsPowerOf2(n int) bool
- func Log2(n int) int
- func Max(a, b int) int
- func MaxFloat(a, b float64) float64
- func Min(a, b int) int
- func MinFloat(a, b float64) float64
- func NextPowerOf2(n int) int
- func Normalize(x []float64)
- func OverlapAdd(output []float64, input []float64, offset int)
- func RMS(x []float64) float64
- func RealIFFT(input []Complex, outputSize int) ([]float64, error)
- func Sin(x float64) float64
- func Window(windowType, length int) []float64
- func WindowedOverlapAdd(output []float64, input []float64, window []float64, offset int)
- type CELTMode
- func (m *CELTMode) CLTMDCTBackward(X []float64, carry []float64) []float64
- func (m *CELTMode) CLTMDCTForward(in []float64) []float64
- func (m *CELTMode) IMDCT(X []float64) []float64
- func (m *CELTMode) IMDCTRaw(X []float64) []float64
- func (m *CELTMode) InverseOverlapAdd(y []float64, tail []float64) []float64
- type Complex
- type FFTConfig
- type MDCT
- func (m *MDCT) Forward(input []float64) ([]float64, error)
- func (m *MDCT) ForwardOverlap(input []float64, overlap []float64) ([]float64, error)
- func (m *MDCT) Inverse(input []float64) ([]float64, error)
- func (m *MDCT) InverseOverlap(coeffs []float64, overlap []float64) ([]float64, error)
- func (m *MDCT) Size() int
Constants ¶
const ( WindowHann = iota WindowHamming WindowBlackman WindowSine WindowVorbis )
Window types
const Pi = math.Pi
Pi is the mathematical constant π
Variables ¶
This section is empty.
Functions ¶
func ApplyWindow ¶
ApplyWindow multiplies the input signal by a window function in-place.
func BitReverse ¶
BitReverse reverses the bits of n for the given number of bits
func ClampFloat ¶
ClampFloat restricts a float64 value to a given range
func Normalize ¶
func Normalize(x []float64)
Normalize normalizes a slice to have maximum absolute value of 1.0
func OverlapAdd ¶
OverlapAdd performs overlap-add operation for windowed frames.
Types ¶
type CELTMode ¶
type CELTMode struct {
N int // frame size (e.g. 960)
Overlap int // overlap size (e.g. 120)
Window []float64 // synthesis window of length Overlap (rising ramp, 0→1)
}
CELTMode holds parameters for the CELT MDCT with small-overlap model.
func NewCELTMode ¶
NewCELTMode creates a CELT mode. window is the overlap-region window (length = overlap).
func (*CELTMode) CLTMDCTBackward ¶
CLTMDCTBackward performs the CELT inverse transform and TDAC mirror/window step matching libopus clt_mdct_backward. carry holds the ov/2 future samples preserved from the previous call in libopus' decode_mem layout.
func (*CELTMode) CLTMDCTForward ¶ added in v1.1.0
CLTMDCTForward performs the CELT forward MDCT, the analysis counterpart of CLTMDCTBackward. It is a faithful float port of libopus clt_mdct_forward_c (celt/mdct.c) for the non-subdivided (stride=1) case, using the same trig convention as IMDCTRaw (cos(2π(i+0.125)/(2N))).
Input `in` is the analysis buffer of length N+Overlap: the first Overlap samples are the windowed transition from the previous frame and the remaining N samples are the current frame (libopus celt_encoder compute_mdcts passes in+b*N over a buffer of stride B*N+overlap). Output is N MDCT coefficients matching the layout consumed by CLTMDCTBackward.
scale is the post-FFT scale factor making CLTMDCTBackward(CLTMDCTForward(x)) reconstruct x through overlap-add; it pairs with the "raw" (unnormalised) IMDCTRaw used by the backward path.
func (*CELTMode) IMDCT ¶
IMDCT computes the N-point CELT inverse MDCT and returns N raw (unwindowed) time-domain samples. Windowing is deferred to InverseOverlapAdd.
Formula (RFC 6716 §5.5.2):
Y[n] = (2/N) * sum_{k=0}^{N-1} X[k] * cos(π/N * (k+1/2) * (n + N/2 + 1/2))
= (2/N) * Re( exp(iπ(2n+N+1)/(4N)) * DFT_{2N}(a')[n] )
where a'[k] = X[k] * exp(iπk(N+1)/(2N)) (zero-padded to 2N)
type Complex ¶
type Complex struct {
Real, Imag float64
}
Complex represents a complex number for FFT operations
func AnyFFT ¶
AnyFFT computes the DFT of x using Bluestein's chirp-Z algorithm. Works for any length N (not restricted to powers of 2).
func FFT ¶
FFT performs a Cooley-Tukey FFT on the input data. The input size must be a power of 2. This implementation is based on the classic radix-2 decimation-in-time algorithm.
func RealFFT ¶
RealFFT performs FFT on real-valued input, exploiting symmetry. Returns only the first n/2+1 complex values (the rest are conjugate symmetric).
type FFTConfig ¶
type FFTConfig struct {
// contains filtered or unexported fields
}
FFTConfig holds precomputed twiddle factors for efficient repeated FFT operations.
func NewFFTConfig ¶
NewFFTConfig creates a new FFT configuration with precomputed twiddle factors.
func (*FFTConfig) ExecuteInPlace ¶ added in v1.2.0
ExecuteInPlace performs the configured FFT directly in data.
type MDCT ¶
type MDCT struct {
// contains filtered or unexported fields
}
MDCT represents a Modified Discrete Cosine Transform configuration. MDCT is used extensively in audio coding, particularly in CELT.
func NewMDCT ¶
NewMDCT creates a new MDCT configuration. size is the number of output coefficients (input is 2*size samples). For non-power-of-2 sizes (e.g. 960), a direct cosine computation is used.
func (*MDCT) Forward ¶
Forward performs the forward MDCT transform. Input: 2*N samples, Output: N coefficients.
func (*MDCT) ForwardOverlap ¶
ForwardOverlap performs forward MDCT with proper overlap handling for streaming.
func (*MDCT) Inverse ¶
Inverse performs the inverse MDCT transform (IMDCT). Input: N coefficients, Output: 2*N samples (before overlap-add).
func (*MDCT) InverseOverlap ¶
InverseOverlap performs inverse MDCT with proper overlap-add for streaming.