Loading...
Logo
Processing Forum
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!

Replies(3)

I don't know Minim enough to answer, but indeed, currently you just display the image when the loop index reaches a given value, which happen always...
Side note: as said in the Reference, put size() at the top of the setup() function.
Thank you for your reply. Yeah I must find a way to make the image only appear when called on when the program detects sound with the microphone.

Maybe a webcam would be easier to use? Hmm..
Never mind I solved it!

import ddf.minim.spi.*;
import ddf.minim.signals.*;
import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.ugens.*;
import ddf.minim.effects.*;

Minim minim;
AudioInput in;

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

void setup()
{
size(612, 300, P2D);
minim = new Minim(this);
minim.debugOn();

// get a line in from Minim, default bit depth is 16
in = minim.getLineIn(Minim.STEREO, 160);
img = loadImage("moonwalk.jpg"); // Ladda in bilden i programmet
}

void draw()
{
  background(0);
  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) {
     ellipse(10, 10, 10, 10);
     
     image(img, 0, height/2, img.width/2, img.height/2);
   //trigger AudioSample q
   }

println(in.left.level()*1); // signalvärdet *1000


}
}