I’m actually coding a program in C++ using the library PortAudio.
This library is using a callback function tu manage audio input and output.
In C++, I implemented this callback function in my class “Audio” and I can’t send it to Pa_OpenDefaultStream(). The compiler says “this argument is incompatible with parameter of type PaStreamCallback*” with this line :
Pa_OpenDefaultStream(&this->_stream, 1, 2, paFloat32, this->_sampleRate, this->_framesPerBuffer, callbackFunction, NULL);
When I use C, sending my callbackFunction like this works well.
How can I send my callback function to this OpenDefaultStream function ?
You need to implement a plain global function with the same signature as PaStreamCallback.
It looks like PaStreamCallback takes an argument, void* userData. This is what’s usually called a context argument. Without knowledge of PortAudio I guess that you can use this to represent your class instance. When you call Pa_OpenDefaultStream, pass “this” for the userData pointer, where you wrote NULL in your example.
Here is a sample implememtation of the function wrapper you need:
Then replace your original code with:
I assumed you would make your callbackFunction to take all the other args.