| 1 |
//--------------------------------------------------------------------- |
| 2 |
// name: mfcc-basic.ck |
| 3 |
// desc: mel-frequency cepstral coefficients |
| 4 |
// basic MFCC feature extractor |
| 5 |
// |
| 6 |
// version: need chuck version 1.5.0.0 or higher |
| 7 |
// sorting: part of ChAI (ChucK for AI) |
| 8 |
// |
| 9 |
// uncomment for MFCC API: |
| 10 |
// MFCC.help(); |
| 11 |
// |
| 12 |
// author: Ge Wang (https://ccrma.stanford.edu/~ge/) |
| 13 |
// date: Spring 2023 |
| 14 |
//--------------------------------------------------------------------- |
| 15 |
|
| 16 |
// synthesis / analysis network |
| 17 |
adc => FFT fft =^ MFCC mfcc => blackhole; |
| 18 |
|
| 19 |
// set number of coefficients in MFCC (how many we get out) |
| 20 |
// 13 is a commonly used value; using less here for printing |
| 21 |
7 => mfcc.numCoeffs; |
| 22 |
// set number of mel filters in MFCC |
| 23 |
10 => mfcc.numFilters; |
| 24 |
|
| 25 |
// set FFT size |
| 26 |
2048 => fft.size; |
| 27 |
// set window type and size |
| 28 |
Windowing.hann(fft.size()) => fft.window; |
| 29 |
// our hop size (how often to perform analysis) |
| 30 |
fft.size()::samp => dur HOP; |
| 31 |
|
| 32 |
// let one FFT-size of time pass (to buffer) |
| 33 |
fft.size()::samp => now; |
| 34 |
// control loop |
| 35 |
while( true ) |
| 36 |
{ |
| 37 |
//---------------------------------------------------------------- |
| 38 |
// upchuck() computes our MFCC, automatically computing upstream |
| 39 |
// dependencies connected to it using =^ (e.g., FFT) |
| 40 |
//---------------------------------------------------------------- |
| 41 |
mfcc.upchuck(); |
| 42 |
// print |
| 43 |
cherr <= "MFCC: "; |
| 44 |
// print the MFCC results |
| 45 |
for( int i; i < mfcc.fvals().size(); i++ ) |
| 46 |
{ cherr <= mfcc.fval(i) <= " "; } |
| 47 |
// endline |
| 48 |
cherr <= IO.newline(); |
| 49 |
// advance time |
| 50 |
HOP => now; |
| 51 |
} |