dnnblob

package
v0.2.6 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 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 dnnblob parses the USE_WEIGHTS_FILE format read by libopus `dnn/parse_lpcnet_weights.c`. A blob contains named records with a type tag, payload byte size, and weight data. Clone validates the record framing and retains a copy of the input; each record's data view refers to that copy.

The package checks required record names for known DRED, OSCE, and LPCNet model families and exposes typed float32, int32, and int8 views. Model loaders bind those views to layers and validate layer dimensions; this package does not execute the networks.

Index

Constants

View Source
const (
	TypeFloat   int32 = 0
	TypeInt     int32 = 1
	TypeQWeight int32 = 2
	TypeInt8    int32 = 3
)

Record type tags, matching the libopus WeightArray type field (dnn/nnet.h WEIGHT_TYPE_*): float32, int32, quantized weights and int8.

Variables

This section is empty.

Functions

func RequiredDREDDecoderRecordNames

func RequiredDREDDecoderRecordNames() []string

RequiredDREDDecoderRecordNames returns the shared loader-derived record names for the standalone libopus DRED decoder model family. Callers must treat the returned slice as read-only.

func RequiredDecoderControlRecordNames

func RequiredDecoderControlRecordNames(requireOSCEBWE bool) []string

RequiredDecoderControlRecordNames returns the shared loader-derived record names expected by the default-build libopus main decoder path for OPUS_SET_DNN_BLOB. When requireOSCEBWE is true, it includes the optional OSCE and OSCE_BWE families. Callers must treat the returned slice as read-only.

func RequiredEncoderControlRecordNames

func RequiredEncoderControlRecordNames() []string

RequiredEncoderControlRecordNames returns the shared loader-derived record names the libopus encoder path expects from OPUS_SET_DNN_BLOB. Callers must treat the returned slice as read-only.

Types

type Blob

type Blob struct {
	Raw     []byte
	Records []Record
}

Blob stores a framing-validated copy of a libopus-style weights blob and its records. Raw, Records, and Record.Data are mutable; each Record.Data payload aliases Raw. Leave them unchanged while model views use the blob.

func Clone

func Clone(data []byte) (*Blob, error)

Clone validates data using libopus parse_weights-style framing rules and returns a persistent copy whose record slices point into the copied buffer.

func (*Blob) DecoderModels

func (b *Blob) DecoderModels() DecoderModelState

DecoderModels reports which decoder-side model families have all required record names in the retained blob. Model loaders validate layer dimensions.

func (*Blob) HasRecord

func (b *Blob) HasRecord(name string) bool

HasRecord reports whether the parsed blob contains a record with the given name.

func (*Blob) Record

func (b *Blob) Record(name string) (Record, bool)

Record returns the first record with the given name, mirroring libopus find_array_entry() first-match behavior.

func (*Blob) SupportsDREDDecoder

func (b *Blob) SupportsDREDDecoder() bool

SupportsDREDDecoder reports whether the required DRED decoder record names are present.

func (*Blob) SupportsDREDEncoder

func (b *Blob) SupportsDREDEncoder() bool

SupportsDREDEncoder reports whether the required DRED encoder record names are present.

func (*Blob) SupportsFARGAN

func (b *Blob) SupportsFARGAN() bool

SupportsFARGAN reports whether the required FARGAN model record names are present.

func (*Blob) SupportsOSCE

func (b *Blob) SupportsOSCE() bool

SupportsOSCE reports whether the required LACE and NoLACE record names are present.

func (*Blob) SupportsOSCEBWE

func (b *Blob) SupportsOSCEBWE() bool

SupportsOSCEBWE reports whether the required OSCE_BWE record names are present.

func (*Blob) SupportsOSCELACE

func (b *Blob) SupportsOSCELACE() bool

SupportsOSCELACE reports whether all required LACE record names are present.

func (*Blob) SupportsOSCENoLACE

func (b *Blob) SupportsOSCENoLACE() bool

SupportsOSCENoLACE reports whether all required NoLACE record names are present.

func (*Blob) SupportsPLC

func (b *Blob) SupportsPLC() bool

SupportsPLC reports whether the required PLC model record names are present.

func (*Blob) SupportsPitchDNN

func (b *Blob) SupportsPitchDNN() bool

SupportsPitchDNN reports whether the required pitch-model record names are present for the libopus DRED and PLC/FARGAN control loaders.

func (*Blob) ValidateDREDDecoderControl

func (b *Blob) ValidateDREDDecoderControl() error

ValidateDREDDecoderControl checks for the record names required by the standalone libopus DRED decoder loader. Model loaders validate dimensions.

func (*Blob) ValidateDecoderControl

func (b *Blob) ValidateDecoderControl(requireOSCEBWE bool) error

ValidateDecoderControl checks for the record names required by the default libopus decoder DNN-blob control and, when requested, OSCE and OSCE_BWE. Model loaders validate layer dimensions.

func (*Blob) ValidateEncoderControl

func (b *Blob) ValidateEncoderControl() error

ValidateEncoderControl checks for the record names required by the libopus encoder DNN-blob control. The model loader validates layer dimensions.

type DecoderModelState

type DecoderModelState struct {
	PitchDNN bool
	PLC      bool
	FARGAN   bool
	DRED     bool
	OSCE     bool
	OSCEBWE  bool
}

DecoderModelState summarizes which decoder-side model families are present in a validated weights blob.

type Float32View

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

Float32View is a zero-copy typed view over a validated float32 record payload.

func Float32ViewFromBytes

func Float32ViewFromBytes(data []byte, size int32) (Float32View, error)

Float32ViewFromBytes returns a zero-copy float32 view over raw record bytes, validating that the byte count matches size and contains whole elements. This matches libopus's size-driven layer binding behavior.

func (Float32View) At

func (v Float32View) At(i int) float32

At returns the i-th float32 value. It panics if i is outside [0, Len()).

func (Float32View) Bytes added in v0.2.0

func (v Float32View) Bytes() []byte

Bytes returns the view's little-endian payload without copying.

func (Float32View) Empty

func (v Float32View) Empty() bool

Empty reports whether the view is empty.

func (Float32View) Fill

func (v Float32View) Fill(dst []float32) int

Fill copies the view into dst and returns the number of values written.

func (Float32View) Len

func (v Float32View) Len() int

Len reports the number of float32 values in the view.

type Int8View

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

Int8View is a zero-copy typed view over a validated int8 record payload.

func Int8ViewFromBytes

func Int8ViewFromBytes(data []byte, size int32) (Int8View, error)

Int8ViewFromBytes returns a zero-copy int8 view over raw record bytes, validating only the byte size.

func (Int8View) At

func (v Int8View) At(i int) int8

At returns the i-th int8 value.

func (Int8View) Bytes added in v0.2.0

func (v Int8View) Bytes() []byte

Bytes returns the view's payload without copying.

func (Int8View) Empty

func (v Int8View) Empty() bool

Empty reports whether the view is empty.

func (Int8View) Fill

func (v Int8View) Fill(dst []int8) int

Fill copies the view into dst and returns the number of values written.

func (Int8View) Len

func (v Int8View) Len() int

Len reports the number of int8 values in the view.

type Int32View

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

Int32View is a zero-copy typed view over a validated int32 record payload.

func Int32ViewFromBytes

func Int32ViewFromBytes(data []byte, size int32) (Int32View, error)

Int32ViewFromBytes returns a zero-copy int32 view over raw record bytes, validating that the byte count matches size and contains whole elements.

func (Int32View) At

func (v Int32View) At(i int) int32

At returns the i-th int32 value. It panics if i is outside [0, Len()).

func (Int32View) Empty

func (v Int32View) Empty() bool

Empty reports whether the view is empty.

func (Int32View) Fill

func (v Int32View) Fill(dst []int32) int

Fill copies the view into dst and returns the number of values written.

func (Int32View) Len

func (v Int32View) Len() int

Len reports the number of int32 values in the view.

type Record

type Record struct {
	Name string
	Type int32
	Size int32
	Data []byte
}

Record mirrors one libopus WeightArray entry parsed from a weights blob.

func (Record) Float32View

func (r Record) Float32View() (Float32View, error)

Float32View returns a zero-copy float32 view over the record payload.

func (Record) Int8View

func (r Record) Int8View() (Int8View, error)

Int8View returns a zero-copy int8 view over the record payload.

func (Record) Int32View

func (r Record) Int32View() (Int32View, error)

Int32View returns a zero-copy int32 view over the record payload.

Jump to

Keyboard shortcuts

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