// in this example, we assume that width equals outputLen. int myWidth = 512; int myHeight = 512; int whatColor = 0; int xLoc = int(random(myWidth)); int yLoc = int(random(myHeight)); int oldXLoc = mouseX; int oldYLoc = mouseY; int newXLoc, newYLoc; boolean redFlag = true; boolean greenFlag = true; boolean blueFlag = true; boolean genFlag = false; int myRed = int(random(255)); int myGreen = int(random(255)); int myBlue = int(random(255)); int b =0; int[] rainX = new int[10]; int[] rainY = new int[10]; int[] rainSpeed = new int[10]; int [] rainWind = new int[10]; int[] particleFlag = new int[10]; int d; // SONIA V2.5 -- EXPERT EXAMPLE for Audio Live Stream. int outputLen = 256; // Define the length of the LiveOutput Stream. void setup(){ //size(512,200); // in this example, we assume that width equals outputLen. size(myWidth, myHeight); background(0); Sonia.start(this,11000); // Start Sonia in a lower sampling rate, for improved CPU performance. LiveOutput.start(outputLen,outputLen*2); // Start LiveOutput, define the Stream-length and Stream-buffer. LiveOutput.startStream(); // Start the streaming -activates the liveOutputEvent(){} for (d=0; d<10; d++){ rainX[d] = 10; rainY[d] = 10; rainSpeed[d] = 10; rainWind[d] = 1; particleFlag[d] = 0; } colorMode(RGB, 255); cursor(CROSS); } void loop(){ background(0); if(genFlag){ float rotation = sin((mouseY/3)*((TWO_PI)/outputLen)); rotate(rotation); smooth(); } // Draw the waveform of the sample-data for (int i=0; i < outputLen-1; i++) { int data = int(LiveOutput.data[i]); adjustColors(i); drawRain(i); } } // This event is automatically called every time new sample data is required by the LiveOutput stream. // You are expected to pass LiveOutput.data[] new values on each call. // Notice that LiveOutput.data.length is determined by the LiveOutput.start(streamLength)command in void setup() void liveOutputEvent(){ if(mousePressed){ // do the math for creating the sample data int freq = mouseX/27; // mouseX determines the amount of sine-cycles to be created. float oneCycle = (TWO_PI) / outputLen; // math to be used in sin() below. it changes the value range, to produce 1 sin cycle. float amp = 0.5; // determines the amplitude of our sample data. (values range from 0.0 to 1.0); // populate the liveOutput 'data' array with sample data for (int i=0; i < outputLen; i++) { LiveOutput.data[i] = amp* sin(float(i*oneCycle*freq)); whatColor = int(LiveOutput.data[i]*100); if (whatColor< 0){ whatColor = 0; } //println(whatColor); genFlag = true; //adjustColors(whatColor); } }else { // on mouseRelease, do a fade-out of the sample data by slowly 'shrinking' the array values. for (int i=0; i < outputLen; i++) { LiveOutput.data[i] *= 0.98; genFlag = false; } } } // Safely close the sound engine upon Browser shutdown. public void stop(){ Sonia.stop(); super.stop(); } void drawRain(int d){ noStroke(); rect(d+width/4, LiveOutput.data[d]*25, d+1+height/4, LiveOutput.data[(d+1)]*25); for(int c=0; c