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 › Constructor Undefined Error
Page Index Toggle Pages: 1
Constructor Undefined Error? (Read 1355 times)
Constructor Undefined Error?
Feb 2nd, 2010, 10:13am
 
Hi,

I am quite new to processing and am getting a constructor error when compiling, this is my code for the logAverages.pde:
Code:
/**
* Linear Averages
* by Damien Di Fede.
*
* This sketch demonstrates how to use the averaging abilities of the FFT.
* 128 linearly spaced averages are requested and then those are drawn as rectangles.
*/

import ddf.minim.analysis.*;
import ddf.minim.*;
import processing.serial.*;

Serial myPort; // Create object from Serial class
int val; // Data received from the serial port

Minim minim;
AudioPlayer jingle;
FFT fft;
FFTAnalyser analyser;

void setup()
{
String portName = Serial.list()[0];
myPort = new Serial(this, portName, 9600);

size(512, 200, P2D);
//minim = new Minim(this);

//jingle = minim.loadFile("song.mp3", 2048);

analyser = new FFTAnalyser(this, "song.mp3", 2048);

// loop the file
//jingle.loop();
// create an FFT object that has a time-domain buffer the same size as jingle's sample buffer
// and a sample rate that is the same as jingle's
// note that this needs to be a power of two
// and that it means the size of the spectrum will be 1024.
// see the online tutorial for more info.
//fft = new FFT(jingle.bufferSize(), jingle.sampleRate());
// use 128 averages.
// the maximum number of averages we could ask for is half the spectrum size.
//fft.linAverages(128);

//fft.logAverages(60, 5);
rectMode(CORNERS);

}

void draw()
{
background(0);
fill(0,0,255);
// perform a forward FFT on the samples in jingle's mix buffer
// note that if jingle were a MONO file, this would be the same as using jingle.left or jingle.right
fft.forward(jingle.mix);
int w = int(analyser.specSize()/analyser.avgSize());
for(int i = 0; i < analyser.avgSize(); i++)
{
// draw a rectangle for each average, multiply the value by 5 so we can see it better
rect(i*w, height, i*w + w, height - analyser.getAvg(i));
if(i > 6)
fill(255,0,0);


}

setDmxChannel(1,(int)(analyser.getAvg(10)*3));
setDmxChannel(2,0);
setDmxChannel(3,(int)(analyser.getAvg(0)));
setDmxChannel(4,255);


}

void setDmxChannel(int channel, int value) {
// Convert the parameters into a message of the form: 123c45w where 123 is the channel and 45 is the value
// then send to the Arduino
myPort.write( str(channel) + "c" + str(value) + "w" );
}

void stop()
{
// always close Minim audio classes when you finish with them
/*
jingle.close();
minim.stop();
*/
analyser.stop();
super.stop();
}


and here is the code from my FFTAnalyser
Code:

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

public class FFTAnalyser {

public float [] peaks; // peaks of the averages, aka "maxAverages" in other implementations
public int [] peakHoldTimes; // how long to hold THIS peak meter? decay if == 0
public int peakHoldTime; // how long do we hold peaks? (in fft frames)
public float peakDecayRate; // how quickly the peaks decay: 0f=instantly .. 1f=not at all
public FFT fft;
public float samplingRate;
public int minBandwidth = 60;
public int bandsPerOctave = 5;
Minim minim;
AudioPlayer jingle;


public FFTAnalyzer(LogAverages parent, String filename, int sampleRate) {

minim = new Minim(parent);
jingle = minim.loadFile(filename, sampleRate);
jingle.loop();
fft = new FFT(jingle.bufferSize(), jingle.sampleRate());
fft.logAverages(this.minBandwidth, this.bandsPerOctave);


}
/*
public setLogAverage(int minBandwidth, int bandsPerOctave){
}
*/

public float getAvg(int i){
return this.fft.getAvg(i);
}

public float avgSize(){
return this.fft.avgSize();
}

public float specSize(){
return this.fft.specSize();
}

public void stop(){
// always close Minim audio classes when you finish with them
this.jingle.close();
this.minim.stop();

}



}


The error im getting is:
The constructor LogAverages.FFTAnalyser(LogAverages, String, int) is undefined.

Can anyone help?



Re: Constructor Undefined Error?
Reply #1 - Feb 2nd, 2010, 11:05am
 
The class is called FTTAnalyser but your constructor name does not match change the 'z' below to 's'

Code:
  public FFTAnalyzer(LogAverages parent, String filename, int sampleRate) {


Smiley
Re: Constructor Undefined Error?
Reply #2 - Feb 2nd, 2010, 11:12am
 
Edit: oh good, Quark spotted it.  Slippery devil.  I'll leave the rest of my comment though:

I assume you're using Eclipse or another straight Java editor because you're writing in Java style (declaring public/private, etc.)   If you're using the Processing IDE, you can remove all instances of "public" and "private" because everything is inside the PApplet class.  I would also suggest using different variable names for objects in a child class that are essentially pointers to the parent class object (e.g. Minim minim = parent;) -- so you don't end up referring to the wrong one from inside a child class method.
Re: Constructor Undefined Error?
Reply #3 - Feb 3rd, 2010, 3:00am
 
BenHem said
Quote:
I assume you're using Eclipse or another straight Java editor because you're writing in Java style (declaring public/private, etc.)   If you're using the Processing IDE, you can remove all instances of "public" and "private" because everything is inside the PApplet class.


JackW must be using the Processing IDE because
Code:
void setup(){
}

will not work in Eclipse without the public keyword.

The sketch as posted is in fact 2 tabs and in Processing the second (and subsequent) tab can be either a .pde in which case it is part of the main sketch or a .java, in which case it is not part of the main sketch but a separate class and has to use standard Java syntax.

This is what JackW has done so he correctly passes a reference to the main sketch in the constructor so he has access to the PApplet methods. That's why the we need the public/private in the FFTAnalyser class.
Re: Constructor Undefined Error?
Reply #4 - Feb 3rd, 2010, 3:11pm
 
Heh, thanks.  I had forgotten all about .java tabs.  Excuse me.  X|
Page Index Toggle Pages: 1