// ChucK Brain // Copyright 2008 Les Hall // This software is protected by the GNU General Public License // parameters 10 => int num_delays; // number of delay UGens 4 => int num_layers; // number of layers (input + hidden + output) 1::second => dur total_delay; // the total delay duration // variables num_delays => int num_width; // width of neural net total_delay / num_delays => dur dly; // the delay amount // define the patch // define and hook up the delays Delay delay[num_delays]; // instantiate the delays adc => delay[0]; // hook the adc to the input for (1 => int i; i < num_delays; i++) { delay[i-1] => delay[i]; // chain them together in series } for (0 => int i; i < num_delays; i++) { delay[i].max (dly); // set the max delays delay[i].delay (dly); // set the delays } delay[num_delays-1] => blackhole; // suck out samples // define and hook up the neurons Gain nn_weights[num_layers][num_width][num_width]; // define the neural net weights Dyno nn_outputs[num_layers][num_width]; // define the neural net outputs for (0 => int neuron; neuron < num_width; neuron++ ) { delay[neuron] => nn_outputs[0][neuron]; // connect inputs to delay lines } for (1 => int layer; layer < num_layers; layer++) { for (0 => int neuron; neuron < num_width; neuron++ ) { for (0 => int weight; weight < num_width; weight++) { nn_outputs[layer-1][neuron] => nn_weights[layer][neuron][weight]; // connect weight input nn_weights[layer][neuron][weight] => nn_outputs[layer][neuron]; // connect weight output } } } for (0 => int layer; layer < num_layers; layer++) { for (0 => int neuron; neuron < num_width; neuron++ ) { nn_outputs[layer][neuron].limit (); // the activation function } } // define the output node and hook it up Dyno out => dac; for (0 => int neuron; neuron < num_width; neuron++ ) { nn_outputs[num_layers-1][neuron] => out; // connect all neural net outputs to out } out.limit (); // set output as limiter // seed the neural net weights for (1 => int layer; layer < num_layers; layer++) { for (0 => int neuron; neuron < num_width; neuron++ ) { for (0 => int weight; weight < num_width; weight++) { nn_weights[layer][neuron][weight].gain (Std.randf ()); } } } // time loop while (true) { // time delay 1::ms => now; }