File: FFTPeak.schelp

package info (click to toggle)
supercollider-sc3-plugins 3.7.1~repack-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 14,332 kB
  • ctags: 11,704
  • sloc: cpp: 140,180; lisp: 14,746; ansic: 2,133; xml: 86; makefile: 82; haskell: 21; sh: 8
file content (43 lines) | stat: -rw-r--r-- 1,131 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
CLASS:: FFTPeak
summary:: Find peak value in an FFT frame
categories:: UGens>Analysis, UGens>FFT
related:: Classes/Pitch, Classes/Tartini

DESCRIPTION::
Given an FFT chain, this finds the bin with the strongest magnitude. It outputs the frequency of that bin, and its magnitude.  No interpolation is done on the values.

This could be used as a primitive pitch detector, but in practice autocorrelation methods (as used in link::Classes/Pitch:: and link::Classes/Tartini::) give more reliable pitch tracks. This simple approach gives poor resolution and robustness for that purpose. However it can be useful for other things...

CLASSMETHODS::

METHOD:: kr
argument:: buffer
argument:: freqlo
argument:: freqhi
returns:: # freq, mag. 

EXAMPLES::

code::
// Let's see how good it is at tracking the "pitch" of a sinewave!
s.boot;
b = Buffer.alloc(s,2048,1);
(
x = {
var in, chain, pitch, freq, mag;

pitch = MouseX.kr(100, 1000, 1);
in = SinOsc.ar(pitch);
chain = FFT(b.bufnum, in);

# freq, mag = FFTPeak.kr(chain);

Out.ar(0, in.dup * 0.1);
pitch.poll(label: "Tru freq");
freq .poll(label: "Inferred");
}.play(s);
)

x.free;
::