File: SpecCentroid.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 (40 lines) | stat: -rw-r--r-- 1,200 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
class:: SpecCentroid
summary:: Spectral centroid
categories:: UGens>FFT
related:: Classes/SpecFlatness, Classes/SpecPcile

description::
Given an link::Classes/FFT:: strong::chain::, this measures the emphasis::spectral:: centroid, which is the weighted mean frequency, or the "centre of mass" of the spectrum. (DC is ignored.)

This can be a useful indicator of the perceptual emphasis::brightness:: of a signal.

classmethods::
method:: kr

argument:: buffer
an link::Classes/FFT:: chain.

examples::

A link::Classes/Blip:: oscillator is ideal for demonstrating this because the number of harmonics is directly manipulated: as the number of harmonics increases, the centroid is pushed higher. In the example, left-to-right changes the number of harmonics, but up-to-down changes the fundamental pitch; note the different effects of these two on the centroid.

code::
s.boot;
b = Buffer.alloc(s, 2048, 1);
(
x = {
	var in, chain, freq, rq, centroid;

	//freq = LFPar.kr(0.3).exprange(100, 1000);
	freq = MouseY.kr(1000, 100, 1);
	in = Blip.ar(freq, MouseX.kr(1, 100, 1));
	chain = FFT(LocalBuf(2048), in);
	centroid = SpecCentroid.kr(chain);
	centroid.poll(10);
	in.dup * 0.1

}.play
)

x.free;
::