| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: features-combined.ck |
| 3 |
// desc: extracting multiple features; collect into one vector |
| 4 |
// e.g., Centroid, Flux, RMS, MFCC |
| 5 |
// |
| 6 |
// author: Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 7 |
// date: Spring 2023 |
| 8 |
//--------------------------------------------------------------------- |
| 9 |
|
| 10 |
// audio input into a FFT |
| 11 |
adc => FFT fft; |
| 12 |
// a thing for collecting multiple features into one vector |
| 13 |
FeatureCollector combo => blackhole; |
| 14 |
// add spectral feature: Centroid |
| 15 |
fft =^ Centroid centroid =^ combo; |
| 16 |
// add spectral feature: Flux |
| 17 |
fft =^ Flux flux =^ combo; |
| 18 |
// add spectral feature: RMS |
| 19 |
fft =^ RMS rms =^ combo; |
| 20 |
// add spectral feature: MFCC |
| 21 |
fft =^ MFCC mfcc =^ combo; |
| 22 |
|
| 23 |
// set number of coefficients in MFCC (how many we get out) |
| 24 |
// 13 is a commonly used value; using less here for printing |
| 25 |
13 => mfcc.numCoeffs; |
| 26 |
// set number of mel filters in MFCC |
| 27 |
10 => mfcc.numFilters; |
| 28 |
|
| 29 |
// set FFT size |
| 30 |
2048 => fft.size; |
| 31 |
// set window type and size |
| 32 |
Windowing.hann(fft.size()) => fft.window; |
| 33 |
// our hop size (how often to perform analysis) |
| 34 |
fft.size()::samp => dur HOP; |
| 35 |
|
| 36 |
// let one FFT-size of time pass (to buffer) |
| 37 |
fft.size()::samp => now; |
| 38 |
// control loop |
| 39 |
while( true ) |
| 40 |
{ |
| 41 |
//----------------------------------------------------------------- |
| 42 |
// a single upchuck() will trigger analysis on everything |
| 43 |
// connected upstream from combo via the upchuck operator (=^) |
| 44 |
// the total number of output dimensions is the sum of |
| 45 |
// dimensions of all the connected unit analyzers |
| 46 |
//----------------------------------------------------------------- |
| 47 |
combo.upchuck(); |
| 48 |
|
| 49 |
// print |
| 50 |
cherr <= "features (" <= combo.fvals().size() <= " total dims): "; |
| 51 |
// print the MFCC results |
| 52 |
for( int i; i < combo.fvals().size(); i++ ) |
| 53 |
{ cherr <= combo.fval(i) <= " "; } |
| 54 |
// endline |
| 55 |
cherr <= IO.newline(); |
| 56 |
|
| 57 |
// advance time |
| 58 |
HOP => now; |
| 59 |
} |