denote.compare¶
Compare a version of a piece with a reference: harmony and sound, on the same moments (denote#3).
align_audio() measures how closely a version follows the
reference’s harmony and melody (chroma DTW), and is blind to timbre on purpose.
compare_audio() adds the other half, how close the sound is, and keeps
both on one footing: the two recordings are aligned once, and every metric reads
the same warping path, so each compares the same musical moments.
Metrics are a registry (METRICS, a name -> metric mapping you can
extend or replace through metrics=): a metric is a callable taking an
AlignedPair and returning a distance (lower is closer). An embedding
metric (CLAP, MERT, a Fréchet-style distance) is one more entry, with no change
to callers.
Built in:
"chroma": the alignment’s own cost, mean cosine distance between chroma frames along the path (0 identical pitch content, 1 unrelated). Measured on an orchestral minute, an unrelated piece in the same key and style scored about 0.16-0.21 against the reference, so it discriminates mainly below about 0.15."timbre": MFCCsc1..c19(c0, loudness, left out) of both recordings, each coefficient z-scored with statistics pooled over both (so a global difference in spectral shape is kept, not normalised away), then the root-mean-square difference per coefficient, averaged along the path. 0 is the same sound; two unrelated timbres are typically around 1. The starter it replaces (z-scored per recording) separated a General MIDI render (0.46-0.79) from a light audio-to-audio pass of the original (0.41); it is a coarse spectral-envelope measure, not a perceptual one.
Module Attributes
an aligned pair -> a distance (lower is closer). |
|
The built-in metrics, by name. |
|
What |
Functions
|
How close |
|
The alignment's chroma cost: mean cosine distance along the path. |
|
Mean RMS difference of pooled-z-scored MFCCs |
Classes
|
Two recordings at one rate, and the alignment between them, as metrics see them. |
|
Distances between a version and a reference (lower is closer), and their alignment. |
- class denote.compare.AlignedPair(audio, reference, sr, frame_rate, alignment)[source]¶
Bases:
objectTwo recordings at one rate, and the alignment between them, as metrics see them.
audioandreferenceare mono samples atsr;alignment.raw["path"]holds the warping path as(audio frame, reference frame)rows atframe_rateframes per second (hophop_lengthsamples).
- class denote.compare.AudioComparison(scores, alignment)[source]¶
Bases:
objectDistances between a version and a reference (lower is closer), and their alignment.
scoresmaps each metric name to its distance;comparison["timbre"]reads one.
- denote.compare.DFLT_METRICS = ('chroma', 'timbre')¶
What
compare_audio()computes whenmetricsis not given.
- denote.compare.METRICS: Mapping[str, Callable[[AlignedPair], float]] = mappingproxy({'chroma': <function chroma_metric>, 'timbre': <function timbre_metric>})¶
The built-in metrics, by name.
- denote.compare.Metric¶
an aligned pair -> a distance (lower is closer).
- Type:
A metric
alias of
Callable[[AlignedPair],float]
- denote.compare.chroma_metric(pair)[source]¶
The alignment’s chroma cost: mean cosine distance along the path.
- Return type:
- denote.compare.compare_audio(audio, reference, *, metrics=('chroma', 'timbre'), registry=mappingproxy({'chroma': <function chroma_metric>, 'timbre': <function timbre_metric>}), sr=None, reference_sr=None, subsequence=False, transpose=0, frame_rate=10.0, audio_sr=22050)[source]¶
How close
audiois toreference, metric by metric, on the same musical moments.- Parameters:
audio (
Union[str,Path,ndarray]) – The version to judge: a path, or an array withsr.reference (
Union[str,Path,ndarray]) – The reference: a path, or an array withreference_sr.metrics (
Union[Iterable[str],Mapping[str,Callable[[AlignedPair],float]]]) – Metric names looked up inregistry, or a{name: metric}mapping used as is (to add one without registering it).registry (
Mapping[str,Callable[[AlignedPair],float]]) – Where names are looked up (defaultMETRICS).subsequence (
bool) – As foralign_audio(), which is run once and shared.transpose (
Union[int,str]) – As foralign_audio(), which is run once and shared.frame_rate (
float) – As foralign_audio(), which is run once and shared.audio_sr (
int) – As foralign_audio(), which is run once and shared.
- Return type:
- Returns:
An
AudioComparison.
Example:
c = denote.compare_audio("render.wav", "original.wav") c["chroma"], c["timbre"]