We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexDiscussionExhibition › Uploading images with AudioInput
Page Index Toggle Pages: 1
Uploading images with AudioInput (Read 718 times)
Uploading images with AudioInput
Jun 18th, 2009, 6:58am
 
Hello everybody, I'm new with Processing and I'm having some troubles with my code.. I would like Processing to upload different images, depending on the value of the AudioInput.. Depending on the frequency of the sound, the image should change.
Here is the code, but what I can see is only a white square so I guess that something is wrong.. Maybe the values? How can I get the frequencies of a live sound?

Thanks for your advices, and.. sorry for my English!   Roll Eyes

PImage a;
import ddf.minim.*;

Minim minim;
AudioInput in;
int val;

void setup()
{
size (600,600,P2D);
a = loadImage("2.jpg");
background (255,255,255);

minim = new Minim(this);
minim.debugOn();

// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 512);
}

void draw()
{
val=Math.abs(int(in.mix.get(0)*512));
println(val);
if(val > 0 && val < 85){loadImage("1.jpg");
}
else { if (val > 85 && val < 170) {a=loadImage ("2.jpg");
}
}
if (val > 170 && val < 255) {a=loadImage ("3.jpg");
}
else { if (val > 255 && val < 340) {a=loadImage ("4.jpg");
}
}
if (val > 340 && val < 425) {a=loadImage ("5.jpg");
}
else { if (val > 425 && val < 512) {a=loadImage ("6.jpg");
}
}
}


void stop()
{
// always close Minim audio classes when you are done with them
in.close();
minim.stop();

super.
stop();
}
Re: Uploading images with AudioInput
Reply #1 - Jun 18th, 2009, 7:16am
 
Note 1: Exhibition is a place to show finished sketches, not to ask for help. I think this message will be moved by a moderator.
Note 2: once you have an image, you can display it with image() function.
Note 3: for a small amount of images, it might be more efficient to load (and not "upload") the images in setup() (in an array) instead of repeatedly in draw().
Page Index Toggle Pages: 1