| 1 |
//////////////////////////////////////////////////////////////////// |
| 2 |
// PitchTrack is a monophonic autocorrelation pitch tracker with // |
| 3 |
// a fast response and extremely high accuracy, even at low // |
| 4 |
// frequencies. It is adapted from [helmholtz~] for Pd by Katja, // |
| 5 |
// documented at http://www.katjaas.nl/helmholtz/helmholtz.html // |
| 6 |
//////////////////////////////////////////////////////////////////// |
| 7 |
|
| 8 |
// Options |
| 9 |
// get(): (read only) get calculated frequency |
| 10 |
// |
| 11 |
// fidelity: (float) [0-1], default 0.95 |
| 12 |
// This is a threshold for certainty about the result. A highly periodic |
| 13 |
// signal (ie one that has a strong pitch center) should produce a result |
| 14 |
// with a high fidelity, which a non-periodic signal (eg noise) will have |
| 15 |
// a very low fidelity. Setting this parameter close to 1 should reduce |
| 16 |
// the number of inaccurate reports. |
| 17 |
// |
| 18 |
// sensitivity (float) [0-1], default 0.003 |
| 19 |
// This is the minimum RMS value to trigger a pitch calculation. Setting |
| 20 |
// this parameter low forces PitchTrack to attempt to find the pitch of |
| 21 |
// even very quiet sounds. Higher values will cause it to trigger only |
| 22 |
// on louder notes. |
| 23 |
// |
| 24 |
// overlap (int) [1-?], default 2 |
| 25 |
// How much to overlap successive analysis frames. Higher values should |
| 26 |
// produce smoother values, at the cost of an increase of CPU load. |
| 27 |
// |
| 28 |
// frame (int) [128-?], default 2048 |
| 29 |
// Size of FFT frame for analysis. Smaller values result in lower latency |
| 30 |
// and high responsiveness but less accuracy. Higher values result in |
| 31 |
// considerably greater CPU load. Values that aren't powers of 2 get |
| 32 |
// rounded up to the next power of 2. Recommend 512, 1024, or 2048. |
| 33 |
// |
| 34 |
// bias (float) [0-1], default 0.2 |
| 35 |
// Katja's pitch tracker introduces a small bias to help with the tracking. |
| 36 |
// (See the link above.) I don't know how this parameter affects the output. |
| 37 |
|
| 38 |
// Example |
| 39 |
SinOsc osc => dac; // create an oscillator |
| 40 |
// PitchTrack must connect to blackhole to run |
| 41 |
osc => PitchTrack pitch => blackhole; |
| 42 |
|
| 43 |
0.5 => osc.gain; |
| 44 |
|
| 45 |
while (true) |
| 46 |
{ |
| 47 |
// set the oscillator to a random frequency |
| 48 |
Math.random2f(200,1000) => osc.freq; |
| 49 |
<<< "Actual oscillator frequency:",osc.freq(),"Hz" >>>; |
| 50 |
250::ms => now; // pass a little time |
| 51 |
<<< "PitchTrack thinks it's this:",pitch.get(),"Hz" >>>; |
| 52 |
<<< "Difference:",Math.fabs(osc.freq() - pitch.get()),"Hz\n" >>>; |
| 53 |
2::second => now; |
| 54 |
} |