Action triggered by a sound level

edited February 2016 in Library Questions

I'm building an art installation controlled my processing. In the previous version of it, the sound played was triggered by a mouse press and a key press using MakeyMakey keyboard durning a test run. As my research is done about the reactions of the users to the experience, i'm shifting the code to something different. I'd like to make a final installation be triggered not by a key or mouse press, but by a sound of surrounding environment, so a sound would be played when the noise level captured by a microphone reaches a certain level.

What code could I use for it? Is there any tutorial about the microphone triggers?

Here is my code from the previous run if anyone would be keen to suggest changes.

import ddf.minim.*;
import ddf.minim.analysis.*;
import ddf.minim.effects.*;
import ddf.minim.signals.*;
import ddf.minim.spi.*;
import ddf.minim.ugens.*;
import processing.sound.*;
import processing.video.*;
Minim minim;
AudioPlayer one; //variable name
AudioPlayer male;
Capture cam;

void setup(){
//println(Capture.list());
  //size(640,360);
  fullScreen();

 cam = new Capture(this,1280,720,30);
  cam.start();


  minim = new Minim(this);
  one =minim.loadFile("german.wav");
 male=minim.loadFile("male.wav");

}

void draw(){

  //background(0);
 if (cam.available()) {
    cam.read();
if (mousePressed == true);    
     saveFrame();
  }


image(cam,0,0);

}

void mousePressed(){
 //if (mousePressed == true);
  one.play();
  cam.start();
  //  saveFrame();
}

void mouseReleased()
{
  if (mousePressed || true);
  one.close();
  one =minim.loadFile("german.wav");
  //cam.close() 
  //cam.stop(); 
}

void keyPressed()
{
  if (key == ' ' );
  male.play();

}

void keyReleased(){
  male =minim.loadFile("male.wav");
}

Answers

Sign In or Register to comment.