I am building a sound generator program in Java and I am trying to port it to c++
I can easily do this in Java, but I am new to c++
In c++ I have an interface called iSamplePlayer and this is the iSample.h file:
class ISamplePlayer {
public:
virtual double GetFrequency()
virtual void SetFrequencyAtZero(double frequency)
virtual void SetSampleRate(uint32_t sampleRate)
virtual void SetAmplitude(double amplitude)
//virtual void SetAdsrEnvelope(AdsrEnvelope adsrEnvelope)
virtual void SetOffset(double offset)
virtual void AddToFrequency(double offset)
virtual void SubtractFromFrequency(double offset)
virtual double GenerateWaveformPoint() = 0;
};
a base class called AWaveform, this is the AWaveform.h file:
class AWaveform : public ISamplePlayer{
public:
// constants
const uint32_t SAMPLE_RATE = 44100;
// constructors
AWaveform(double frequency, uint32_t sampleRate);
AWaveform(double frequency);
AWaveform(const AWaveform& orig);
virtual ~AWaveform();
// getters setter and other methods are here
// generateWaveForm method
virtual double GenerateWaveformPoint() override = 0;
private:
// instance variables
double amplitude; // volume
double frequency; // pitch
double point; // current sample
uint32_t sampleRate; // rate of samples per second
double holdFrequency; // hold frequency till it can be changed.
double waveLength; // length of one waveform in samples
double waveSampleIndex; // keeps track of the waveLength
};
and Finally in the class SineGenerator, I have the GenerateWaveformPoint() function in the SineGenerator.h that actualy overrides with code:
class SineGenerator : AWaveform{
public:
// constants
const double DEF_PEAK_PERCENTAGE = 0.5;
const double DEF_HORIZONTAL_OFFSET = 0;
// constructors
SineGenerator(double frequency, double peakPercentage, double offset);
SineGenerator(double frequency, double peakPercentage);
SineGenerator(double frequency);
SineGenerator(const SineGenerator& orig);
virtual ~SineGenerator();
// methods
double GenerateWaveformPoint() override {
// check frequency
CheckFrequency();
// genorate point.
DrawSinePoint();
// checks if waveSampleIndex is equal to wavelength
CheckWaveLength();
// apply ADSR amplitude
//if (getAdsrEnvelope() != null) {
// setPointVolume(getAdsrEnvelope().getADSRvolume());
//}
// set volume
SetPointVolume(GetAmplitude());
// return the sample data
return GetPoint();
}
protected:
void DrawSinePoint()
{
// code goes here
}
private:
// instance variables
double peakPercentage;
double smallWaveFrequency; // used for != 50% waves
double smallWaveIndex; // index of smallwave
double smallWaveLength; // use to hold small wave length for != 50%
double holdIndex; // used to keep track of hold time
double holdLength; // use to hold hold length for != 50%
double updatePeakPercentage; // holds the update value
};
It gives this error "undefined reference to `vtable for ISamplePlayer'".
How do I properly make a virtual function that overrides an interface's virtual function?