Documentation
¶
Overview ¶
Package celt implements the MDCT layer of the Opus decoder.
Index ¶
- func OverlapWindow() []float32
- func SmoothFade(in1, in2, out []float32, overlap int, channels int)
- func SmoothFadeWithSampleRate(in1, in2, out []float32, overlap int, channels int, outputSampleRate int)
- type Decoder
- func (d *Decoder) Decode(in []byte, out []float32, isStereo bool, outputChannelCount int, ...) error
- func (d *Decoder) DecodeToSampleRate(in []byte, out []float32, isStereo bool, outputChannelCount int, ...) error
- func (d *Decoder) DecodeWithRange(in []byte, out []float32, isStereo bool, outputChannelCount int, ...) error
- func (d *Decoder) DecodeWithRangeToSampleRate(in []byte, out []float32, isStereo bool, outputChannelCount int, ...) error
- func (d *Decoder) FinalRange() uint32
- func (d *Decoder) Mode() *Mode
- func (d *Decoder) Reset()
- type Encoder
- func (e *Encoder) Complexity() int
- func (e *Encoder) EncodeFrame(pcm [][]float32, dst []byte, frameBytes, startBand, endBand int) (int, error)
- func (e *Encoder) FinalRange() uint32
- func (e *Encoder) Mode() *Mode
- func (e *Encoder) Reset()
- func (e *Encoder) SetBitrate(bps int)
- func (e *Encoder) SetComplexity(c int)
- func (e *Encoder) SetConstrainedVBR(cvbr bool)
- func (e *Encoder) SetLossRate(rate int)
- func (e *Encoder) SetVBR(vbr bool)
- type Mode
- func (m *Mode) BandCount() int
- func (m *Mode) BandEdges(lm int) ([]int, error)
- func (m *Mode) BandRangeForSampleRate(sampleRate int) (startBand, endBand int, err error)
- func (m *Mode) BandWidth(band, lm int) (int, error)
- func (m *Mode) FrameSampleCount(lm int) (int, error)
- func (m *Mode) HybridBandRange(sampleRate int) (startBand, endBand int, err error)
- func (m *Mode) LMForFrameSampleCount(frameSampleCount int) (int, error)
- func (m *Mode) MaxLM() int
- func (m *Mode) SampleRate() int
- func (m *Mode) ShortBlockSampleCount() int
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 ¶
SmoothFade applies the RFC 6716 CELT transition window over one 2.5 ms overlap at the internal 48 kHz CELT rate.
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 ¶
FinalRange exposes the range coder state for RFC conformance tests.
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 (*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 ¶
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) SetBitrate ¶
SetBitrate sets the nominal target bitrate in bits per second.
func (*Encoder) SetComplexity ¶
func (*Encoder) SetConstrainedVBR ¶
func (*Encoder) SetLossRate ¶
SetLossRate sets the expected packet loss rate (0-100 percent).
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) BandEdges ¶
BandEdges returns the RFC 6716 Table 55 MDCT bin edges scaled for a CELT LM.
func (*Mode) BandRangeForSampleRate ¶
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 ¶
BandWidth returns the number of MDCT bins in one energy band for a CELT LM.
func (*Mode) FrameSampleCount ¶
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 ¶
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 ¶
LMForFrameSampleCount maps a sample count per channel to a CELT LM.
func (*Mode) SampleRate ¶
SampleRate returns the CELT synthesis sample rate.
func (*Mode) ShortBlockSampleCount ¶
ShortBlockSampleCount returns the CELT 2.5 ms block size at 48 kHz.