I’m trying to make an FMOD based MIDI synthesiser using C++ in VS on Windows.
I have successfully set up FMOD, created the pcmreadcallback function (that just generates a sine wave) and it all works well.
Now I am trying to implement this functionality into a class.
In order to do this I am putting all of the normal FMOD setup code including the line that sets the call back function (soundInfo.pcmreadcallback = callbackfunction;) into the constructor of the class.
I’ve then made the actual callbackfunction itself a member method of the same class.
The code is the same as my previous working code apart from the fact that the code is now in the constructor of a class and the callback function is a member method of the same class.
When I build I get the following errors:
error C3867: ‘Channel::PCMRead’: function call missing argument list; use ‘&Channel::PCMRead’ to create a pointer to member
IntelliSense: a value of type "FMOD_RESULT (__stdcall Channel::*)(FMOD_SOUND *sound, void *data, unsigned int datalen)" cannot be assigned to an entity of type "FMOD_SOUND_PCMREADCALLBACK" c:\users\ben\documents\visual studio 2010\projects\benfmodsynth\benfmodsynth\benfmodsynth_classes.h
Can anyone explain why this is happening?
Is it something to do with the fact that the callback member function is not actually fully fleshed out at the point when the constructor is running?
If so I can see why it is asking me to use a pointer to the function but I can’t work out how to do it.
- bb586 asked 4 years ago
[quote:2d2q70am]I’ve then made the actual callbackfunction itself a member method of the same class.[/quote:2d2q70am]
The callbacks expect C calling conventions F_CALLBACK which on windows is __stdcall, member methods use __thiscall (which adds the hidden ‘this’ parameter so that local member data can be accessed). You need to make the method static so it removes the ‘this’ parameter so the function signature matches what is expected by FMOD. This has the implication that you cannot access any of members of your class inside the callback. To solve this you can set the userdata to point to your class (that is what it’s there for). Then inside the static callback you can cast the userdata to your class type and access members.
- Guest answered 4 years ago
Please login first to submit.