File: SpecPcile.schelp

package info (click to toggle)
supercollider 1%3A3.13.0%2Brepack-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 80,292 kB
  • sloc: cpp: 476,363; lisp: 84,680; ansic: 77,685; sh: 25,509; python: 7,909; makefile: 3,440; perl: 1,964; javascript: 974; xml: 826; java: 677; yacc: 314; lex: 175; objc: 152; ruby: 136
file content (57 lines) | stat: -rw-r--r-- 2,181 bytes parent folder | download | duplicates (2)
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
class:: SpecPcile
summary:: Find a percentile of FFT magnitude spectrum
categories:: UGens>FFT
related:: Classes/SpecCentroid, Classes/SpecFlatness

description::
Given an link::Classes/FFT:: chain this calculates the cumulative distribution of the frequency spectrum, and outputs the frequency value which corresponds to the desired percentile.

For example, to find the frequency at which 90% of the spectral energy lies below that frequency, you want the 90-percentile, which means the value of emphasis::fraction:: should be 0.9. The 90-percentile or 95-percentile is often used as a measure of strong::spectral roll-off::.

The optional third argument strong::interpolate:: (code::ir::) specifies whether interpolation should be used to try and make the percentile frequency estimate more accurate, at the cost of a little higher CPU usage. Set it to 1 to enable this.

Optional fourth argument is strong::binout:: (code::ir::) specifies whether to output the bin number instead of the frequency (default 0, set to 1 to enable). If interpolate is enabled, linear interpolation on the bin number is performed.

classmethods::
method:: kr

argument:: buffer
an link::Classes/FFT:: chain.
argument:: fraction
argument:: interpolate
argument:: binout

examples::

code::

// Simple demo with filtering white noise, and trying to infer the cutoff freq.
// Move the mouse.
(
{
	var in, chain, realcutoff, estcutoff;
	realcutoff = MouseX.kr(0.00001,22050);
	in = LPF.ar(WhiteNoise.ar, realcutoff);
	chain = FFT(LocalBuf(2048), in);
	estcutoff = Lag.kr(SpecPcile.kr(chain, 0.9), 1);
	realcutoff.poll(Impulse.kr(1), "real cutoff");
	estcutoff.poll(Impulse.kr(1), "estimated cutoff");
	Out.kr(0, estcutoff * 22050.0.reciprocal);
	Out.ar(0, in);
}.scope;
)

// Audio input - try different vowel/long-consonant sounds and see what comes out.
// Specifically, change from "ssss" through to "aaaa" through to "wwww".
(
{
	var in, chain, perc;
	in = SoundIn.ar([0,1]).mean;
	chain = FFT(LocalBuf(2048), in);
	//Out.ar(0, in * 0.1);
	perc = SpecPcile.kr(chain, 0.5);
	Out.kr(0, perc * 22050.0.reciprocal);
	Out.ar(1, LPF.ar(WhiteNoise.ar, perc)); // outputting to right channel
}.scope;
)
::