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.
IndexProgramming Questions & HelpSound,  Music Libraries › Controlling a threshold using different volumes
Page Index Toggle Pages: 1
Controlling a threshold using different volumes (Read 532 times)
Controlling a threshold using different volumes
Jun 10th, 2009, 11:14am
 
hi! i'm doing an installation for a chool project by capturing webcam image (JMyron) and turning it black and white using a threshold filter and some other stuff.

my problem is that i want to control the level of my threshold using volumes.

If the volume is loud the image gets darker, if the volume is low the image gets whiter.

I found an Ess example using FFT to be able to capture mic activity, but i cant seem to use the volume of that input to control my threshold.

I tested the filters using a keypressed function (CASE UP AND CASE DOWN) and it works. so my problem is on using the volume to get the same effect.

Ill put the code here, i'm not sure if there's a problem on doing that, if there is i'm sorry, but i'm kind of desperate, i've trie lots of things and can't seem to get it done.

_______________________________________________________

import JMyron.*;
import krister.Ess.*;

//exemplo 2

JMyron m;

int imgWidth, imgHeight;
PImage img1, img2;
float level;

int bufferSize;
int steps;
float limitDiff;
int numAverages=32;
float myDamp=.1f;
float maxLimit,minLimit;

FFT myFFT;
AudioInput myInput;


void setup(){
 imgWidth = 320;
 imgHeight = 240;
 img1 = new PImage (imgWidth, imgHeight);
 img2 = new PImage (imgWidth, imgHeight);
 
 level= 0.5;
 
 size(800,400,JAVA2D);
 
 m = new JMyron();
 
 m.start(imgWidth, imgHeight);
 
 m.findGlobs(0);
 
  // start up Ess
 Ess.start(this);  

 // set up our AudioInput
 bufferSize=512;
 myInput=new AudioInput(bufferSize);

 // set up our FFT
 myFFT=new FFT(bufferSize*2);
 myFFT.equalizer(true);

 // set up our FFT normalization/dampening
 minLimit=.005;
 maxLimit=.05;
 myFFT.limits(minLimit,maxLimit);
 myFFT.damp(myDamp);
 myFFT.averages(numAverages);

 // get the number of bins per average
 steps=bufferSize/numAverages;

 // get the distance of travel between minimum and maximum limits
 limitDiff=maxLimit-minLimit;

 frameRate(25);        

 myInput.start();

 
}

void draw() {
 background(235);
 m.update();
 m.imageCopy(img1.pixels);
 img1.updatePixels();
 image(img1, 50, 60);
 
 m.imageCopy(img2.pixels);
  img2.updatePixels();
  img2.filter(GRAY);
  img2.filter(THRESHOLD, level);
  img2.filter(ERODE);
  img2.filter(DILATE);
 image(img2, 430, 60);
 
}

void settings()
{
 m.settings();
}

public void stop() {
 
 m.stop();
 super.stop();
}

void volume()
{
 if(myInput.volume >= 30)
 {
   level += 0.005;
   if(level > 0.995) level = 0.995;
   println(level);
   
 }
   else if(myInput.volume <= 29)
   {
   level -= 0.005;
   if(level < 0.005) level = 0.005;
   println(level);
   }
   
 

}

_______________________________________________________-

thank you all!!
Page Index Toggle Pages: 1