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 & HelpSyntax Questions › missing semicolon
Page Index Toggle Pages: 1
missing semicolon? (Read 1242 times)
missing semicolon?
Dec 29th, 2009, 8:57am
 
Hello i have a problem with this code. i got it as it is and i have not to much knowledge to repair it.
so when i run it i have the error "Syntrax error, maybe a missing semicolon?" what is wrong??

were is the cobe:

        import krister.Ess.*;
   import processing.serial.*;

   // “bufferSize” defines the buffer used to read and
   // process the signal from the microphone
   int bufferSize;

   // “steps” and “limitDiff” define the scale of the reading
   int steps;
   float limitDiff;

   // numAverages defines the number of averages computed between
   // the reading of all the frequency bands
   int numAverages=3;

   // the value of “Damp” defines on how similar and smooth should be
   // the frequency band

   float myDamp=.1f;

   // “maxLimit” and “minLimit” define the lowest and the highest value
   // of the reading scale
   float maxLimit,minLimit;

   // “bass”, “medium” and “high” are the variable that will store the
   // output value to be sent to the Arduino board
   int bass;
   int medium;
   int high;

   // “myPort” is dedicated to the Serial port
   Serial myPort;

   // “myFFT” is dedicated to store the array with all the readings
   FFT myFFT;

   // “AudioInput” is the variable to store the audio
   AudioInput myInput;
   
       void setup () {
   size(700,221);// start up Ess
   Ess.start(this);

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

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

   // 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();
   myPort = new Serial(this, Serial.list()[2], 115200);
   }
   
       void draw() {
   background(0,0,255);

   // draw the waveform

   noStroke();
   fill(255,128);

   // draw the spectrum

   for (int i=0; i
   rect(10+i,10,1,myFFT.spectrum[i]*200);
   }
   
       // draw our averages
   for(int i=0; i)

   {
   int tuning=74;
   fill(255,128);
   rect(10+i*steps,10,steps,myFFT.averages[i]*200);
   fill(255);
   rect(10+i*steps,(int)(10+myFFT.maxAverages[i]*200),steps,1);
   rect(10+i*steps,10,1,200);
   
   int bass = int(myFFT.averages[0]*tuning);
int medium = int(myFFT.averages[1]*tuning);
int high = int(myFFT.averages[2]*tuning);
println(byte(bass+33));
println(medium+108);
println(high+183);
myPort.write(byte(bass+33));
myPort.write(byte(medium+108));
myPort.write(byte(high+183));
}

public void audioInputData(AudioInput theInput) {
myFFT.getSpectrum(myInput);
}
Re: missing semicolon?
Reply #1 - Dec 29th, 2009, 9:27am
 
Code:

for (int i=0; i
rect(10+i,10,1,myFFT.spectrum[i]*200);
}


For-loop is incomplete.
Re: missing semicolon?
Reply #2 - Dec 29th, 2009, 11:01am
 
what i could fill to complete it?
Re: missing semicolon?
Reply #3 - Dec 29th, 2009, 11:34am
 
for (int i=0; i

it has to be something like that

for (int i=0; i>X;i++);

where i>X could be anything else like i< or <= etc. and the i++ part could be changed to i+=10 for example or i--
but i++ is the most commoin if you just want to loop something X times.
Re: missing semicolon?
Reply #4 - Dec 30th, 2009, 7:20pm
 
This is the original post which i got the code, it might help you. i try everithing but..nothing!!

The final Processing code. To process the sound I used the ESS library that reads the spectrum of a sound source. The website of this library can be found here: Link.
The following code is taken by the library website, and changed by me to make it work with my installation
Here I import the Ess library and the serial one, and initialize all the variables needed for the script to run.


   import krister.Ess.*;
   import processing.serial.*;

   // “bufferSize” defines the buffer used to read and
   // process the signal from the microphone
   int bufferSize;

   // “steps” and “limitDiff” define the scale of the reading
   int steps;
   float limitDiff;

   // numAverages defines the number of averages computed between
   // the reading of all the frequency bands
   int numAverages=3;

   // the value of “Damp” defines on how similar and smooth should be
   // the frequency band

   float myDamp=.1f;

   // “maxLimit” and “minLimit” define the lowest and the highest value
   // of the reading scale
   float maxLimit,minLimit;

   // “bass”, “medium” and “high” are the variable that will store the
   // output value to be sent to the Arduino board
   int bass;
   int medium;
   int high;

   // “myPort” is dedicated to the Serial port
   Serial myPort;

   // “myFFT” is dedicated to store the array with all the readings
   FFT myFFT;

   // “AudioInput” is the variable to store the audio
   AudioInput myInput;

At this point I start with the setup of the stage, I initialize the libraries and call all the functions to read the audio

   void setup () {
   size(700,221);// start up Ess
   Ess.start(this);

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

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

   // 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();
   myPort = new Serial(this, Serial.list()[2], 115200);
   }

I start by drawing on the stage the waveform and the spectrum

   void draw() {
   background(0,0,255);

   // draw the waveform

   noStroke();
   fill(255,128);

   // draw the spectrum

   for (int i=0; i
   rect(10+i,10,1,myFFT.spectrum[i]*200);
   }

Then we start to calculate the averages. As I set up the numAverages to be 3, the loop will continue as long as the “i” variable will not reach the number of 3. I declare the variable “tuning”, that I always use as a multiplier in case the signals that I get become too low. Than I draw 3 rectangles, each one set to be tall as the average of the first, second and third frequency range.

   // draw our averages
   for(int i=0; i)

   {
   int tuning=74;
   fill(255,128);
   rect(10+i*steps,10,steps,myFFT.averages[i]*200);
   fill(255);
   rect(10+i*steps,(int)(10+myFFT.maxAverages[i]*200),steps,1);
   rect(10+i*steps,10,1,200);

Now, I start to retrieve the final values that I have to send to the board. I transform the value into an integer, as the “myFFT” variable was decleares as a float, and multiply the result by the “tuning” variable, that I can easily adjust if I should need to do so. I print everything on the Processing console for debugging, and then send the values to Arduino. Note that I added 33 to the “bass” variable, 108 to the “medium” and 183 to the “high”. I did so because Arduino will read the range between 33 and 108 and assign the value to the pin dedicated for the bass fan.


   int bass = int(myFFT.averages[0]*tuning);
   int medium = int(myFFT.averages[1]*tuning);
   int high = int(myFFT.averages[2]*tuning);
   println(byte(bass+33));
   println(medium+108);
   println(high+183);
   myPort.write(byte(bass+33));
   myPort.write(byte(medium+108));
   myPort.write(byte(high+183));
   }

At the end I call the function that reads the input from the soundcard

   public void audioInputData(AudioInput theInput) {
   myFFT.getSpectrum(myInput);
   }
Re: missing semicolon?
Reply #5 - Dec 30th, 2009, 7:43pm
 
like we said. these are not for loops :

 for (int i=0; i
  rect(10+i,10,1,myFFT.spectrum[i]*200);
  }


or

 for(int i=0; i)

  {


maybe take a look at http://processing.org/reference/for.html
Re: missing semicolon?
Reply #6 - Dec 30th, 2009, 8:16pm
 
ok. i will work on it
thank you for your time
Re: missing semicolon?
Reply #7 - Dec 30th, 2009, 8:29pm
 
if you would tell us what you are actually doing there, i could tell you what to do. but it doesnt make much sense
Re: missing semicolon?
Reply #8 - Dec 31st, 2009, 3:24am
 
Starting with the original code from Reply 4 then to draw the spectrum the following should work.
Code:

for (int i=0; i < myFFT.spectrum.length; i++){
  rect(10+i,10,1,myFFT.spectrum[i]*200);
}


From the comments
Quote:
Then we start to calculate the averages. As I set up the numAverages to be 3, the loop will continue as long as the “i” variable will not reach the number of 3. I declare the variable “tuning”, that I always use as a multiplier in case the signals that I get become too low. Than I draw 3 rectangles, each one set to be tall as the average of the first, second and third frequency range.


On that premise I think it should look like
Code:

// numAverages has already been set to 3
// draw our averages
for(int i=0; i < numAverages; i++) {
  int tuning=74;
  fill(255,128);
  rect(10+i*steps,10,steps,myFFT.averages[i]*200);
  fill(255);
  rect(10+i*steps,(int)(10+myFFT.maxAverages[i]*200),steps,1);
  rect(10+i*steps,10,1,200);
}

Hope this works. Smiley
Page Index Toggle Pages: 1