import pitaru.sonia_v2_9.*; // automcatically added when importing the library from the processing menu. void setup(){ size(1024,400); noStroke (); Sonia.start(this); // Start Sonia engine. LiveInput.start(256); // Start LiveInput and return 256 FFT frequency bands. } void draw(){ getMeterLevel(); // Show meter-level reading for Left/Right channels. getSpectrum(); // Show FFT reading } void getSpectrum(){ // 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++){ ellipse (i*20, height/2, LiveInput.spectrum[i]/30, LiveInput.spectrum[i]/30); } } 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 meterDataLeft = LiveInput.getLevel(0); float meterDataRight = LiveInput.getLevel(1); // draw a volume-meter for each channel. float left = meterDataLeft*255; float right = meterDataRight*255*2; fill(left); background(255-left); } // Safely close the sound engine upon Browser shutdown. public void stop(){ Sonia.stop(); super.stop(); }