File: mfcc-basic.ck

package info (click to toggle)
chuck 1.5.5.7-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 41,260 kB
  • sloc: cpp: 124,539; ansic: 35,893; javascript: 2,111; yacc: 609; makefile: 457; python: 174; perl: 86
file content (51 lines) | stat: -rw-r--r-- 1,547 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
//---------------------------------------------------------------------
// name: mfcc-basic.ck
// desc: mel-frequency cepstral coefficients
//       basic MFCC feature extractor
//
// version: need chuck version 1.5.0.0 or higher
// sorting: part of ChAI (ChucK for AI)
//
// uncomment for MFCC API:
// MFCC.help();
//
// author: Ge Wang (https://ccrma.stanford.edu/~ge/)
// date: Spring 2023
//---------------------------------------------------------------------

// synthesis / analysis network
adc => FFT fft =^ MFCC mfcc => blackhole;

// set number of coefficients in MFCC (how many we get out)
// 13 is a commonly used value; using less here for printing
7 => mfcc.numCoeffs;
// set number of mel filters in MFCC
10 => mfcc.numFilters;

// set FFT size
2048 => fft.size;
// set window type and size
Windowing.hann(fft.size()) => fft.window;
// our hop size (how often to perform analysis)
fft.size()::samp => dur HOP;

// let one FFT-size of time pass (to buffer)
fft.size()::samp => now;
// control loop
while( true )
{
    //----------------------------------------------------------------
    // upchuck() computes our MFCC, automatically computing upstream
    // dependencies connected to it using =^ (e.g., FFT)
    //----------------------------------------------------------------
    mfcc.upchuck();
    // print
    cherr <= "MFCC: ";
    // print the MFCC results
    for( int i; i < mfcc.fvals().size(); i++ )
    { cherr <= mfcc.fval(i) <= " "; }
    // endline
    cherr <= IO.newline();
    // advance time
    HOP => now;
}