Quantcast
Channel: Processing Forum
Viewing all articles
Browse latest Browse all 1768

How to get an If to work with audioinput?

$
0
0
Hello there! (Also I'am sorry if I posted this in the wrong section.)
I'am new to processing and new to coding in general and I decided to attempt to get an image to appear when the microphone detects a sound(very simple stuff). I believe the issue is that I have no idea what to have in the "If (???)". 

Any advice would be greatly appreciated, I've been trying to solve this issue for 1-2 days now but I'am completely stuck and I can´t find any tutorials to help me : / (Also plz excuse the horrid patch-work code, but I only want it to work, atm pretty/proper structure aint on my radar ^^ )

import ddf.minim.*;

Minim minim;
AudioInput input;

PImage img; // Deklarera en variabel för typ PImage

void setup() {
minim = new Minim(this);
input = minim.getLineIn();
size(640, 360);
  img = loadImage("moonwalk.jpg"); // Just random pic loaded in atm
}

void draw() {
background(0);
stroke(255);
for(int i = 0; i < input.bufferSize() - 1; i++){
point(i, 50 + input.mix.get(i)* 50);
if (i > 10) {image(img, 0, height/2, img.width/2, img.height/2); //This is where I believe the issue is
//Mainly I have no idea what the If should look like : /.
}

};
};

To recap: atm the picture just becomes visible instantly in the program and lies there like a dead fish, but I want the picture to only be visible when the microphone detects a sound.

Please take into consideration I'm just a newbie and not very good with coding terms yet.

Thanks for reading!

Viewing all articles
Browse latest Browse all 1768

Trending Articles