Saturday, November 27, 2004

Thanksgiving Processing Code

This version has a timer for 10 seconds and stays on a level till the user hits it up to the next or until the 10 seconds are up. We will have a legend so they know what the colors mean.

// CODE
// SONIA V2.5 -- Audio Live Stream.
//http://www.pitaru.com/sonia/
//Goal is to capture audio data and parse into if/then statements
//Note the Sonia code folder goes into the sketch folder

BImage color1;
BImage color2;
BImage color3;
BImage color4;
BImage color5;

/*int numOfPics = 150; //number of images in image array for video sequence
BImage[] carlos = new BImage[numOfPics]; //new array of up to 224 photos

int numOfImages = 100; //number of images in image array for background images
BImage[] boxing = new BImage[numOfImages]; //new array of photos*/

int a = 0; // variable for counting through the display of photos
int picDislayTime = 10000; //time image is displayed in milliseconds
int movDisplayTime = 70; //time image is displayed in milliseconds

int whichImage = 0;
int startTime;
int startTimeMov;

float previousLevel = 0;
//float meterLevel = liveinput.getlevel

boolean showing = false;
boolean slowDown = false;

void setup(){

Sonia.start(this); // Start Sonia engine.
LiveInput.start(256); // Start LiveInput and return 256 FFT frequency bands.

size(640,480);
colorMode(RGB, 255, 255 ,255, 100);//need this comment later for tinting, etc

/*for(int j=0; j int m = j + 1;
carlos[j] = loadImage("boxing" + m + ".jpg");
}*/

color1 = loadImage("color1.gif");
color2 = loadImage("color2.gif");
color3 = loadImage("color3.gif");
color4 = loadImage("color4.gif");
color5 = loadImage("color5.gif");

/*for(int i=0; i int n = i + 1;
carlos[i] = loadImage("carlos" + n + ".gif");
}*/

startTime = millis();

}
void loop(){

background(0,0,0);
showImage(); //Show appropriate image based on input from microphone
if (showing) {
if (whichImage == 5) {
image(color5, 0, 0);
}
else if (whichImage == 4) {
image(color4,0,0);
}
else if (whichImage == 3) {
image(color3,0,0);
}
else if (whichImage == 2) {
image(color2,0,0);
}
else if (whichImage == 1) {
image(color1,0,0);
}
if (millis() - startTime > picDislayTime) {
showing = false;
}
if (1000 * LiveInput.getLevel(Sonia.LEFT) > previousLevel) {
showing = false;
}
}
}

// Safely close the sound engine upon Browser shutdown.
public void stop(){
Sonia.stop();
super.stop();
}

void showImage()//Show appropriate background image based on input from microphone
{
float meterDataLeft = 1000 * LiveInput.getLevel(Sonia.LEFT);
println(meterDataLeft);

if (!showing) {
if (meterDataLeft > 740) {
previousLevel= meterDataLeft;
whichImage = 5;
showing = true;
startTime = millis();
}
else if (meterDataLeft > 580) {
previousLevel= meterDataLeft;
whichImage = 4;
showing = true;
startTime = millis();
}
else if (meterDataLeft > 420) {
previousLevel= meterDataLeft;
whichImage = 3;
showing = true;
startTime = millis();
}
else if (meterDataLeft > 260) {
previousLevel= meterDataLeft;
whichImage = 2;
showing = true;
startTime = millis();

}
else if (meterDataLeft > 100) {
whichImage = 1;
showing = true;
startTime = millis();
previousLevel= meterDataLeft;




}
}
}