Using sound as a trigger
in
Core Library Questions
•
2 years ago
Im pretty much newb at this and have very little idea what im doing. I want the code to detect sounds and trigger a background change/another .wav file . I'm using getLineIn to detect the sounds but I cant figure out how to get that info to trigger the background/sound change.
My current code:
import ddf.minim.*;
Minim minim;
AudioInput in;
AudioSnippet s1;
AudioSnippet s2;
AudioSnippet s3;
AudioSnippet s4;
AudioSnippet s5;
int bask;
float sum;
float averageAudioInput;
float scaledAudioInput;
void setup(){
size(600,600,P2D);
background(0);
minim = new Minim(this);
s1 = minim.loadSnippet("andsword.wav");
s2 = minim.loadSnippet("Boom.wav");
s3 = minim.loadSnippet("Horn.wav");
s4 = minim.loadSnippet("twang.wav");
s5 = minim.loadSnippet("windandstring.wav");
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()
{
background(0);
stroke(255);
// draw the waveforms
for(int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*150, i+1, 50 + in.left.get(i+1)*150);
line(i, 150 + in.right.get(i)*150, i+1, 150 + in.right.get(i+1)*150);
}
}
void function(){
for (int i = 0; i < 1; i++){
float r = (1000*in.right.get(i));
float l = (1000*in.left.get(i+1));
float number = ((r*l)/2);
//println(number);
if ( number > 100) {
s1.rewind();
s1.play();
}
//if(1 > 150)
//{
//s1.rewind();
//s1.play();
//background(255);
}
}
void stop(){
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
there are two options in void function() that i was fiddling with but i couldn't get either to work... Any idea what should work, or what im doing wrong?
My current code:
import ddf.minim.*;
Minim minim;
AudioInput in;
AudioSnippet s1;
AudioSnippet s2;
AudioSnippet s3;
AudioSnippet s4;
AudioSnippet s5;
int bask;
float sum;
float averageAudioInput;
float scaledAudioInput;
void setup(){
size(600,600,P2D);
background(0);
minim = new Minim(this);
s1 = minim.loadSnippet("andsword.wav");
s2 = minim.loadSnippet("Boom.wav");
s3 = minim.loadSnippet("Horn.wav");
s4 = minim.loadSnippet("twang.wav");
s5 = minim.loadSnippet("windandstring.wav");
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()
{
background(0);
stroke(255);
// draw the waveforms
for(int i = 0; i < in.bufferSize() - 1; i++)
{
line(i, 50 + in.left.get(i)*150, i+1, 50 + in.left.get(i+1)*150);
line(i, 150 + in.right.get(i)*150, i+1, 150 + in.right.get(i+1)*150);
}
}
void function(){
for (int i = 0; i < 1; i++){
float r = (1000*in.right.get(i));
float l = (1000*in.left.get(i+1));
float number = ((r*l)/2);
//println(number);
if ( number > 100) {
s1.rewind();
s1.play();
}
//if(1 > 150)
//{
//s1.rewind();
//s1.play();
//background(255);
}
}
void stop(){
// always close Minim audio classes when you are done with them
in.close();
minim.stop();
super.stop();
}
there are two options in void function() that i was fiddling with but i couldn't get either to work... Any idea what should work, or what im doing wrong?
1