/** by russ Based on the LiveInput example by Amit Pitaru, this sketch uses sound to "awaken" the images. */ // LiveInput example for Processing V90 // Description: Shows FFT spectrum and volume level for the active sound-input on your mahcine. // For PC: use the 'Sounds & Audio Devices' menu in the control panel to choose your input; Mic, wave, etc. // For Mac: the current microphone device will be used as input. // By: Amit Pitaru, July 16th 2005 import pitaru.sonia_v2_9.*; // automcatically added when importing the library from the processing menu. PImage b; PImage c; PImage d; PImage e; PImage f; PImage g; PImage h; PImage i; int foo = 0; void setup(){ size(720,480); Sonia.start(this); // Start Sonia engine. LiveInput.start(256); // Start LiveInput and return 256 FFT frequency bands. b = loadImage("port_bg_low_1.1.jpg"); c = loadImage("port_bg_low_1.2.jpg"); d = loadImage("port_bg_low_1.3.jpg"); e = loadImage("port_bg_low_1.4.jpg"); f = loadImage("port_bg_low_1.5.jpg"); g = loadImage("port_bg_low_1.6.jpg"); h = loadImage("port_bg_low_1.7.jpg"); i = loadImage("port_bg_low_1.8.jpg"); } void draw(){ background(0,0,0); getMeterLevel(); // Show meter-level reading for Left/Right channels. getSpectrum(); // Show FFT reading } void getSpectrum(){ strokeWeight(2 ); stroke(52, 46, 41); // populate the spectrum array with FFT values. LiveInput.getSpectrum(); // draw a bar for each of the elements in the spectrum array. // Note - the current FFT math is done in Java and is very raw. expect optimized alternative soon. for ( int i = 0; i < LiveInput.spectrum.length; i++){ line(i*5, height, i*5, height - LiveInput.spectrum[i]/10); } } void getMeterLevel(){ // get Peak level for each channel (0 -> Left , 1 -> Right) // Value Range: float from 0.0 to 1.0 // Note: use inputMeter.getLevel() to combine both channels (L+R) into one value. float meterData = LiveInput.getLevel(); println(meterData); meterData *=100; if (meterData < 3 ) { image(b, 0, 0, 720, 480); } else if (meterData < 5 ) { image(c, 0, 0, 720, 480); } else if (meterData < 7 ) { image(d, 0, 0, 720, 480); } else if (meterData < 10 ) { image(e, 0, 0, 720, 480); } else if (meterData < 13 ) { image(f, 0, 0, 720, 480); } else if (meterData < 16 ) { image(g, 0, 0, 720, 480); } else if (meterData < 18 ) { image(h, 0, 0, 720, 480); } else { image(i, 0, 0, 720, 480); } } // Safely close the sound engine upon Browser shutdown. public void stop(){ Sonia.stop(); super.stop(); }