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 › Problems with BeatDetect (ess sound library)
Page Index Toggle Pages: 1
Problems with BeatDetect (ess sound library) (Read 1114 times)
Problems with BeatDetect (ess sound library)
Feb 16th, 2010, 5:05pm
 
hi to all guys :-D
I'm writing an application for an university exam in which i've to represent the three points of the first guglielmo marconi's message. Each point (class dot) increase your diameter when a sound isOnset (my idea is that each different dot generate a wave (class onda) when minim detect a different sound frequency, hi, mid e low).
At begin of application i've initialized a boolean variable named "beatLow" as false. In draw() function this variable begin true when "isOnset" method begin true too:
Code:
if (beat.isOnset()) beatLow = true; 


Then with a conditional structure I call a .start method of the "Onda" class, one for each Dot.
Code:

if (beatLow = true) {
   onde2[ondattiva2].start(500, centerpoint, 255);
   ondattiva2++;
   onde1[ondattiva1].start(180, centerpoint, 255);
   ondattiva1++;
   onde3[ondattiva3].start(820, centerpoint, 255);
   ondattiva3++;
   if (ondattiva2 >= numOnde2) {
     ondattiva2 = 0;
   }
   if (ondattiva1 >= numOnde1) {
     ondattiva1 = 0;
   }
   if (ondattiva3 >= numOnde3) {
     ondattiva3 = 0;
   }
 }


The problem now is that the beatLow has becamed true and I don't know how make it false after that "one Onda" is started.  :-?

Can Anyone of you give me an hand with this code? I need that every time that beatDetect detect a frequency, an Onda start from the Dot.
I attach maincode and the two classes

Thanks very much everyone for his attention  :)
Andrea P.

Code:

// THE MAIN CODE

import ddf.minim.*;
import ddf.minim.analysis.*;

Dot dot;
Onda[] onde1;   // creazione dell'array dei cerchi concentrici 1
Onda[] onde2;   // creazione dell'array dei cerchi concentrici 2
Onda[] onde3;   // creazione dell'array dei cerchi concentrici 3
Minim minim;
AudioInput in;
AudioPlayer song;
BeatDetect beat;
int numOnde1 = 100;
int numOnde2 = 80;
int numOnde3 = 10;
int ondattiva1 = 0;
int ondattiva2 = 0;
int ondattiva3 = 0;
int dc = 50;

color co;
int centerpoint;

boolean record = false;
boolean beatMid = false;
boolean beatHigh = false;
boolean beatLow = false;

float one, two, three;

void setup() {
 size(1000, 450);
 centerpoint = height/2;
 
 minim = new Minim(this);
 minim.debugOn();
 in = minim.getLineIn(Minim.STEREO, 512);
 song = minim.loadFile("computerlove.mp3", 2048);
 song.play();
 beat = new BeatDetect();
 beat.detect(song.mix);
 
 onde2 = new Onda[numOnde2];   // crea e inizializza l'array dei cerchi 2
 onde1 = new Onda[numOnde1];   // crea e inizializza l'array dei cerchi 1
 onde3 = new Onda[numOnde3];   // crea e inizializza l'array dei cerchi 3
 
 for (int i=0; i<numOnde2; i++) {
   onde2[i] = new Onda();   // costruisce i cerchi 2
 }
 for (int g=0; g<numOnde1; g++) {
   onde1[g] = new Onda();   // costruisce i cerchi 1
 }
 for (int f=0; f<numOnde3; f++) {
   onde3[f] = new Onda();   // costruisce i cerchi 3
 }
}

void draw() {
 
 background(0);
 
 if (beat.isOnset()) beatLow = true;
 
 dot = new Dot(500,centerpoint,1);   // i tre
 dot = new Dot(180,centerpoint,0.95);   // costruisce
 dot = new Dot(820,centerpoint,1);   // punti
 
 for (int i=0; i<numOnde2; i++) {
   onde2[i].grow();
   onde2[i].display();
 }
 for (int z=0; z<numOnde1; z++) {
   onde1[z].grow();
   onde1[z].display();
 }
 for (int w=0; w<numOnde3; w++) {
   onde3[w].grow();
   onde3[w].display();
 }
 
 if(record) {
   endRecord();
   record = false;
 }
 
 if (beatLow = true) {
   onde2[ondattiva2].start(500, centerpoint, 255);
   ondattiva2++;
   onde1[ondattiva1].start(180, centerpoint, 255);
   ondattiva1++;
   onde3[ondattiva3].start(820, centerpoint, 255);
   ondattiva3++;
   if (ondattiva2 >= numOnde2) {
     ondattiva2 = 0;
   }
   if (ondattiva1 >= numOnde1) {
     ondattiva1 = 0;
   }
   if (ondattiva3 >= numOnde3) {
     ondattiva3 = 0;
   }
 }
}

void stop() {
 song.close();
 minim.stop();
 super.stop();
}


Code:

// THE DOT CLASS

class Dot {
 Dot (int xc, int yc, float moltiplic) {
   beat.detect(song.mix);
   float a = map(dc, 20, 80, 60, 255);
   fill(255, 255, 255);
   if (beat.isOnset()) dc = 80;
   ellipse(xc,yc,dc,dc);
   dc *= moltiplic;
   if ( dc < 20 ) dc = 20;
   noStroke();
   smooth();
 }
}


Code:

// THE ONDA CLASS

class Onda {
 float xo, yo, n;   // ascissa e ordinata del centro del cerchio
 float diametronda;   // diametro del cerchio
 boolean on = false;
 
 void start(float xpos, float ypos, color colore) {
   xo = xpos;
   yo = ypos;
   on = true;
   co = colore;
   diametronda = 55;
 }
 
 void grow() {
   if (on == true) {
     diametronda += 2;
     if (diametronda > height) {
       on = false;
     }
   }
 }
 
 void display() {
   if (on == true) {
     noFill();
     smooth();
     strokeWeight(5);
     ellipse(xo,yo,diametronda,diametronda);
     stroke(co);
   }
 }
}
Re: Problems with BeatDetect (ess sound library)
Reply #1 - Feb 16th, 2010, 5:22pm
 
i have two questions. why dont you use beat.isOnset in the first place instead of beatLow... ?

like :
if (beat.isOnset()) {
   onde2[ondattiva2].start(500, centerpoint, 255);

and the other quetsion is, what is wrong with just setting it back to false, when done?
Re: Problems with BeatDetect (ess sound library)
Reply #2 - Feb 16th, 2010, 7:52pm
 
Hi,
try deleting
Code:
 if (beat.isOnset()) beatLow = true;  



and changing Code:
 if (beatLow = true) { 


to
Code:
 if (beat.isOnset()) { 



that way, if beat.isOnset, it will grow; if it is not, it will just skip the Loop.
Re: Problems with BeatDetect (ess sound library)
Reply #3 - Feb 16th, 2010, 7:54pm
 
that was one of my questions... i was just not sure why he did it that way
Page Index Toggle Pages: 1