lpcnetplc

package
v0.2.1 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: 6 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 lpcnetplc implements the LPCNet feature prediction, pitch analysis, and FARGAN synthesis used by libopus's neural packet-loss concealment and DRED recovery paths. Model loaders bind the feature predictor, PitchDNN, and FARGAN layers from a validated dnnblob.Blob; State retains the per-decoder feature queue, PCM history, and recurrent predictor state.

The implementation follows libopus 1.6.1's `dnn/lpcnet_plc.c`, `dnn/nnet.c`, `dnn/pitchdnn.c`, and `dnn/fargan.c`. Numerical guarantees apply to matched reference builds. Target-specific floating-point operation order can produce different output across targets.

Index

Constants

View Source
const (
	FARGANSubframeSize       = 40
	FARGANFrameSize          = FARGANNBSubframes * FARGANSubframeSize
	FARGANDeemphasis         = 0.85
	SigNetInputSize          = FARGANCondSize + 2*FARGANSubframeSize + 4
	SigNetFWC0ConvInputs     = 2 * SigNetInputSize
	SigNetFWC0MemSize        = SigNetFWC0ConvInputs - SigNetInputSize
	SigNetFWC0StateSize      = SigNetFWC0ConvInputs
	SigNetFWC0ConvOutSize    = 192
	SigNetFWC0GLUGateOutSize = 192
	SigNetGRU1OutSize        = 160
	SigNetGRU1StateSize      = 160
	SigNetGRU2OutSize        = 128
	SigNetGRU2StateSize      = 128
	SigNetGRU3OutSize        = 128
	SigNetGRU3StateSize      = 128
	SigNetGRU1InputSize      = SigNetFWC0GLUGateOutSize + 2*FARGANSubframeSize
	SigNetGRU2InputSize      = SigNetGRU1OutSize + 2*FARGANSubframeSize
	SigNetGRU3InputSize      = SigNetGRU2OutSize + 2*FARGANSubframeSize
	SigNetSkipDenseInputSize = SigNetGRU1OutSize + SigNetGRU2OutSize + SigNetGRU3OutSize + SigNetFWC0ConvOutSize + 2*FARGANSubframeSize
	SigNetSkipDenseOutSize   = 128
	SigNetSigDenseOutSize    = FARGANSubframeSize
	SigNetPitchGateSize      = 4
)

FARGAN signal-network dimensions, copied verbatim from libopus 1.6.1 dnn/fargan.h and dnn/fargan_data.h. FARGAN is the framewise auto-regressive GAN vocoder that synthesizes time-domain PCM from LPCNet feature vectors; these constants size the GLU conv, the three recurrent GRU stages and the skip/output dense layers that make up sig_net.

View Source
const (
	FARGANPEmbedInputs     = 224
	FARGANPEmbedOutSize    = 12
	FARGANCondDense1Size   = 64
	FARGANCondConv1OutSize = 128
	FARGANCondConv1InSize  = 64
	FARGANCondConv1Delay   = 1
	FARGANCondConv1State   = FARGANCondConv1InSize * (FARGANCondConv1Delay + 1)
	FARGANCondConv1Inputs  = FARGANCondConv1State + FARGANCondConv1InSize
	FARGANCondDense2Size   = 320
	FARGANNBSubframes      = 4
	FARGANCondSize         = FARGANCondDense2Size / FARGANNBSubframes
	PitchMinPeriod         = 32
	PitchMaxPeriod         = 256
)

FARGAN conditioning-network dimensions, copied verbatim from libopus 1.6.1 dnn/fargan.h and dnn/fargan_data.h. The conditioning network embeds the pitch period, then runs two dense layers around a delayed conv1d to produce the per-subframe conditioning vectors that drive the FARGAN signal network. PitchMinPeriod / PitchMaxPeriod bound the pitch-period search shared with the pitch-prediction buffer.

View Source
const (
	NumBands    = 18
	InputSize   = 2*NumBands + NumFeatures + 1
	DenseInSize = 128
	GRU1Size    = 192
	GRU2Size    = 192
)

LPCNet PLC feature-prediction model dimensions, copied verbatim from libopus 1.6.1 dnn/plc_data.h (with NumBands from dnn/freq.h). This is the small GRU network that predicts the next LPCNet feature vector during packet loss; InputSize covers the band energies, the feature vector and the lost-flag, and the two GRU stages feed the output dense layer. The activation* values are the in-network activation selector shared with the runtime.

View Source
const (
	NumFeatures       = 20
	NumTotalFeatures  = 36
	FrameSize         = 160
	ContVectors       = 5
	PLCBufSize        = (ContVectors + 10) * FrameSize
	FARGANContSamples = 320
	MaxFEC            = 104
)

Constants mirrored from libopus 1.6.1 dnn/lpcnet headers.

Variables

This section is empty.

Functions

func PeriodFromFeatures

func PeriodFromFeatures(features []float32) int

PeriodFromFeatures mirrors the libopus FARGAN pitch-period formula.

Types

type Analysis

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

Analysis mirrors the retained libopus LPCNet encoder-analysis state used by the PLC/DRED concealment front end.

func (*Analysis) BurgCepstralAnalysis

func (a *Analysis) BurgCepstralAnalysis(dst, pcm []float32) int

BurgCepstralAnalysis mirrors libopus burg_cepstral_analysis(). It writes the 36-float Burg cepstrum used by the first-loss PLC analysis loop.

func (*Analysis) ComputeSingleFrameFeaturesFloat

func (a *Analysis) ComputeSingleFrameFeaturesFloat(dst, pcm []float32) int

ComputeSingleFrameFeaturesFloat mirrors libopus lpcnet_compute_single_frame_features_float(). It retains encoder-analysis state across calls and writes one 36-float feature vector into dst.

func (*Analysis) Loaded

func (a *Analysis) Loaded() bool

Loaded reports whether the analysis runtime currently has the pitch model family required by libopus.

func (*Analysis) PrimeHistoryFramesFloat

func (a *Analysis) PrimeHistoryFramesFloat(history []float32) int

PrimeHistoryFramesFloat replays a run of normalized 10 ms PCM frames through the retained analysis frontend so first-loss CELT entry can start from the same recent 16 kHz history window used for PLC state priming.

func (*Analysis) Reset

func (a *Analysis) Reset()

Reset clears the retained analysis state but preserves the bound model.

func (*Analysis) SetDREDEncoderMode

func (a *Analysis) SetDREDEncoderMode(enabled bool)

SetDREDEncoderMode selects the libopus DRED encoder-side band-energy accumulation shape used before RDOVAE latent extraction.

func (*Analysis) SetModel

func (a *Analysis) SetModel(blob *dnnblob.Blob) error

SetModel binds the shared pitch model family used by libopus LPCNet analysis. The retained analysis state is reset after a successful bind.

func (*Analysis) SetModelPreservingState

func (a *Analysis) SetModelPreservingState(blob *dnnblob.Blob) error

SetModelPreservingState replaces the pitch model without clearing retained analysis state.

type Conv2DLayer

type Conv2DLayer struct {
	Bias         dnnblob.Float32View
	FloatWeights dnnblob.Float32View
	InChannels   int
	OutChannels  int
	KTime        int
	KHeight      int
}

Conv2DLayer is the typed Go projection of one libopus Conv2dLayer weight bundle used by PitchDNN's cross-correlation conv stages. Weights are always float32; KTime and KHeight are the kernel extents over the time and feature axes, matching conv2d_init in dnn/nnet.h.

type Conv2DLayerSpec

type Conv2DLayerSpec struct {
	Name         string
	Bias         string
	FloatWeights string
	InChannels   int
	OutChannels  int
	KTime        int
	KHeight      int
}

Conv2DLayerSpec names the blob records and dimensions for one Conv2DLayer, mirroring the libopus conv2d_init argument tuple.

func PitchDNNConv2DLayerSpecs

func PitchDNNConv2DLayerSpecs() []Conv2DLayerSpec

PitchDNNConv2DLayerSpecs returns the shared libopus-shaped convolution layer specs the pure-Go pitch runtime binds from a validated blob. Callers must treat the returned slice as read-only.

type FARGAN

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

FARGAN is the caller-owned FARGAN vocoder: a bound model plus its recurrent state and pre-allocated scratch, so repeated synthesis stays allocation-free. It mirrors how libopus embeds FARGANState in the LPCNet PLC decoder.

func (*FARGAN) LastPeriod

func (f *FARGAN) LastPeriod() int

LastPeriod reports the most recent pitch period carried by the retained FARGAN runtime. Decoder DRED parity uses this to align SILK lowband carry state after neural concealment without copying the full snapshot.

func (*FARGAN) Loaded

func (f *FARGAN) Loaded() bool

Loaded reports whether a FARGAN model is currently retained.

func (*FARGAN) PrimeContinuity

func (f *FARGAN) PrimeContinuity(pcm0, features0 []float32) int

PrimeContinuity seeds the FARGAN recurrent buffers from past PCM and the preceding feature vectors, mirroring libopus fargan_cont() (dnn/fargan.c). It requires at least FARGANContSamples PCM samples and at least ContVectors*NumFeatures feature values, and returns FARGANContSamples on success or 0 otherwise.

func (*FARGAN) Reset

func (f *FARGAN) Reset()

Reset clears recurrent synthesis state while preserving the bound model.

func (*FARGAN) SetModel

func (f *FARGAN) SetModel(blob *dnnblob.Blob) error

SetModel binds a validated FARGAN model and clears retained synthesis state.

func (*FARGAN) SetModelPreservingState

func (f *FARGAN) SetModelPreservingState(blob *dnnblob.Blob) error

SetModelPreservingState replaces the bound model without clearing retained synthesis state.

func (*FARGAN) Snapshot

func (f *FARGAN) Snapshot() FARGANSnapshot

Snapshot returns a copy of the retained FARGAN runtime state for parity tests.

func (*FARGAN) Synthesize

func (f *FARGAN) Synthesize(pcm, features []float32) int

Synthesize generates one FARGAN frame (FARGANFrameSize samples) of PCM into pcm from a single LPCNet feature vector, mirroring libopus fargan_synthesize (dnn/fargan.c). It runs the conditioning network once, then the signal network per subframe. It returns FARGANFrameSize on success or 0 if the model is unbound, the state is unprimed, or either input/output slice is too short.

type FARGANConditioner

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

FARGANConditioner mirrors the libopus compute_fargan_cond() runtime and retains the conv1 state needed across frames on a zero-allocation path.

func (*FARGANConditioner) Compute

func (c *FARGANConditioner) Compute(out, features []float32) int

Compute mirrors libopus compute_fargan_cond() using the period derived from the current feature vector.

func (*FARGANConditioner) ComputeWithPeriod

func (c *FARGANConditioner) ComputeWithPeriod(out, features []float32, period int) int

ComputeWithPeriod mirrors libopus compute_fargan_cond() for an explicit pitch period. It writes one full 4-subframe conditioning vector.

func (*FARGANConditioner) FillCondConv1State

func (c *FARGANConditioner) FillCondConv1State(dst []float32) int

FillCondConv1State copies the retained conv1 conditioning state into dst.

func (*FARGANConditioner) LastPeriod

func (c *FARGANConditioner) LastPeriod() int

LastPeriod reports the last period passed through ComputeWithPeriod.

func (*FARGANConditioner) Reset

func (c *FARGANConditioner) Reset()

Reset clears the retained conditioning state but preserves the loaded model.

func (*FARGANConditioner) SetModel

func (c *FARGANConditioner) SetModel(blob *dnnblob.Blob) error

SetModel binds a validated libopus-style FARGAN blob and resets retained conditioner state.

type FARGANConditionerModel

type FARGANConditionerModel struct {
	PEmbed LinearLayer
	Dense1 LinearLayer
	Conv1  LinearLayer
	Dense2 LinearLayer
}

FARGANConditionerModel holds the FARGAN conditioning-network weight layers: the pitch embedding, two dense layers and the delayed conv1d, matching the cond_net members libopus binds in init_fargan (dnn/fargan_data.c).

func LoadFARGANConditionerModel

func LoadFARGANConditionerModel(blob *dnnblob.Blob) (*FARGANConditionerModel, error)

LoadFARGANConditionerModel binds the conditioning subset of the libopus FARGAN model family into typed Go layers.

type FARGANConditionerState

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

FARGANConditionerState is the persistent conditioning-network state: the conv1d delay-line memory and the last pitch period, mirroring the cond members of libopus FARGANState.

type FARGANModel

type FARGANModel struct {
	PEmbed        LinearLayer
	Dense1        LinearLayer
	Conv1         LinearLayer
	Dense2        LinearLayer
	CondGainDense LinearLayer
	FWC0Conv      LinearLayer
	FWC0GLUGate   LinearLayer
	GRU1Input     LinearLayer
	GRU1Recurrent LinearLayer
	GRU2Input     LinearLayer
	GRU2Recurrent LinearLayer
	GRU3Input     LinearLayer
	GRU3Recurrent LinearLayer
	GRU1GLUGate   LinearLayer
	GRU2GLUGate   LinearLayer
	GRU3GLUGate   LinearLayer
	SkipGLUGate   LinearLayer
	SkipDense     LinearLayer
	SigDenseOut   LinearLayer
	GainDenseOut  LinearLayer
}

FARGANModel holds every weight layer libopus binds for the FARGAN vocoder: the conditioning network (PEmbed / Dense1 / Conv1 / Dense2 / CondGainDense) plus the signal network's GLU conv, three GRU stages with their GLU gates, and the skip and output dense layers. Field order and the record names bound in LoadFARGANModel mirror the FARGAN struct and init_fargan in dnn/fargan_data.{h,c}.

func LoadFARGANModel

func LoadFARGANModel(blob *dnnblob.Blob) (*FARGANModel, error)

LoadFARGANModel binds the libopus FARGAN conditioning and signal layers from a validated blob into a reusable FARGANModel.

type FARGANSnapshot

type FARGANSnapshot struct {
	ContInitialized bool
	DeemphMem       float32
	PitchBuf        [PitchMaxPeriod]float32
	CondConv1State  [FARGANCondConv1State]float32
	FWC0Mem         [SigNetFWC0StateSize]float32
	GRU1State       [SigNetGRU1StateSize]float32
	GRU2State       [SigNetGRU2StateSize]float32
	GRU3State       [SigNetGRU3StateSize]float32
	LastPeriod      int
}

FARGANSnapshot exposes the retained FARGAN state needed by decoder-level parity tests.

type FARGANState

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

FARGANState is the persistent FARGAN runtime state, mirroring the recurrent members of libopus FARGANState (dnn/fargan.h): the de-emphasis memory, the pitch prediction buffer, the conditioning conv state, the GLU-conv memory, the three GRU hidden states and the last pitch period. contInitialized tracks whether PrimeContinuity has seeded the buffers, matching libopus' cont_initialized flag.

type LinearLayer

type LinearLayer struct {
	Bias         dnnblob.Float32View
	Subias       dnnblob.Float32View
	Weights      dnnblob.Int8View
	FloatWeights dnnblob.Float32View
	Scale        dnnblob.Float32View
	NbInputs     int
	NbOutputs    int
}

LinearLayer is the typed Go projection of one libopus LinearLayer weight bundle. Bias/Subias/Scale are float32 records; the weight payload is either int8 (paired with Scale) or float32, matching the libopus linear_init selection rules. The same shape is reused by every dense/GRU layer in the LPCNet PLC, FARGAN and PitchDNN models.

type LinearLayerSpec

type LinearLayerSpec struct {
	Name         string
	Bias         string
	Subias       string
	Weights      string
	FloatWeights string
	Scale        string
	NbInputs     int
	NbOutputs    int
}

LinearLayerSpec names the blob records that make up one LinearLayer and its input/output dimensions, mirroring the libopus linear_init argument tuple. Empty record names mark components a layer does not carry.

func FARGANConditionerLayerSpecs

func FARGANConditionerLayerSpecs() []LinearLayerSpec

FARGANConditionerLayerSpecs returns the shared libopus-shaped FARGAN conditioning layer specs the pure-Go loader binds from a validated weights blob. Callers must treat the returned slice as read-only.

func FARGANModelLayerSpecs

func FARGANModelLayerSpecs() []LinearLayerSpec

FARGANModelLayerSpecs returns the shared libopus-shaped conditioning and signal layer specs the FARGAN runtime binds from a validated blob. Callers must treat the returned slice as read-only.

func ModelLayerSpecs

func ModelLayerSpecs() []LinearLayerSpec

ModelLayerSpecs returns the libopus-shaped PLC model layer specs the pure-Go loader binds from a validated weights blob. Callers must treat the returned slice as read-only.

func PitchDNNLinearLayerSpecs

func PitchDNNLinearLayerSpecs() []LinearLayerSpec

PitchDNNLinearLayerSpecs returns the shared libopus-shaped dense/GRU layer specs the pure-Go pitch runtime binds from a validated blob. Callers must treat the returned slice as read-only.

type Model

type Model struct {
	DenseIn  LinearLayer
	DenseOut LinearLayer
	GRU1In   LinearLayer
	GRU1Rec  LinearLayer
	GRU2In   LinearLayer
	GRU2Rec  LinearLayer
}

Model holds the LPCNet PLC feature-prediction layers: the input dense layer, two GRU stages (input + recurrent weights each) and the output dense layer, matching the PLCModel struct in dnn/plc_data.h.

func LoadModel

func LoadModel(blob *dnnblob.Blob) (*Model, error)

LoadModel binds a libopus-style PLC model blob into typed Go layers.

type PitchDNN

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

PitchDNN mirrors libopus PitchDNNState and keeps all recurrent state/scratch caller-owned so repeated analysis stays allocation-free.

func (*PitchDNN) Compute

func (p *PitchDNN) Compute(ifFeatures, xcorrFeatures []float32) float32

Compute mirrors libopus compute_pitchdnn() and returns the normalized pitch class value used by LPCNet analysis.

func (*PitchDNN) Loaded

func (p *PitchDNN) Loaded() bool

Loaded reports whether a pitch model is currently retained.

func (*PitchDNN) Reset

func (p *PitchDNN) Reset()

Reset clears recurrent pitch state while preserving the bound model.

func (*PitchDNN) SetModel

func (p *PitchDNN) SetModel(blob *dnnblob.Blob) error

SetModel binds a validated pitch model family and clears recurrent state.

func (*PitchDNN) SetModelPreservingState

func (p *PitchDNN) SetModelPreservingState(blob *dnnblob.Blob) error

SetModelPreservingState replaces the bound model without clearing recurrent state, matching libopus USE_WEIGHTS_FILE reloads.

type PitchDNNModel

type PitchDNNModel struct {
	DenseIFUpsampler1 LinearLayer
	DenseIFUpsampler2 LinearLayer
	DenseDownsampler  LinearLayer
	DenseFinal        LinearLayer
	Conv1             Conv2DLayer
	Conv2             Conv2DLayer
	GRUInput          LinearLayer
	GRURecurrent      LinearLayer
}

PitchDNNModel holds the PitchDNN weight layers: two dense IF-upsamplers, two conv2d cross-correlation stages, a downsampler, a GRU (input + recurrent) and a final dense layer. Field order and the bound record names mirror the PitchDNN struct and init_pitchdnn in dnn/pitchdnn_data.{h,c}.

func LoadPitchDNNModel

func LoadPitchDNNModel(blob *dnnblob.Blob) (*PitchDNNModel, error)

LoadPitchDNNModel binds the libopus pitchdnn model family into reusable Go layers.

type Predictor

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

Predictor owns reusable PLC model state and scratch so callers can keep the post-DRED feature predictor on an explicit zero-allocation path.

func (*Predictor) Loaded

func (p *Predictor) Loaded() bool

Loaded reports whether a PLC model is currently retained.

func (*Predictor) Predict

func (p *Predictor) Predict(out, in []float32) int

Predict mirrors libopus compute_plc_pred(). It writes one feature vector into out and returns the number of floats written.

func (*Predictor) Reset

func (p *Predictor) Reset()

Reset clears the recurrent predictor state but preserves the loaded model.

func (*Predictor) SetModel

func (p *Predictor) SetModel(blob *dnnblob.Blob) error

SetModel binds a libopus-style PLC model blob and resets predictor state.

func (*Predictor) SetModelPreservingState

func (p *Predictor) SetModelPreservingState(blob *dnnblob.Blob) error

SetModelPreservingState replaces the bound model without clearing predictor state, matching libopus USE_WEIGHTS_FILE reloads.

type PredictorSnapshot

type PredictorSnapshot struct {
	GRU1 [GRU1Size]float32
	GRU2 [GRU2Size]float32
}

PredictorSnapshot exposes the retained predictor GRU state for parity tests.

type State

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

State mirrors the low-cost LPCNet PLC state that the libopus DRED recovery path mutates before audio concealment: the retained feature queue, predictor backups, feature history and PCM history used around the predictor-driven part of lpcnet_plc_conceal().

func (*State) AnalysisGap

func (s *State) AnalysisGap() int

AnalysisGap reports whether the retained PCM history has a gap for the predictor-side analysis loop.

func (*State) AnalysisPos

func (s *State) AnalysisPos() int

AnalysisPos reports the retained PCM-analysis cursor in samples.

func (*State) Blend

func (s *State) Blend() int

Blend reports the retained libopus LPCNet PLC blend flag.

func (*State) ClearBlend

func (s *State) ClearBlend()

ClearBlend mirrors the libopus good-packet handoff when PLC updates are skipped: a successful packet exits concealment by clearing only the blend flag, leaving queued/history state intact.

func (*State) ConcealFrameFloat

func (s *State) ConcealFrameFloat(p *Predictor, f *FARGAN, frame []float32) bool

ConcealFrameFloat mirrors the bounded post-analysis branch of lpcnet_plc_conceal(). When blend is zero it assumes the caller already has the continuity features and PCM tail the history-analysis branch would have produced, then synthesizes one concealed frame. It reports whether the step consumed queued FEC, not whether concealment succeeded.

func (*State) ConcealFrameFloatWithAnalysis

func (s *State) ConcealFrameFloatWithAnalysis(a *Analysis, p *Predictor, f *FARGAN, frame []float32) bool

ConcealFrameFloatWithAnalysis mirrors the full lpcnet_plc_conceal() float path, including the first-loss history replay through Burg/LPCNet analysis before the final predictor/FARGAN synthesis step. It reports whether the step consumed queued FEC, not whether concealment succeeded.

func (*State) ConcealmentFeatureStep

func (s *State) ConcealmentFeatureStep(p *Predictor) bool

ConcealmentFeatureStep mirrors the predictor-backed feature evolution inside lpcnet_plc_conceal(), excluding the final FARGAN audio synthesis.

func (*State) ConsumeFECOrPredict

func (s *State) ConsumeFECOrPredict(p *Predictor, out []float32) bool

ConsumeFECOrPredict mirrors libopus get_fec_or_pred(). It consumes one queued concrete FEC feature vector when available, otherwise predicts one feature vector from the current recurrent state.

func (*State) FECAdd

func (s *State) FECAdd(features []float32)

FECAdd mirrors lpcnet_plc_fec_add(). A nil features slice records a skipped positive feature offset.

func (*State) FECClear

func (s *State) FECClear()

FECClear mirrors lpcnet_plc_fec_clear().

func (*State) FECFillPos

func (s *State) FECFillPos() int

FECFillPos reports how many concrete feature vectors are queued.

func (*State) FECReadPos

func (s *State) FECReadPos() int

FECReadPos reports the next queued feature vector read position.

func (*State) FECSkip

func (s *State) FECSkip() int

FECSkip reports how many positive feature offsets were recorded as missing.

func (*State) FillContFeatures

func (s *State) FillContFeatures(dst []float32) int

FillContFeatures copies the retained continuity feature queue into dst and returns the number of floats written.

func (*State) FillCurrentFeatures

func (s *State) FillCurrentFeatures(dst []float32) int

FillCurrentFeatures copies the retained current feature vector into dst and returns the number of floats written.

func (*State) FillPCMHistory

func (s *State) FillPCMHistory(dst []float32) int

FillPCMHistory copies the retained PCM history window into dst and returns the number of floats written.

func (*State) FillQueuedFeatures

func (s *State) FillQueuedFeatures(slot int, dst []float32) int

FillQueuedFeatures copies one queued feature vector into dst and returns the number of floats written.

func (*State) FinishConcealedFrameFloat

func (s *State) FinishConcealedFrameFloat(frame []float32) int

FinishConcealedFrameFloat mirrors the retained PCM-history tail and cursor maintenance that lpcnet_plc_conceal() performs after feature synthesis.

func (*State) GenerateConcealedFrameFloat

func (s *State) GenerateConcealedFrameFloat(p *Predictor, f *FARGAN, frame []float32) bool

GenerateConcealedFrameFloat mirrors the bounded post-analysis branch of lpcnet_plc_conceal() and reports whether concealment succeeded.

func (*State) GenerateConcealedFrameFloatWithAnalysis

func (s *State) GenerateConcealedFrameFloatWithAnalysis(a *Analysis, p *Predictor, f *FARGAN, frame []float32) bool

GenerateConcealedFrameFloatWithAnalysis mirrors the full lpcnet_plc_conceal() float path and reports whether concealment succeeded.

func (*State) LossCount

func (s *State) LossCount() int

LossCount reports the retained libopus concealment loss counter.

func (*State) MarkConcealed

func (s *State) MarkConcealed()

MarkConcealed mirrors lpcnet_plc_conceal()'s post-blend state.

func (*State) MarkUpdated

func (s *State) MarkUpdated()

MarkUpdated mirrors lpcnet_plc_update()'s blend reset.

func (*State) MarkUpdatedFrameFloat

func (s *State) MarkUpdatedFrameFloat(frame []float32) int

MarkUpdatedFrameFloat mirrors the PCM-history and cursor maintenance in lpcnet_plc_update() for one 10 ms frame on the float path.

func (*State) MarkUpdatedFrameInt16

func (s *State) MarkUpdatedFrameInt16(frame []int16) int

MarkUpdatedFrameInt16 mirrors lpcnet_plc_update() once decoded PCM already exists on libopus's exact opus_int16 grid.

func (*State) MarkUpdatedFrameWithAnalysis

func (s *State) MarkUpdatedFrameWithAnalysis(a *Analysis, frame []float32) int

MarkUpdatedFrameWithAnalysis mirrors the good-packet lpcnet_plc_update() cadence for one 10 ms frame while also advancing the retained LPCNet analysis frontend and continuity vectors.

func (*State) PredictPos

func (s *State) PredictPos() int

PredictPos reports the retained prediction cursor in samples.

func (*State) PrimeFirstLossContinuity

func (s *State) PrimeFirstLossContinuity(f *FARGAN) int

PrimeFirstLossContinuity mirrors the bounded post-analysis FARGAN continuity priming inside lpcnet_plc_conceal(). It assumes the caller already has the continuity features and PCM tail the analysis loop would have produced.

func (*State) PrimeFirstLossPrefill

func (s *State) PrimeFirstLossPrefill(p *Predictor) int

PrimeFirstLossPrefill mirrors the post-analysis first-loss predictor prefill that runs before FARGAN continuity priming. It restores plc_bak[0], then generates and queues the two extra causal feature vectors libopus needs.

func (*State) PrimeFirstLossWithAnalysis

func (s *State) PrimeFirstLossWithAnalysis(a *Analysis, p *Predictor, f *FARGAN) bool

PrimeFirstLossWithAnalysis mirrors the full first-loss history-analysis branch of lpcnet_plc_conceal(). It replays retained PCM history through Burg cepstral analysis and LPCNet feature extraction, advances predictor backup state, generates the two extra causal feature vectors, and primes FARGAN continuity.

func (*State) QueueFeatures

func (s *State) QueueFeatures(features []float32)

QueueFeatures mirrors queue_features() for the 5-vector continuity history.

func (*State) ReplaceHistoryFromFramesFloat

func (s *State) ReplaceHistoryFromFramesFloat(frames []float32) int

ReplaceHistoryFromFramesFloat replaces the retained PCM-history window with a fresh run of decoded 10 ms frames without disturbing queued FEC or predictor state. This mirrors libopus update_plc_state() semantics at the lpcnet state level when neural PLC is entered from CELT decode history.

func (*State) Reset

func (s *State) Reset()

Reset clears the retained queue state and resets blend to the libopus post-update default.

func (*State) RestorePredictor

func (s *State) RestorePredictor(p *Predictor)

RestorePredictor restores the retained plc_net state into the predictor.

func (*State) RestorePredictorBackup

func (s *State) RestorePredictorBackup(p *Predictor, idx int)

RestorePredictorBackup restores one retained plc_bak snapshot into the predictor and plc_net mirror.

func (*State) Snapshot

func (s *State) Snapshot() StateSnapshot

Snapshot returns a copy of the retained PLC state for parity tests.

func (*State) StepFECOrPredict

func (s *State) StepFECOrPredict(p *Predictor, out []float32) bool

StepFECOrPredict mirrors the predictor-side backup rotation and get_fec_or_pred() call that libopus uses inside lpcnet_plc_conceal().

func (*State) SyncPredictor

func (s *State) SyncPredictor(p *Predictor)

SyncPredictor snapshots the current predictor state into the retained plc_net mirror.

type StateSnapshot

type StateSnapshot struct {
	Blend       int
	LossCount   int
	AnalysisGap int
	AnalysisPos int
	PredictPos  int
	FECReadPos  int
	FECFillPos  int
	FECSkip     int
	FEC         [MaxFEC][NumFeatures]float32
	Features    [NumTotalFeatures]float32
	Cont        [ContVectors * NumFeatures]float32
	PCM         [PLCBufSize]float32
	PLCNet      PredictorSnapshot
	PLCBak      [2]PredictorSnapshot
}

StateSnapshot exposes the retained PLC state needed by decoder-level parity tests without changing the production hot path.

Jump to

Keyboard shortcuts

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