423,335 Members | 1,149 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 423,335 IT Pros & Developers. It's quick & easy.

Portaudio wants a callback function pointer, but I have the data in a class

P: 31
Hello,

I want to use portaudio for my c++ audio project. The problem is: As you can see here and here, it wants me to pass the callback function as a function argument of openDefaultStream(). The problem is: The audio data lies in a class. So there is a object of the class AudioManager() which collects the newest samples. The problem is now: I can't pass a member function pointer to openDefaultStream(), right? Since that would require me to pass the object it should be called on as well. But if I make the function static, how can I access the newest samples then?
1 Week Ago #1
Share this Question
Share on Google+
1 Reply


weaknessforcats
Expert Mod 5K+
P: 9,163
Write a function that receives data from AudioManager. The function then calls the member function of your class.

Pass the address of this function to Audiomanager.

When AudioManager calls the function, the data received is the input argument and the function updates an object of your class.


Check out the design pattern called Adapter.
5 Days Ago #2

Post your reply

Sign in to post your reply or Sign up for a free account.