Documentation
¶
Overview ¶
Package qualitycompare is the single, canonical quality comparator for gopus-vs-libopus parity tests. It standardizes on opus_compare — the reference quality tool shipped with libopus and the metric RFC 8251 defines conformance with — so the trust in these comparisons does not depend on gopus: it is the same tool and metric the whole Opus ecosystem (and the spec) uses.
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 ¶
- Variables
- func AssertQuality(t *testing.T, cmp QualityComparison, bar QualityBar, label string)
- func ComputeOpusCompareQuality(decoded, reference []int16, sampleRate, channels int) (float64, error)
- func ComputeOpusCompareQualityFloat32(decoded, reference []float32, sampleRate, channels int) (float64, error)
- func ComputeOpusCompareQualityFloat32WithDelay(decoded, reference []float32, sampleRate, channels, maxDelay int) (float64, int, error)
- type MetricTier
- type ParityIntent
- type ParityVerdict
- type QualityBar
- type QualityComparison
- type RegionVerdict
- type SignalProfile
Constants ¶
This section is empty.
Variables ¶
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"} )
Trusted quality bars. "near-exact" is the bar SILK/CELT (and now Hybrid) decode already meet vs libopus (measured Q>=99.7); it is far above the RFC-8251 conformance floor (Q>=0) yet still strictly below bit-exactness, leaving room only for the transcendental/platform rounding tail that is not a gopus defect.
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 is a trusted parity threshold, anchored to RFC 8251 conformance and libopus's own cross-build self-variation. A zero value means "unchecked".
func QualityBarForMode ¶
func QualityBarForMode(mode string, channels int) QualityBar
QualityBarForMode returns the trusted bar for a decode-parity case by dominant mode. All three modes now meet the near-exact bar vs libopus.
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 ¶
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.