FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Topics & Contributions
   Sound
(Moderators: pitaru, REAS)
   problem - sending data from getLevel
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: problem - sending data from getLevel  (Read 454 times)
mintra
Guest
Email
problem - sending data from getLevel
« on: Jan 23rd, 2004, 6:56pm »

I'm very new at processing and have very little programming background, might not understand any technical term.
This is the problem:
i use mic to get the sound from people, i need to use the data from Level of the sound.
but i couldn't send the data to the class i create, the code is below :
 
======================================================
// CODE// SONIA V2.5 -- Audio Live Stream.
 
BFont metaBold;  
Txt mintraTxt;
int left2;
float left;
float left1;
 
void setup(){
   size(512,200);
   Sonia.start(this); // Start Sonia engine.
   LiveInput.start(2); // Start LiveInput and return 256 FFT frequency bands.
   mintraTxt = new Txt(left);
}
 
void loop(){
   background(0,30,0);
   // Get Level from microphone
   float meterData = LiveInput.getLevel();
   float left = meterData*3*height/4;
   // Value Range: float from 0.0 to 1.0
   // draw a volume-meter  
   strokeWeight(width);
   stroke(0,100,0);
   line(width/2 - 120, height, width/2 - 120 , height - left);
   mintraTxt.write();
}
 
class Txt {
   int left2;
   
   Txt(float _left1) {
     left1 = _left1;
   }
   
   void write() {
     
   metaBold = loadFont("Meta-Bold.vlw.gz");
   //float right = meterDataRight*height;
   int left2 = int(left1);
   textFont(metaBold, 24);  
   text(left2, width/2, height/2);
   }
}
 
// Safely close the sound engine upon Browser shutdown.
public void stop(){
    Sonia.stop();
    super.stop();
}
======================================================
 
this is a test on sending the getLevel value out by text(), but i couldn't exactly get any value from it.
is there any mistake in my code?
could you help me pls!!!
 
 
 
 
mKoser

WWW Email
Re: problem - sending data from getLevel
« Reply #1 on: Jan 23rd, 2004, 8:03pm »

hi mintra,
 
i've just run quickly through your code, and here's a few comments:
 
a. if you define (int myVar; or float myVar; etc.) a variable in the beginning (before setup()) you should not define it within the loop, setup, class or whatever, if you define it again, it becomes a private variable to that method (within the brackects of, say, loop(){}).
 
b. you can pass-in variables to the class-methods (your write-method within the Txt-class). I've changed it so it the code does that now instead of relying on "global" varibles.
 
- - -
 
anyway, i hope this gets you going, i hope i didn't change too much in your code.
 
Code:

BFont metaBold;
float left;
 
Txt mintraTxt;
 
void setup(){
  size(512,200);
  Sonia.start(this); // Start Sonia engine.
  LiveInput.start(2); // Start LiveInput and return 256 FFT frequency bands.
  mintraTxt = new Txt();
}
 
void loop(){
  background(0,30,0);
  
  // Get Level from microphone
  // i've simplified this a bit
  left = LiveInput.getLevel()*3*height/4;
  
  // Value Range: float from 0.0 to 1.0
  // draw a volume-meter
  strokeWeight(width);
  stroke(0,100,0);
  line(width/2 - 120, height, width/2 - 120 , height - left);
  
  // pass the variable 'left' to the Txt-object
  // in order for this to be printed on the screen
  mintraTxt.write(left);
}
 
class Txt {
  Txt() {
  }
 
  // pass in a floating point, which then will be printed on the screen (the num variable)
  void write(float num) {
    metaBold = loadFont("Meta-Bold.vlw.gz");
    textFont(metaBold, 24);
    text(num, width/2, height/2);
  }
}
 
// Safely close the sound engine upon Browser shutdown.
public void stop(){
  Sonia.stop();
  super.stop();
}

 
please let us know when you have stuff for us to see, or any other problems!
 
+ mikkel
« Last Edit: Jan 23rd, 2004, 8:04pm by mKoser »  

mikkel crone koser | www.beyondthree.com | http://processing.beyondthree.com
mintra
Guest
Email
Re: problem - sending data from getLevel
« Reply #2 on: Jan 24th, 2004, 12:44am »

You save my life! Thank you very much. I need to learn a lot more about programming.
 
Pages: 1 

« Previous topic | Next topic »