// Music Visualizer // Copyright 2008 Les Hall // This software is protected by the GNU General Public License // parameters [30, 20] @=> int chart_size[]; // size of vowel formant chart 1024 => int num_samples; // number of FFT samples 20 => int tail_length; // length of tail 30 => int led_size; // size of LEDs 400 => int slider_width; // width of sliders 100 => int slider_height; // height of sliders // variables // the patch adc => LPF lpf1 => FFT fft1 =^ RMS rms1 => blackhole; adc => HPF hpf1 => FFT fft2 =^ RMS rms2 => blackhole; adc => Gain volume => dac; 500.0 => lpf1.freq; 500.0 => hpf1.freq; num_samples => fft1.size => fft2.size; Windowing.hamming(num_samples/2) => fft1.window => fft2.window; // spork processes spork ~ adjust_volume(); spork ~ bouncing_ball(); // set up the display MAUI_View led_view; MAUI_LED led[chart_size[0]][chart_size[1]]; led_view.size(chart_size[0]*led_size, chart_size[1]*led_size); led_view.position(0, 50); led_view.name("Visualizer"); led_view.display(); for (int x; x now; } // adjust volume function void adjust_volume () { volume_slider.value() => volume.gain; while(true) { volume_slider => now; volume_slider.value() => volume.gain; } } // bounce a ball around on the screen function void bouncing_ball () { float x_pos; float y_pos; 0.000001 => float x_pos_max; 0.000001 => float y_pos_max; int x; int y; int tail[tail_length][2]; while (true) { // turn off LED led[tail[0][0]][tail[0][1]].unlight(); (num_samples/4)::samp => now; // shift tail for (1 => int i; i tail[i-1][j]; } } // get RMS values rms1.upchuck() @=> UAnaBlob blob1; blob1.fval(0) => x_pos; rms2.upchuck() @=> UAnaBlob blob2; blob2.fval(0) => y_pos; // find maximum values if (x_pos > x_pos_max) { x_pos => x_pos_max; } if (y_pos > y_pos_max) { y_pos => y_pos_max; } // determine chart position of ball ( (x_pos/x_pos_max)*chart_size[0]) $ int => x; if (x > chart_size[0]-1) { chart_size[0]-1 => x; } ( (y_pos/y_pos_max)*chart_size[1]) $ int => y; if (y > chart_size[1]-1) { chart_size[1]-1 => y; } chart_size[1]-1 - y => y; // add to tail x => tail[tail_length-1][0]; y => tail[tail_length-1][1]; // set ball color led[x][y].color(led[x][y].blue); led[x][y].light(); // time delay (num_samples/4)::samp => now; } }