By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,222 Members | 1,730 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,222 IT Pros & Developers. It's quick & easy.

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

P: 31

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?
Sep 15 '18 #1
Share this Question
Share on Google+
1 Reply

Expert Mod 5K+
P: 9,197
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.
Sep 16 '18 #2

Post your reply

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