SuperCollider CLASSES (extension)

PV_MagSmooth
ExtensionExtension

Smooth spectral magnitudes over time

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))

Class Methods

*new (buffer, factor: 0.1)

Arguments:

chain

an fft chain

factor

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

Inherited class methods

Instance Methods

Inherited instance methods

Examples

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;