celt

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 25, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

Package celt implements the MDCT layer of the Opus decoder.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func OverlapWindow

func OverlapWindow() []float32

OverlapWindow returns the MDCT overlap window (celt_mode->window in libopus). The encoder-side gain crossfades in src/opus_encoder.c are shaped by it, and those run before the CELT layer sees the samples.

func SmoothFade

func SmoothFade(in1, in2, out []float32, overlap int, channels int)

SmoothFade applies the RFC 6716 CELT transition window over one 2.5 ms overlap at the internal 48 kHz CELT rate.

func SmoothFadeWithSampleRate

func SmoothFadeWithSampleRate(in1, in2, out []float32, overlap int, channels int, outputSampleRate int)

SmoothFadeWithSampleRate applies the CELT transition window at an Opus API output rate. RFC 6716 indexes the 48 kHz window by 48000/Fs for lower rates.

Types

type Decoder

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

Decoder maintains state for the RFC 6716 Section 4.3 CELT layer.

func NewDecoder

func NewDecoder() Decoder

NewDecoder creates a CELT decoder with the static Opus 48 kHz mode.

func (*Decoder) Decode

func (d *Decoder) Decode(
	in []byte,
	out []float32,
	isStereo bool,
	outputChannelCount int,
	frameSampleCount int,
	startBand int,
	endBand int,
) error

Decode decodes one CELT frame into interleaved 48 kHz float PCM.

func (*Decoder) DecodeToSampleRate

func (d *Decoder) DecodeToSampleRate(
	in []byte,
	out []float32,
	isStereo bool,
	outputChannelCount int,
	frameSampleCount int,
	startBand int,
	endBand int,
	outputSampleRate int,
) error

DecodeToSampleRate decodes one CELT frame into interleaved float PCM at the requested Opus API sample rate. RFC 6716 keeps the MDCT mode at 48 kHz and decimates during CELT deemphasis for lower output rates.

func (*Decoder) DecodeWithRange

func (d *Decoder) DecodeWithRange(
	in []byte,
	out []float32,
	isStereo bool,
	outputChannelCount int,
	frameSampleCount int,
	startBand int,
	endBand int,
	rangeDecoder *rangecoding.Decoder,
) error

DecodeWithRange decodes one CELT frame using an Opus range decoder shared with the SILK layer in hybrid packets.

func (*Decoder) DecodeWithRangeToSampleRate

func (d *Decoder) DecodeWithRangeToSampleRate(
	in []byte,
	out []float32,
	isStereo bool,
	outputChannelCount int,
	frameSampleCount int,
	startBand int,
	endBand int,
	outputSampleRate int,
	rangeDecoder *rangecoding.Decoder,
) error

DecodeWithRangeToSampleRate decodes one CELT frame with a shared range coder and emits PCM at the requested Opus API sample rate.

func (*Decoder) FinalRange

func (d *Decoder) FinalRange() uint32

FinalRange exposes the range coder state for RFC conformance tests.

func (*Decoder) Mode

func (d *Decoder) Mode() *Mode

Mode returns the static CELT mode used by this decoder.

func (*Decoder) Reset

func (d *Decoder) Reset()

Reset clears frame-to-frame CELT decode state.

type Encoder

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

Encoder encodes PCM audio into CELT-only Opus frames.

It maintains the inter-frame state required by RFC 6716 Section 5.3: the previous log-energy per band used to predict coarse energy deltas (Section 5.3.3), and the analysis state (pre-emphasis memory and MDCT overlap buffer) needed to produce a continuous bitstream across frames.

The encoder and decoder share the same deterministic bit-allocation algorithm (computeAllocation, Section 5.3.4). After encoding a sequence of symbols the value of rng must match the decoder's rng exactly (RFC 6716 Section 5.1) — use FinalRange on both sides to verify this invariant during testing.

func NewEncoder

func NewEncoder() Encoder

func (*Encoder) Complexity

func (e *Encoder) Complexity() int

func (*Encoder) EncodeFrame

func (e *Encoder) EncodeFrame(pcm [][]float32, dst []byte, frameBytes, startBand, endBand int) (int, error)

EncodeFrame encodes one CELT frame from float PCM into dst. It returns the number of bytes written. dst must be at least frameBytes long.

func (*Encoder) FinalRange

func (e *Encoder) FinalRange() uint32

FinalRange returns the range coder state after the last EncodeFrame call. Compare with the decoder's FinalRange to verify encoder/decoder sync (RFC 6716 Section 5.1).

func (*Encoder) Mode

func (e *Encoder) Mode() *Mode

func (*Encoder) Reset

func (e *Encoder) Reset()

func (*Encoder) SetBitrate

func (e *Encoder) SetBitrate(bps int)

SetBitrate sets the nominal target bitrate in bits per second.

func (*Encoder) SetComplexity

func (e *Encoder) SetComplexity(c int)

func (*Encoder) SetConstrainedVBR

func (e *Encoder) SetConstrainedVBR(cvbr bool)

func (*Encoder) SetLossRate

func (e *Encoder) SetLossRate(rate int)

SetLossRate sets the expected packet loss rate (0-100 percent).

func (*Encoder) SetVBR

func (e *Encoder) SetVBR(vbr bool)

type Mode

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

Mode describes the static 48 kHz CELT mode from RFC 6716 Section 4.3.

func DefaultMode

func DefaultMode() *Mode

DefaultMode returns the static 48 kHz CELT mode used by Opus.

func (*Mode) BandCount

func (m *Mode) BandCount() int

BandCount returns the number of CELT energy bands.

func (*Mode) BandEdges

func (m *Mode) BandEdges(lm int) ([]int, error)

BandEdges returns the RFC 6716 Table 55 MDCT bin edges scaled for a CELT LM.

func (*Mode) BandRangeForSampleRate

func (m *Mode) BandRangeForSampleRate(sampleRate int) (startBand, endBand int, err error)

BandRangeForSampleRate returns the coded CELT band range for an Opus bandwidth sample rate. The end bands come from the RFC 6716 Section 4.3/Table 55 band stop frequencies.

func (*Mode) BandWidth

func (m *Mode) BandWidth(band, lm int) (int, error)

BandWidth returns the number of MDCT bins in one energy band for a CELT LM.

func (*Mode) FrameSampleCount

func (m *Mode) FrameSampleCount(lm int) (int, error)

FrameSampleCount returns the sample count per channel for a CELT LM. RFC 6716 Section 4.3.3 defines LM as log2(frame_size/120).

func (*Mode) HybridBandRange

func (m *Mode) HybridBandRange(sampleRate int) (startBand, endBand int, err error)

HybridBandRange returns the CELT band range used by hybrid modes. RFC 6716 Section 4.3 leaves bands below band 17 to SILK in hybrid modes.

func (*Mode) LMForFrameSampleCount

func (m *Mode) LMForFrameSampleCount(frameSampleCount int) (int, error)

LMForFrameSampleCount maps a sample count per channel to a CELT LM.

func (*Mode) MaxLM

func (m *Mode) MaxLM() int

MaxLM returns the maximum CELT frame-size shift.

func (*Mode) SampleRate

func (m *Mode) SampleRate() int

SampleRate returns the CELT synthesis sample rate.

func (*Mode) ShortBlockSampleCount

func (m *Mode) ShortBlockSampleCount() int

ShortBlockSampleCount returns the CELT 2.5 ms block size at 48 kHz.

Jump to

Keyboard shortcuts

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