Wiki » History » Version 2

Chris Cannam, 2015-02-02 12:03 PM

1 1 Chris Cannam
h1. The problem
2 1 Chris Cannam
3 1 Chris Cannam
The problem we're trying to solve is:
4 1 Chris Cannam
5 1 Chris Cannam
We have two (or more) recordings of a particular score. We want to carry out some task such as audio alignment on them, but they differ in pitch (tuning frequency) sufficiently to confuse the feature extractor we want to use. We therefore want to detect the difference in pitch between the two, and compensate for it.
6 1 Chris Cannam
7 1 Chris Cannam
This differs from the problem of deducing the tuning frequency of a recording in isolation, because the frequency difference may be quite extreme: more than a semitone. If you ran a tuning-frequency detector (of the type that works by calculating the difference between predominant frequencies and chroma bin centre frequencies) on both recordings, you would believe them closer in frequency than they actually are, because the whole semitones spanned by the difference would be perceived as a change of key rather than tuning frequency.
8 2 Chris Cannam
9 2 Chris Cannam
h2. Experiments
10 2 Chris Cannam
11 2 Chris Cannam
h3. Iterative chroma comparison
12 2 Chris Cannam
13 2 Chris Cannam
Using the script @iterative-chroma/chromacompare.sh@.
14 2 Chris Cannam
15 2 Chris Cannam
Extracts chroma means (using CQ Chromagram) from the first 30 sec of the reference (at 440Hz) and then repeatedly extracts chroma means from the first 30 sec of the test recording with the chroma tuned to various numbers of cents below and above 440 (from -400 to 400 in 10 cent steps). At each step it calculates the Euclidean distance between the chroma vector just extracted and that from the reference. The frequency yielding the lowest distance is reported.
16 2 Chris Cannam
17 2 Chris Cannam
This takes 2m11sec to run and reports the best tuning frequency as 548Hz.
18 2 Chris Cannam
19 2 Chris Cannam
The closest probe frequencies to the actual tuning are 398.85Hz (-170c) and 401.16Hz (-160c). Both score worse than 440Hz does.
20 2 Chris Cannam
21 2 Chris Cannam
h3. Iterative MATCH path comparison
22 2 Chris Cannam
23 2 Chris Cannam
Using the script @iterative-match/matchcompare.sh@.
24 2 Chris Cannam
25 2 Chris Cannam
As above, except that the score is based on lowest MATCH overall path cost between the two files (with the tuning frequency adjusted appropriately for the second one).
26 2 Chris Cannam
27 2 Chris Cannam
This takes 4m12sec to run and reports the best tuning frequency as 363.6Hz.
28 2 Chris Cannam
29 2 Chris Cannam
Once again the two closest probe frequencies score worse than 440Hz does.
30 2 Chris Cannam
31 2 Chris Cannam
MATCH does actually seem to find a reasonable alignment if you feed it the test file pitch-shifted to A=440Hz along with the reference, so this doesn't seem to be a fault in the aligner. I think I am simply misinterpreting the underlying meaning of the overall path cost.
32 2 Chris Cannam
33 2 Chris Cannam
h3. Spectrum comparator
34 2 Chris Cannam
35 2 Chris Cannam
A plugin written for this purpose, in @spectrum-compare@. It works by calculating a mean harmonic spectrum for each of its two input channels, then repeatedly frequency-scaling one using a multiplicative factor and comparing the values for each rescaled version, within a limited frequency range, with the reference version.
36 2 Chris Cannam
37 2 Chris Cannam
It probes shifts up to 2400 cents in both directions and reports a shift of -1021 as the best result. There are various other local minima but the true difference is nowhere near any of them. This may be down to arithmetic error, it seems hard to believe that there wouldn't be a minimum nearby - must review.
38 2 Chris Cannam
39 2 Chris Cannam
h3. Separate tuning and key estimation
40 2 Chris Cannam
41 2 Chris Cannam
h4. NNLS Chroma Tuning plugin
42 2 Chris Cannam
43 2 Chris Cannam
Run on the Egarr recording alone, takes 0.54 sec to produce an estimate of A=445.8 Hz. This is strangely fast! But obviously on its own it has no way to tell the tuning is more than a semitone different.
44 2 Chris Cannam
45 2 Chris Cannam
If concert A actually was 445.8Hz, our actual tuning frequency of 400Hz would be just above G. Can we adjust for the greater-than-a-semitone shift using a key detector as well?
46 2 Chris Cannam
47 2 Chris Cannam
h4. NNLS Chroma and QM Key Detector
48 2 Chris Cannam
49 2 Chris Cannam
The QM Key Detector reports a modal key of C major for the reference and B major for the test piece.
50 2 Chris Cannam
51 2 Chris Cannam
The tuning plugin had reported a tuning frequency of 445.8. If we take this at face value and apply the pitch shift necessary to adjust from 445.8Hz to 440Hz, and then run the key detector, we get a modal key of Bb major.
52 2 Chris Cannam
53 2 Chris Cannam
From 445.8Hz to 440Hz is about 23 cents, so we have shifted the piece down by 23 cents and found it to be a whole tone lower than the reference -- implying that the original tuning frequency was about 177 cents below the reference, or about 397Hz.
54 2 Chris Cannam
55 2 Chris Cannam
That's pretty good, but relying on a key detector feels fragile. We got the right modal key here, but this is an easy piece (in fact it's one of the pieces the key detector's reference templates came from). We could easily have got a complementary key as the modal key and ended up miles out.
56 2 Chris Cannam
57 2 Chris Cannam
I started implementing this in a script (@tuning-and-key/keycompare.sh@), taking advantage as well of the fact that the key detector also has a tuning frequency parameter. But then I discovered that the tuning frequency estimation from NNLS Chroma was not reliable after all -- it produces a different result (433.753) if you resample the audio first (from 48 to 44.1 kHz).
58 2 Chris Cannam
59 2 Chris Cannam
Taking the same approach, if we shift the audio up from 433.753 to 440 and then run the key detector, we get a modal key of A major, three semitones below the reference. We have shifted the piece up by 24.8 cents and found it to be three semis lower than the reference, so the original tuning frequency must have been 324.8 cents below the reference, or about 364.7Hz.
60 2 Chris Cannam
61 2 Chris Cannam
That's no good -- back to the drawing board.