Overview
Here you can find an introduction to Fast Fourier Transformation in SuperCollider and some examples.
Content
To analyse an Audio-Signal via a FFT you use the FFT UGen. This UGen needs a Buffer, to save the analysis data. You can either use a global Buffer, declared and allocated outside the SynthDef or Function, or use a LocalBuf, which creates a Buffer when the Synth is made and local to this UGen graph.
This is a simple example where a Audio-Signal is analysed via FFT and resynthesized via IFFT. By default all FFT UGens work with mono signals.
// load a soundfile into a mono buffer
~samp = Buffer.readChannel(s, "/my_samp.wav", channels:[0]);
~samp.play;
// LocalBuf creates local Buffer when the Synth is created on the Server
(
x = {
var sig, chain;
sig = PlayBuf.ar(1, ~samp, BufRateScale.ir(~samp), loop: 1);
chain = FFT(LocalBuf(2048), sig); // this returns a Buffer with the FFT information of the input signal, with number of bins == size of the bufferr
sig = IFFT(chain); // resynthesize the original signal
}.play;
)Example with a Phase Vocoder UGen, which transforms the FFT data.
(
x = {
var sig, chain;
sig = PlayBuf.ar(1, ~samp, BufRateScale.ir(~samp), loop: 1);
chain = FFT(LocalBuf(16384), sig);
chain = PV_BinScramble(chain, 0.75, 0.9, Impulse.kr(0.5));
sig = IFFT(chain)!2;
}.play;
)To work with multichannel Files, FFT takes an array with buffer of the size of the nummer of channels you need.
// load a soundfile into a multichannel buffer
~samp = Buffer.read(s, "/Users/philippneumann/Documents/Kompositionen/SommerAmU/pvn/sndfls/harp_clean/01_clean.wav");
~samp.play;
(
x = {
var sig, chain;
sig = PlayBuf.ar(1, ~samp, BufRateScale.ir(~samp), loop: 1);
chain = FFT({LocalBuf(1024)} ! 2, sig);
chain = PV_BinScramble(chain, 0.75, 0.9, Impulse.kr(0.5));
sig = IFFT(chain)!2;
}.play;
)