File: PV_MagSmooth.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 (82 lines) | stat: -rw-r--r-- 1,608 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
class:: PV_MagSmooth
summary:: Smooth spectral magnitudes over time
categories::  UGens>FFT, UGens>Analysis
related:: PV_MagSmear

Description::

Smooths out the magnitude of FFT bins over time using recursive averaging.

For each bin, the calculation looks like:

mag = (prevmag * factor) + (mag * (1-factor))


classmethods::

method::new

argument::chain
an fft chain

argument::factor
from 0 (no smoothing occurs) to 1 ("infinite" smoothing, magnitudes never change)


Examples::

code::

s.boot;
b = Buffer.alloc(s, 1024);
c = Buffer.read(s, "sounds/a11wlk01.wav");

(
x = {
var son, chain, out;

son = PlayBuf.ar(1, c, loop: 1);

chain = FFT(b, son);
chain = PV_MagSmooth(chain, 1 - MouseX.kr(1, 0.00001, 1));

out = IFFT(chain);

(out * 0.3).dup

}.play;
)
x.free;


// This one subtracts the smoothed version away, to leave just the spiky bits!
// This is a fairly well-known basis of noise-removal by spectral subtraction,
// which works well if the noise is static or slow-changing while the signal 
// is fast-changing.
// In this demo, mouse left/right controls the amount of smoothing,
//  and when the mousebutton is down you hear the "original" 
//  (otherwise you hear the "cleaned" version).
d = Buffer.alloc(s, 1024);
(
x = {
var son, chain, chainorig, chainsmooth, out;

son = PlayBuf.ar(1, c, loop: 1);

chain = FFT(b, son);
chainorig = PV_Copy(chain, d);
chainsmooth = PV_MagSmooth(chain, 1 - MouseX.kr(1, 0.00001, 1));
chain = PV_MagSubtract(chainorig, chainsmooth, 1);

out = XFade2.ar(IFFT(chain), son, MouseButton.kr(-1,1));

(out * 0.3).dup

}.play;
)
x.free;


b.free; c.free;
::