43 lines · 1.1 KB · Text
RawDownload
// name: autocorr.ck// desc: finding the pitch of a note// author: Curtis Ullerich // UGen/UAna patchSinOsc s => Flip flip =^ AutoCorr corr => blackhole;// analysis zie1024 => flip.size;// output in [-1,1]true => corr.normalize;// calculate sample ratesecond/samp => float srate; // pitch estimatefun float estimatePitch(){    // perform analysis at corr (propagating backwards)    corr.upchuck();    // for simplicity, ignore bins for notes that are "too high"    // to care about; stop at the mid-point because it's symmetrical.    (srate/Std.mtof(90)) $ int => int maxBin;    // iterate over result of analysis    for( maxBin => int bin; bin < corr.fvals().size()/2; bin++ )    {        // look for max        if( corr.fval(bin) >= corr.fval(maxBin) ) {            bin => maxBin;        }    }    // return frequency    return srate/maxBin;} // loopfor (int i; i < 10; i++){    // randomize freq    Math.random2f(Std.mtof(40), Std.mtof(80)) => s.freq;    // move forward in time (by analysis frame size)    flip.size()::samp => now;    // print    <<< "pitch", s.freq(), "estimated to be", estimatePitch(), "hz" >>>;}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t