Machine "Listening" in Supercollider

Posted on 2011-03-22 11:42:34

The code below calculates the MFCCs, spectral centroid, and spectral flatness for an input signal and sends the results over OSC. There’s one problem with it as written, which is that the MFCCs are not sent (or calculated) the first time you run the code, but if you stop it and start it again, they are calculated and sent properly. Still trying to figure that one out.

 s = Server.local.boot;
 // Setup address and buffer
 n = NetAddr("", 57130);
 b = Buffer.alloc(s, 1024, 1);
 // Setup control buses
 ~mfccBus = Bus.alloc(\control, s, 13);
 ~specCentroidBus = Bus.alloc(\control, s, 1);
 ~specFlatnessBus = Bus.alloc(\control, s, 1);
 SynthDef("listenSynth", {|name, buffer = 0, inputChannel = 0, specCentroidBusName = nil, specFlatnessBusName = nil, mfccBusName = nil|
     var in, fft, specCentroid, specFlatness, mfcc;
     in =;
     fft = FFT(buffer, in);
     specCentroid =;
     specFlatness =;
     mfcc =;
     // Output computed values to buses, mfcc);, specCentroid);, specFlatness);
 // Routine that sends the values over OSC
 // Note the "*" in the code for the MFCCs; this is needed to "flatten" the array into a series of numbers that Supercollider likes.
 r ={{
             n.sendMsg("/specCentroid", val);
             n.sendMsg("/specFlatness", val);
         ~mfccBus.getn(13, {|val| {n.sendMsg("/mfcc", *val);}.defer});
 // Create the synth
 ~listenSynth =\listenSynth, [\name, "creature", \buffer, b, \specCentroidBusName, ~specCentroidBus, \specFlatnessBusName, ~specFlatnessBus, \mfccBusName, ~mfccBus]);
 // Clear everything out


Submit comment