An audio library I'm using takes a callback function as an argument, which writes audio into a buffer.
I'm writing a class called Instrument, in which I have a method oscillator() which writes a sine wave to the buffer:
class Instrument {
private:
int oscillator(int16_t* outputBuffer, ...){ // Writes a sine wave to outputBuffer
...
}
RtAudio output; // Object for outputting audio
public:
void start() {
output.openStream(settingsAndStuff, &oscillator); // Error here
...
}
}
The compiler doesn't like this, saying the type of the oscillator() method is incompatible with the type that RtAudio.openStream() accepts.
It works fine if oscillator() is static, presumably because the implicit this pointer passed into the method changes its type. However, I can't have it be static because I need oscillator() to have access to Instrument fields (for stuff like amplitude and frequency).
Is there any sort of quick solution that requires a minimal amount of wrappers and such?