Debian Codegraph @

examples/analysis/Sigmund.ck

raw
1 ///////////////////////////////////////////////////
2 // Sigmund: sinusoidal analysis & pitch tracking //
3 // //
4 // by Miller Puckette //
5 // //
6 ///////////////////////////////////////////////////
7
8 // Options:
9 // npts (int): number of points used in analysis.
10 // Must be a power of 2, at least 128. The
11 // minimum frequency that can be tracked is
12 // about 2 * samplerate / npts
13 // default: 1024
14 //
15 // npeak (int): maximum number of sinusoidal peaks
16 // to look for. The computation time is
17 // quadratic in the number of peaks actually
18 // found (this number only sets an upper
19 // limit). Use it to balance CPU time with
20 // quality of results.
21 //
22 // maxfreq (float): maximum frequency of sinusoidal
23 // peaks to look for. This can be useful in
24 // situations where background nose creates
25 // high-frequency, spurious peaks...
26 //
27 // minpower (float): minimum dB level to
28 // report a pitch. Signals quieter than this
29 // will be assumed to be crosstalk and ignored.
30 // default: 50
31 //
32 // freq() (read-only): get reported frequency of
33 // input signal
34 //
35 // env() (read-only): get reported RMS value (in dB)
36 // of input signal
37 //
38 // peak (int): report freq of nth sinusoundal peak
39 // sorting depends on parameter "dotracks"
40 //
41 // amp (int): report amplitude of nth sinusoundal peak
42 // sorting depends on parameter "dotracks"
43 //
44 // tracks (0/1): toggle whether peak and amp are
45 // sorted in order of amplitude or organized into
46 // tracks
47 //
48 // clear(): clear buffers and reset
49 //
50 // param1, param2, param3 (float): mysterious settings...
51
52 // must connect to blackhole to perform DSP
53 TriOsc foo => Sigmund siggy => blackhole;
54
55 4096 => siggy.npts;
56 20 => siggy.npeak;
57 1000 => siggy.maxfreq;
58 25 => siggy.minpower;
59
60 while (true)
61 {
62 Math.random2f(5,300) => foo.freq;
63 Math.random2f(0,1) => foo.gain;
64 second => now;
65 <<< "Real frequency:",foo.freq(),"real gain:",foo.gain(),"Sigmund found this:",siggy.freq(), "power:", siggy.env() >>>;
66 }