0
0

i’d like to use a callback from the Event music system to determine when a segment in a cue stops playing. (note: currently i’m trying to get the .cpp to compile, so the code in the callback is just a stub). surprisingly, i can’t find any example code using this callback type, and i’m getting compile errors:
[code:tnrsreo2]
FMOD_RESULT F_CALLBACK segmentEndCallback(FMOD_MUSIC_CALLBACKTYPE type, void *param1, void *param2, void *userdata)
{
switch (type)
{
case FMOD_MUSIC_CALLBACKTYPE_SEGMENT_END:
// set flag to allow next cue to be triggered
printf("segment end callback");
break;
default:
break;
}
return FMOD_OK;
}
[/code:tnrsreo2]

in the init() method, after:
[code:tnrsreo2] ERRCHECK(result = eventsystem->getMusicSystem(&musicsystem)); [/code:tnrsreo2]

i musicsystem->prepare the cues, then set the callback i:tnrsreo2[/i:tnrsreo2]:
[code:tnrsreo2] ERRCHECK(result = musicsystem->setCallback(segmentEndCallback, 0)); [/code:tnrsreo2]

however, this gives me the following compile error:
error: no matching function for call to ‘FMOD::MusicSystem::setCallback(<unresolved overloaded function type>, int)’
candidates are: virtual FMOD_RESULT FMOD::MusicSystem::setCallback(FMOD_RESULT ()(FMOD_MUSIC_CALLBACKTYPE, void, void*, void), void)

what am i doing wrong?

  • You must to post comments
0
0

Your code works for me. The only thing I can think of that might be going wrong is if your callback is a non-static member of a class. If that is the case then the calling convention will be ‘thiscall’ rather than ‘stdcall’ and it will have an invisible ‘this’ parameter which means it doesn’t match the expected function signature. If that is the case, then there are ways around this such as using std::tr1::bind or boost::bind, but the easiest way is to just make it a static function and pass the ‘this’ pointer as the userdata parameter.

-Pete

  • You must to post comments
0
0

yes, the callback is in a class FMODaudio.cpp, containing the audio code (which is controlled by a Mac interface written in Objective-C++). SO i should declare the callback:
[code:1wwfk9h9]
static FMOD_RESULT F_CALLBACK segmentEndCallback(FMOD_MUSIC_CALLBACKTYPE type, void *param1, void *param2, void *userdata)

[/code:1wwfk9h9]

and then:

ERRCHECK(result = musicsystem->setCallback(segmentEndCallback, this->[color=blue:1wwfk9h9]What?[/color:1wwfk9h9]));

obviously, i’m confused about the use of the userdata field / ‘this’ pointer, because i thought declaring the callback function "static" means it doesn’t have access to the "this" pointer?? so what do i pass to the musicsystem to tell it where the callback is?

  • You must to post comments
0
0

[quote:23atc2bt]obviously, i’m confused about the use of the userdata field / ‘this’ pointer, because i thought declaring the callback function "static" means it doesn’t have access to the "this" pointer??[/quote:23atc2bt]
That is correct, you do not have access to the ‘this’ pointer in a static function. The userdata parameter allows you to pass information into the callback, so you can use that to pass the ‘this’ pointer into the static function.

So you could change you code to something like this:
[code:23atc2bt]ERRCHECK( result = musicsystem->setCallback(segmentEndCallback, static_cast<void*>(this)) ); [/code:23atc2bt]

Then the callback code would change to this:
[code:23atc2bt]FMOD_RESULT F_CALLBACK segmentEndCallback(FMOD_MUSIC_CALLBACKTYPE type, void param1, void *param2, void *userdata)
{
MyClass
instance = static_cast<MyClass*>( userdata );

switch (type)
{
case FMOD_MUSIC_CALLBACKTYPE_SEGMENT_END:
// set flag to allow next cue to be triggered
printf("segment end callback");
break;
default:
break;
}
return FMOD_OK;
} [/code:23atc2bt]

You can then use that ‘instance’ pointer to access members of the instance of your audio class inside your static function.

  • You must to post comments
0
0

while i truly appreciate your help and support, your "passing ‘this’ pointer as userdata" solution confused me more than i already was (not an easy task!) … but then it occurred to me that the whole issue could simply be avoided by "de-class-ing" the methods in my FMODaudio.cpp module, and just calling them as functions from my controller — worked like a charm the first time!

sometimes, it seems to me that the whole object-oriented methodology is more of a pain in the class than it’s worth, particularly in C++. perhaps i’m either too old school (after all, my first professional program was written on punch cards!), or too much of an OO noob, but for the purposes of my current project, i don’t see the advantage of putting the FMOD access code in a class — [i:2hnmexir]particularly when it doesn’t work![/i:2hnmexir] (or requires incomprehensibly arcane pointer passing structures to play nice with the other classes)

but that’s more of a programming discussion than an FMOD topic, and my philosophy of life has always been "whatever works!" … so thanks again for your assistance, but i’m going to call this one a "doctor, my arm hurts when i do this … so don’t do that!" solution :)

  • pdx
  • You must to post comments
0
0

Fair enough, as long as you have a working solution.

-Pete

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.