qualitycompare

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: 17 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 qualitycompare provides the shared quality comparator for gopus and libopus parity tests. It invokes libopus's opus_compare utility to compute the quality metric described by RFC 8251.

This package is importable from both the testvectors package and the root gopus package tests. It depends only on the standard library plus internal/libopustooling and internal/opusmath, so it introduces no import cycle with the root gopus package.

Index

Constants

This section is empty.

Variables

View Source
var (
	QualityBarNearExact = QualityBar{MinQ: 20.0, MinCorr: 0.997, RMSLo: 0.98, RMSHi: 1.02, Desc: "near-exact vs libopus (SILK/CELT/Hybrid bar)"}
	QualityBarRFC       = QualityBar{MinQ: 0.0, MinCorr: 0.985, RMSLo: 0.97, RMSHi: 1.03, Desc: "RFC 8251 conformance floor"}
)

Quality bars measure decoded-waveform agreement with libopus. They complement exact packet and sample comparisons; a quality pass does not establish bit equality or classify an unexplained difference as acceptable. A validated rounding allowance also requires the evidence in reports/validation.md#parity-contract.

Functions

func AssertQuality

func AssertQuality(t *testing.T, cmp QualityComparison, bar QualityBar, label string)

AssertQuality fails t if cmp does not clear bar, logging the trusted basis and the measured metrics. This is the single assertion all migrated quality-parity tests should use, so the bar (and its libopus-anchored rationale) lives in one place rather than scattered per-test constants.

func ComputeOpusCompareQuality

func ComputeOpusCompareQuality(decoded, reference []int16, sampleRate, channels int) (float64, error)

ComputeOpusCompareQuality scores int16 PCM at delay 0.

func ComputeOpusCompareQualityFloat32

func ComputeOpusCompareQualityFloat32(decoded, reference []float32, sampleRate, channels int) (float64, error)

ComputeOpusCompareQualityFloat32 scores float32 PCM at delay 0.

func ComputeOpusCompareQualityFloat32WithDelay

func ComputeOpusCompareQualityFloat32WithDelay(decoded, reference []float32, sampleRate, channels, maxDelay int) (float64, int, error)

ComputeOpusCompareQualityFloat32WithDelay scores float32 PCM, searching the delay candidates up to maxDelay and returning the best Q and its delay.

Types

type MetricTier

type MetricTier int

MetricTier is the trusted metric selected for a region.

const (
	// TierWaveform: opus_compare Q is invalid (sub-48 kHz, < 10 ms, or
	// concealment); correlation + RMS ratio are the trusted metric.
	TierWaveform MetricTier = iota
	// TierOpusCompare: RFC 8251 Q is valid; correlation + RMS reported alongside.
	TierOpusCompare
)

func (MetricTier) String

func (m MetricTier) String() string

type ParityIntent

type ParityIntent int

ParityIntent selects bar strictness, anchored to external references only.

const (
	// IntentNearExact requires gopus to track libopus as closely as libopus
	// tracks itself across builds (the measured SILK/CELT/Hybrid envelope). This
	// is the default for decode/encode parity.
	IntentNearExact ParityIntent = iota
	// IntentRFCConformance requires only RFC 8251 conformance (Q >= 0).
	IntentRFCConformance
)

type ParityVerdict

type ParityVerdict struct {
	Profile SignalProfile
	Regions []RegionVerdict
}

ParityVerdict is the full result of AssertParity.

func AssertParity

func AssertParity(t *testing.T, candidate, reference []float32, p SignalProfile, intent ParityIntent, label string) ParityVerdict

AssertParity is the single self-selecting parity gate for decoded PCM. It splits the stream into its coded prefix and concealed tail (per profile.CodedSamples), scores each region with the only metric valid for it (opus_compare Q for >= 10 ms of coded 48 kHz audio, waveform corr/RMS otherwise), and gates each on the externally anchored bar for that tier and intent. The caller supplies an objective profile and an intent, never a threshold. It fails t on any region miss and returns the full verdict.

type QualityBar

type QualityBar struct {
	MinQ    float64 // absolute opus_compare floor vs the libopus reference.
	MinCorr float64 // waveform correlation floor.
	RMSLo   float64 // RMS ratio lower bound (0 == unchecked).
	RMSHi   float64 // RMS ratio upper bound (0 == unchecked).
	Desc    string  // human-readable basis, e.g. "near-exact (matches SILK/CELT)".
}

QualityBar holds waveform-quality thresholds for comparisons with libopus. Zero disables the correlation and RMS bounds; MinQ is always applied, so a zero MinQ requires a nonnegative quality score.

func QualityBarForMode

func QualityBarForMode(mode string, channels int) QualityBar

QualityBarForMode returns the trusted bar for a decode-parity case by dominant mode. SILK, CELT and Hybrid use the same decoded-waveform quality bar; channels does not change the selected bar.

func (QualityBar) Check

func (bar QualityBar) Check(cmp QualityComparison) []string

Check reports the ways cmp fails bar (empty slice == pass).

type QualityComparison

type QualityComparison struct {
	Q         float64 // opus_compare Opus quality metric (RFC 8251), higher == closer.
	BestDelay int     // sample delay (per channel * channels) that maximized Q.
	Corr      float64 // secondary: waveform Pearson correlation in [-1, 1].
	RMSRatio  float64 // secondary: RMS(candidate) / RMS(reference).
}

QualityComparison is the result of a trusted opus_compare-based comparison.

func CompareDecodedFloat32

func CompareDecodedFloat32(candidate, reference []float32, sampleRate, channels, maxDelay int) (QualityComparison, error)

CompareDecodedFloat32 is the canonical comparator: it scores candidate decoded PCM against a reference (typically libopus-decoded) using delay-searched opus_compare, plus correlation/RMS diagnostics. 48 kHz interleaved PCM.

type RegionVerdict

type RegionVerdict struct {
	Name string
	Tier MetricTier
	Cmp  QualityComparison
	Bar  QualityBar
}

RegionVerdict is the result for one region (coded or concealed) of a stream.

type SignalProfile

type SignalProfile struct {
	SampleRate   int
	Channels     int
	TotalSamples int // Interleaved sample count; zero infers the nonempty PCM length.
	CodedSamples int
}

SignalProfile objectively describes a decoded stream so the metric can be selected without any per-test judgement. CodedSamples is the interleaved count of leading samples produced by coded frames; the remainder (TotalSamples - CodedSamples) is concealment/extrapolation, where opus_compare Q is invalid. For a fully coded stream, set CodedSamples == TotalSamples (or use CodedProfile).

func CodedProfile

func CodedProfile(sampleRate, channels, totalSamples int) SignalProfile

CodedProfile builds a profile for a stream with no concealment.

Jump to

Keyboard shortcuts

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