mdct

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2026 License: LGPL-2.1 Imports: 2 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 mdct implements the forward MDCT used by the AAC encoder, numerically equivalent to FFmpeg's AV_TX_FLOAT_MDCT (libavutil/tx @ d09d5afc3a). Internals are float64 for headroom; the API is float32.

SPDX-License-Identifier: LGPL-2.1-or-later

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MDCT

type MDCT struct {
	// contains filtered or unexported fields
}

MDCT computes a forward MDCT with n output coefficients from 2n inputs:

X[k] = scale * sum_{j=0}^{2n-1} x[j] * cos(pi/n * (j + 0.5 + n/2) * (k + 0.5))

Mirrors libavutil/tx_template.c:ff_tx_mdct_fwd and ff_tx_mdct_gen_exp @ d09d5afc3a (fold 2n reals into n/2 complex points, n/2-point forward FFT, post-rotation; sqrt(scale) folded into the twiddles twice).

func New

func New(n int, scale float64) *MDCT

New returns an MDCT producing n coefficients from 2n input samples with output scale factor scale.

n must be a positive power of two divisible by 4: the FFT's bit-reversal assumes a power-of-two length and Transform's second loop steps over n/4 index pairs. An invalid n would not panic, it would quietly produce wrong coefficients, so it is rejected here. AAC uses 1024 and 128.

Transform writes through the per-instance scratch buffers, so an *MDCT must not be shared across goroutines without external synchronization. The encoder gives each channel its own.

func (*MDCT) Transform

func (m *MDCT) Transform(dst, src []float32)

Transform writes n coefficients to dst from 2n samples in src.

Both slices are re-sliced to their exact length first, so a caller that passes a short buffer fails here rather than part-way through, leaving dst half written.

Jump to

Keyboard shortcuts

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