Open j-funk opened 9 years ago
I agree with j-funk. Unfortunately, I found this to be extremely inaccurate with my Piano at least. Pressing the A4 (440) shows A4 for a tiny millisecond but then jumps around to E and then disappears. Testing others notes (C4, F4 etc) don't even show correctly and just jump around. So I would not recommend this.
This is as consistent as tuning my guitar to a random number generator.
@j-funk @Pranoy1c @Tymski @cwilso @webnard
If you comment out return sampleRate/(best_offset+(8*shift)) under else if (foundGoodCorrelation) the returned frequency is way more stable and accurate at least for notes closer to 440.
} else if (foundGoodCorrelation) { // short-circuit - we found a good correlation, then a bad one, so we'd just be seeing copies from here.
//return sampleRate/(best_offset+(8*shift)); }
Not too sure about the maths for the pitch detection portion, but I decided to generate various oscillators to test the pitch. I noticed that most of the notes are not detected accurately even when generating an oscillator at a fixed frequency (even the live instance is off by a cent for the default A4).
When you reach B6 it is quite drastic with pitch being detected incorrectly by 49 cents (flat).
sourceNode.frequency.value = 1976; // set the oscillator's frequency to B6
var notes = []; /* C C# D Eb E F F# G G# A Bb B*/ notes[0] = [65.41, 69.30, 73.42, 77.78, 82.41, 87.31, 92.50, 98.00, 103.8, 110.0, 116.5, 123.5]; //2
notes[1] = [130.8, 138.6, 146.8, 155.6, 164.8, 174.6, 185.0, 196.0, 207.7, 220.0, 233.1, 246.9]; //3
notes[2] = [261.6, 277.2, 293.7, 311.1, 329.6, 349.2, 370.0, 392.0, 415.3, 440.0, 466.2, 493.9]; //4
notes[3] = [523.3, 554.4, 587.3, 622.3, 659.3, 698.5, 740.0, 784.0, 830.6, 880.0, 932.3, 987.8]; //5
notes[4] = [1047, 1109, 1175, 1245, 1319, 1397, 1480, 1568, 1661, 1760, 1865, 1976]; //6