hybrid

package
v0.2.2 Latest Latest
Warning

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

Go to latest
Published: Oct 7, 2026 License: BSD-3-Clause Imports: 7 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 hybrid implements the Opus Hybrid-mode decoder. Hybrid frames combine a wideband SILK low band with CELT bands starting at band 17 and ending at the active bandwidth limit, using one range decoder for both layers.

Decoder uses separate SILK and CELT decoder state for one stream. It resamples SILK to the configured API rate and combines it with CELT output configured for that same rate. Serialize access to a decoder. This implementation accepts 10 ms and 20 ms encoded Hybrid frames.

Index

Constants

View Source
const (
	// HybridCELTStartBand is the first CELT band decoded in hybrid mode.
	// Bands 0-16 are covered by SILK; CELT starts at band 17 and stops at the
	// configured bandwidth limit.
	HybridCELTStartBand = 17

	// SilkCELTDelay is the libopus SILK/CELT delay in samples at 48 kHz.
	SilkCELTDelay = celt.SilkCELTDelay
)

Constants for Hybrid mode

Variables

View Source
var (
	// ErrInvalidFrameSize indicates a frame size unsupported by Hybrid decoding.
	// Encoded Hybrid frames use 10 ms or 20 ms (480 or 960 samples in the 48 kHz
	// codec domain); PLC also accepts 2.5 ms and 5 ms concealment frames.
	ErrInvalidFrameSize = errors.New("hybrid: invalid frame size (only 10ms/20ms supported)")

	// ErrDecodeFailed indicates a frame decode error.
	ErrDecodeFailed = errors.New("hybrid: frame decode failed")

	// ErrNilDecoder indicates a nil range decoder was passed.
	ErrNilDecoder = errors.New("hybrid: nil range decoder")
)

Errors for Hybrid decoding

Functions

func ValidHybridFrameSize

func ValidHybridFrameSize(frameSize int) bool

ValidHybridFrameSize reports whether frameSize is 480 or 960 samples at 48 kHz, the supported 10 ms and 20 ms encoded Hybrid frame sizes.

Types

type Decoder

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

Decoder decodes Hybrid frames with a SILK low band and CELT high bands. It keeps separate child decoder state, passes the packet's shared range decoder through both layers, and combines their PCM at the configured API rate. A Decoder and its child state belong to one stream; it is not safe for concurrent calls.

func NewDecoder

func NewDecoder(channels int) *Decoder

NewDecoder creates a Hybrid decoder for one or two channels. Values below one select mono; values above two select stereo. The API sample rate defaults to 48 kHz, and Hybrid frames use the wideband SILK decoder plus CELT high bands.

func NewDecoderWithSharedDecoders

func NewDecoderWithSharedDecoders(channels int, silkDec *silk.Decoder, celtDec *celt.Decoder) *Decoder

NewDecoderWithSharedDecoders creates a Hybrid decoder using the supplied SILK and CELT decoders where non-nil. The caller configures those child decoders for the same channel count and stream, then shares them across mode decoders to preserve their histories.

func (*Decoder) ArmFixedPLCLowbandCapture added in v0.2.0

func (d *Decoder) ArmFixedPLCLowbandCapture(buf []int16)

ArmFixedPLCLowbandCapture forwards the integer lowband capture used by the fixed-point multistream Hybrid PLC path. buf receives the resampled SILK int16 samples produced by the next PLC decode.

func (*Decoder) Channels

func (d *Decoder) Channels() int

Channels returns the number of audio channels (1 or 2).

func (*Decoder) Complexity

func (d *Decoder) Complexity() int

Complexity returns the Hybrid highband CELT decoder complexity setting.

func (*Decoder) Decode

func (d *Decoder) Decode(data []byte, frameSize int) ([]float32, error)

Decode decodes a Hybrid frame with the packet stereo flag clear. An empty data slice requests PLC. frameSize is the per-channel sample count at the configured API rate; at the default 48 kHz rate, encoded Hybrid frames use 480 samples for 10 ms or 960 for 20 ms. The result is float32 PCM at that rate.

func (*Decoder) DecodePLCToFloat32WithPacketStereoInto added in v0.2.0

func (d *Decoder) DecodePLCToFloat32WithPacketStereoInto(frameSize int, stereo bool, output []float32) error

DecodePLCToFloat32WithPacketStereoInto conceals a Hybrid frame into caller-owned PCM while advancing the same SILK and CELT PLC state.

func (*Decoder) DecodeStereo

func (d *Decoder) DecodeStereo(data []byte, frameSize int) ([]float32, error)

DecodeStereo decodes a stereo Hybrid frame and returns interleaved float32 PCM at the configured API rate. An empty data slice requests PLC. The decoder must be configured for two channels. frameSize is the per-channel sample count; at 48 kHz, encoded Hybrid frames use 480 or 960 samples.

func (*Decoder) DecodeStereoToFloat32

func (d *Decoder) DecodeStereoToFloat32(data []byte, frameSize int) ([]float32, error)

DecodeStereoToFloat32 decodes a stereo Hybrid frame and returns interleaved float32 PCM at the configured API rate. The decoder must be configured for two channels.

func (*Decoder) DecodeStereoToInt16

func (d *Decoder) DecodeStereoToInt16(data []byte, frameSize int) ([]int16, error)

DecodeStereoToInt16 decodes a stereo Hybrid frame and converts it to interleaved int16 PCM at the configured API rate. The decoder must be configured for two channels.

func (*Decoder) DecodeStereoWithDecoder

func (d *Decoder) DecodeStereoWithDecoder(rd *rangecoding.Decoder, frameSize int) ([]float32, error)

DecodeStereoWithDecoder decodes stereo from a pre-initialized range decoder and returns interleaved float32 PCM at the configured API rate. The decoder must be configured for two channels.

func (*Decoder) DecodeToFloat32

func (d *Decoder) DecodeToFloat32(data []byte, frameSize int) ([]float32, error)

DecodeToFloat32 decodes a Hybrid frame and returns float32 PCM at the configured API rate. frameSize is the per-channel sample count; an empty data slice requests PLC.

func (*Decoder) DecodeToFloat32WithPacketStereo

func (d *Decoder) DecodeToFloat32WithPacketStereo(data []byte, frameSize int, packetStereo bool) ([]float32, error)

DecodeToFloat32WithPacketStereo decodes using packetStereo and returns float32 PCM at the configured API rate. frameSize is the per-channel sample count; an empty data slice requests PLC.

func (*Decoder) DecodeToInt16

func (d *Decoder) DecodeToInt16(data []byte, frameSize int) ([]int16, error)

DecodeToInt16 decodes a Hybrid frame and converts the float32 output to interleaved int16 PCM at the configured API rate. frameSize is the per-channel sample count; an empty data slice requests PLC.

func (*Decoder) DecodeWithDecoder

func (d *Decoder) DecodeWithDecoder(rd *rangecoding.Decoder, frameSize int) ([]float32, error)

DecodeWithDecoder decodes a Hybrid frame from a pre-initialized range decoder and returns float32 PCM at the configured API rate. frameSize is the per-channel sample count. The caller owns rd and controls its packet lifetime.

func (*Decoder) DecodeWithDecoderHook

func (d *Decoder) DecodeWithDecoderHook(rd *rangecoding.Decoder, frameSize int, packetStereo bool, afterSilk func(*rangecoding.Decoder) (int, error)) ([]float32, error)

DecodeWithDecoderHook decodes from a pre-initialized range decoder. afterSilk runs after SILK decodes its symbols and returns the logical packet length after any Opus-layer redundancy parsing. frameSize is the per-channel sample count at the configured API rate.

func (*Decoder) DecodeWithDecoderHookToFloat32

func (d *Decoder) DecodeWithDecoderHookToFloat32(rd *rangecoding.Decoder, frameSize int, packetStereo bool, afterSilk func(*rangecoding.Decoder) (int, error), out []float32) error

DecodeWithDecoderHookToFloat32 decodes a Hybrid frame and writes its interleaved float32 output at the configured API rate into out. frameSize is the per-channel sample count; out must hold frameSize times Channels samples.

func (*Decoder) DecodeWithPacketStereo

func (d *Decoder) DecodeWithPacketStereo(data []byte, frameSize int, packetStereo bool) ([]float32, error)

DecodeWithPacketStereo decodes a Hybrid frame using packetStereo to select the packet's channel layout. frameSize is measured per channel at the configured API rate. An empty data slice requests PLC.

func (*Decoder) FinalRange

func (d *Decoder) FinalRange() uint32

FinalRange returns the final range coder state after decoding a Hybrid frame. It reports the CELT range because CELT consumes the range decoder after SILK.

func (*Decoder) FixedPLCLowbandCaptured added in v0.2.0

func (d *Decoder) FixedPLCLowbandCaptured() int

FixedPLCLowbandCaptured reports the interleaved int16 sample count from the most recent SILK PLC decode captured by ArmFixedPLCLowbandCapture.

func (*Decoder) PhaseInversionDisabled

func (d *Decoder) PhaseInversionDisabled() bool

PhaseInversionDisabled reports whether the CELT layer disables stereo phase inversion.

func (*Decoder) RecordPLCLoss

func (d *Decoder) RecordPLCLoss() float32

RecordPLCLoss advances Hybrid PLC loss cadence and returns the fade factor. This is used when recovering a lost frame via SILK LBRR while CELT still needs concealment for the same frame (decode_fec path).

func (*Decoder) Reset

func (d *Decoder) Reset()

Reset clears decoder state for a new stream. Call this when starting to decode a new audio stream.

func (*Decoder) SetAPISampleRate

func (d *Decoder) SetAPISampleRate(sampleRate int)

SetAPISampleRate sets the output rate for Hybrid PCM. Rates of 8, 12, 16, 24, and 48 kHz update the SILK resampler and CELT downsample factor. With QEXT, 96 kHz selects native CELT mode, which the parent decoder configures. Without QEXT, a 96 kHz request leaves the current rate unchanged. Other values select 48 kHz.

func (*Decoder) SetBandwidth

func (d *Decoder) SetBandwidth(bw celt.CELTBandwidth)

SetBandwidth sets the CELT bandwidth for hybrid decoding.

func (*Decoder) SetComplexity

func (d *Decoder) SetComplexity(complexity int) error

SetComplexity sets CELT decoder complexity for the Hybrid highband layer.

func (*Decoder) SetDeepPLCLossMonoHook

func (d *Decoder) SetDeepPLCLossMonoHook(hook silk.DeepPLCLossMonoHook)

SetDeepPLCLossMonoHook forwards the SILK lowband loss hook used by decoder-side neural PLC/DRED paths.

func (*Decoder) SetFixedHighband

func (d *Decoder) SetFixedHighband(h FixedHybridHighband)

SetFixedHighband installs (or clears, with nil) the integer hybrid highband hook for the next decode. It is a no-op in effect on the float path because the root decoder only sets it while an integer-output packet is active.

func (*Decoder) SetPhaseInversionDisabled

func (d *Decoder) SetPhaseInversionDisabled(disabled bool)

SetPhaseInversionDisabled toggles stereo phase inversion for the CELT layer.

func (*Decoder) SetPrevPacketStereo

func (d *Decoder) SetPrevPacketStereo(stereo bool)

SetPrevPacketStereo synchronizes the previous packet stereo flag. This is used when Hybrid decoding is driven by an external Opus decoder.

func (*Decoder) SetRawMonoFrameHook

func (d *Decoder) SetRawMonoFrameHook(hook silk.RawMonoFrameHook)

SetRawMonoFrameHook forwards the SILK lowband raw mono/mid-channel hook used by decoder-side neural PLC/DRED paths.

func (*Decoder) SetRawMonoLossFrameHook added in v0.2.0

func (d *Decoder) SetRawMonoLossFrameHook(hook silk.RawMonoFrameHook)

SetRawMonoLossFrameHook forwards the SILK loss-history hook used by decoder-side neural PLC/DRED paths.

type FixedHybridHighband

type FixedHybridHighband interface {
	// DecodeHybridHighband is called after the SILK lowband has been decoded and
	// resampled and the shared range decoder rd has been positioned at the CELT
	// start band (after any hybrid redundancy-flag bits, with storage shrunk to
	// exclude trailing redundancy bytes). silkInt16 holds the resampled int16
	// SILK lowband output interleaved by channel (length filled samples). rd is a
	// clone of the shared decoder safe to consume independently of the float CELT
	// decode. frameSizeAPI / frameSize48 are the per-channel API-rate and 48k-core
	// sample counts.
	DecodeHybridHighband(silkInt16 []int16, filled int, rd *rangecoding.Decoder, dataLen, frameSizeAPI, frameSize48 int, packetStereo bool)
}

FixedHybridHighband receives the data needed to run the FIXED_POINT integer CELT highband decode for a hybrid frame, mirroring the libopus opus_decode_frame hybrid path (start_band=17, celt_accum=1 onto the SILK opus_res lowband). It is implemented in the gopus_fixed_point build by the root decoder.

Jump to

Keyboard shortcuts

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