mercredi 1 novembre 2017

Parsing member function pointer when a non-member function pointer was expected?

I am currently having some problems with parsing my member-function a callback function, to a non-member function defined by the library portaudio.

This is how the 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 the member function of the class record, 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);
}

A portaudio which 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 is defined within the class global, but I would like to avoid that. So how do I handle this?

Aucun commentaire:

Enregistrer un commentaire