I am currently having some problems with passing my member-function callback function, to a non-member function defined by the library portaudio.
This is how my class is defined:
class record {
public:
record();
void start_record();
int recordCallback(const void *inputBuffer, void *outputBuffer,
unsigned long framesPerBuffer,
const PaStreamCallbackTimeInfo* timeInfo,
PaStreamCallbackFlags statusFlags, void *userData);
private:
PaStreamParameters inputParameters,
outputParameters;
PaStream* stream;
PaError err = paNoError;
paTestData data;
int totalFrames;
int numSamples;
int numBytes;
SAMPLE max, val;
double average;
};
Within start_record()
I pass the member function to a non-member function.. Meaning I pass a member-function of the class record (the callback), to a non-member function Pa_OpenStream().
err = Pa_OpenStream(
&this->stream,
&this->inputParameters,
NULL, /* &outputParameters, */
SAMPLE_RATE,
FRAMES_PER_BUFFER,
paClipOff, /* we won't output out of range samples so don't bother clipping them */
this->recordCallback,
&data );
if( err != paNoError )
{
std::cout << "Something wrong - open_stream check" << std::endl;
exit(1);
}
portaudio
expects a function pointer of type
int (*)(const void*, void*, long unsigned int, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void*)
and not
and not
int (record::)(const void*, void*, long unsigned int, const PaStreamCallbackTimeInfo*, PaStreamCallbackFlags, void*)
A quick solution would be to define the function outside the class scope, and make the variables which it uses and defined within the class global, but I would like to avoid that. So how do I handle this?