MFCC				mel frequency cepstral coefficients

#coeff1, coeff2, ... = MFCC.kr(chain, numcoeff=13)

chain [fft] - Audio input to track, which has been pre-analysed by the FFT UGen; see examples below for the expected FFT size
numcoeff [s] - Number of coefficients, defaults to 13, maximum of 42; more efficient to use less of course!  

Generates a set of MFCCs; these are obtained from a band-based frequency representation (using the Mel scale by default), and then a discrete cosine transform (DCT). The DCT is an efficient approximation for principal components analysis, so that it allows a compression, or reduction of dimensionality, of the data, in this case reducing 42 band readings to a smaller set of MFCCs. A small number of features (the coefficients) end up describing the spectrum. The MFCCs are commonly used as timbral descriptors. 

Output values are somewhat normalised for the range 0.0 to 1.0, but there are no guarantees on exact conformance to this. Commonly, the first coefficient will be the highest value. 

//Technical note: The 0th coefficient is not generated as it consists of multiplying all bands by 1 and summing

//assumes hop of half fftsize, fine
b = Buffer.alloc(s,1024,1); //for sampling rates 44100 and 48000
//b = Buffer.alloc(s,2048,1); //for sampling rates 88200 and 96000
d=Buffer.read(s,Document.current.dir ++ "/pinknoise2.wav");
d=Buffer.read(s,Document.current.dir ++ "/whitenoise2.wav");
d=Buffer.read(s,Document.current.dir ++ "/sinetest_stepping2.wav");
d.play
d
(
x= {
var in, fft, array;

in= PlayBuf.ar(1,d,BufRateScale.kr(d),1,0,1);

//in = SoundIn.ar(0); 

fft = FFT(b, in, 512, 1);

array=MFCC.kr(fft); 

array.size.postln; 

Out.kr(0,array); 

Out.ar(0,Pan2.ar(in)); 
}.play
)

c= Bus.new('control', 0, 13); 

//poll coefficients
c.getn(13,{arg val; {val.plot;}.defer}); 

//Continuous graphical display of MFCC values; free routine before closing window

(
var ms; 

w=Window.new("Thirteen MFCC coefficients", Rect(200,400,700,300));

ms= MultiSliderView.new(w, Rect(10,10,660,280));

ms.value_(Array.fill(13,0.0));
ms.valueThumbSize_(40.0);
ms.indexThumbSize_(40.0);
ms.gap_(0);

w.front;

r= {

inf.do{

c.getn(13,{arg val; val.postln; {ms.value_(val*0.9)}.defer}); 

0.02.wait; //25 frames per second
};

}.fork;

)

//tidy up
(
r.stop;
b.free;
c.free;
x.free;
w.close;
)