0
0

Hey guys, im trying to understand the Event callback functions of FMOD.

I have read a few of the other posts on this subject (or similar) and have looked through the documentation and cant quite get it to work….. What i want to do is to create a flag that when the file finishes it will start a few other files, and will begin the game properly.

Here is what i have so far (there is a lot more but these are the bits that are important for this question…)

//———————-

result = fmodEventGroup->getEvent("Intro", FMOD_EVENT_DEFAULT, &intro);
ERRCHECK(result);

result = intro->start();
ERRCHECK(result);

//——— within the update function————-

FMOD_RESULT F_CALLBACK FMOD_EVENT_CALLBACK(FMOD_EVENT *intro,
FMOD_CHANNEL_CALLBACKTYPE callbackType,
void *data1, void *data2)
{
if(callbackType == FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_END)
{result = objects[i].event->start();
ERRCHECK(result);
}

//———————————————————-

There error i receive says that "FMOD_EVENT_CALLBACK’ ; local function definitions are illegal.

Can anyone see the reason that this may be occuring?

Im sorry for, probably, simple question, but i am new to programming so please be kind to me :)

Thanks Aiden

  • You must to post comments
0
0

It’s worth mentioning that it’s not advisable to use FMOD as a class name, especially in the global namespace since that will clash with the name of the FMOD namespace.

  • You must to post comments
0
0

Also, it appears as though your callback method is declared as an instance method of a class (which you’re calling FMOD). That is, if I’m reading the error message properly.

So your code looks like something like this:
[code:3d3e40zf]class FMOD
{
// ...
FMOD_RESULT F_CALLBACK myEventCallback( FMOD_EVENT * event,
FMOD_EVENT_CALLBACKTYPE type,
void * param1,
void * param2,
void * userdata );
}[/code:3d3e40zf]

This will not compile, because the method expects to be called as an instance method, but the callback method is required to be called as a static (non-instance) method.

The solution here is to make your callback method a static method, thus:
[code:3d3e40zf]class FMOD
{
// ...
// Note static added
static FMOD_RESULT F_CALLBACK myEventCallback( FMOD_EVENT * event,
FMOD_EVENT_CALLBACKTYPE type,
void * param1,
void * param2,
void * userdata );
}[/code:3d3e40zf]

Hope that helps!

  • You must to post comments
0
0

[quote:1srum7xl]1>main.obj : error LNK2019: unresolved external symbol "enum FMOD_RESULT __stdcall FMOD::myEventCallback(struct FMOD_EVENT *,enum FMOD_EVENT_CALLBACKTYPE,void *,void *,void *)" (?myEventCallback@FMOD@@YG?AW4FMOD_RESULT@@PAUFMOD_EVENT@@W4FMOD_EVENT_CALLBACKTYPE@@PAX22@Z) referenced in function "void __cdecl FMOD::doListenerMovement(void)" (?doListenerMovement@FMOD@@YAXXZ)[/quote:1srum7xl]
The error messages are little bit cryptic but all the information you need is right there.

[quote:1srum7xl]unresolved external symbol[/quote:1srum7xl]
This means the linker could not find the definition for something which was forward declared.

[quote:1srum7xl]enum FMOD_RESULT __stdcall FMOD::myEventCallback(struct FMOD_EVENT *,enum FMOD_EVENT_CALLBACKTYPE,void *,void *,void *)[/quote:1srum7xl]
This is the function signature of the callback, so it is saying it could not find the definition of the callback.

Here is an example which will reproduce the same error:

[code:1srum7xl]void myFunc();

int main()
{
myFunc();
}[/code:1srum7xl]

Here I have forward declared a function called ‘myFunc’ but it has not been defined. This code will compile but it will not link.

Here is a fixed version of that code snippet that will link correctly:
[code:1srum7xl]void myFunc();

int main()
{
myFunc();
}

// function definition
void myFunc()
{
}[/code:1srum7xl]

  • You must to post comments
0
0

Thank you peter

I now understand how this whole thing works much better and iv been able to set up lil tester programs and it works fine…. But when implementing it in my lil game….

to my mind it should be working now, and the earlier problems have now gone away…… now there is sum weird things happening that i dont quite understand….. sorry to be a bother.

Heres my new callback system

[code:kaorpru7]FMOD_RESULT F_CALLBACK myEventCallback( FMOD_EVENT * event,
FMOD_EVENT_CALLBACKTYPE type,
void * param1,
void * param2,
void * userdata );

Void initObjects()
{

//Take if for granted that i have set up all my sound objects & intro sound.

//————- setting locations of sound objects ———————

for (int i=0; i < NUM_OBJECTS; i++)
{
    FMOD_VECTOR pos = { objects[i].xPos, objects[i].yPos, objects[i].zPos };
    FMOD_VECTOR vel = { 0.0f, 0.0f, 0.0f };

    if (objects[i].event)
      {
        result = objects[i].event->set3DAttributes(&pos, &vel);
            ERRCHECK(result);
      }

}
    ERRCHECK(result = intro->setCallback(&myEventCallback, reinterpret_cast<void*>(objects)));
    ERRCHECK(result = intro->start());

}

FMOD_RESULT F_CALLBACK myEventCallback(FMOD_EVENT * event, FMOD_CHANNEL_CALLBACKTYPE type, void * param1, void * param2, void * userdata)
{
FMOD_RESULT result;

Object* objects = reinterpret_cast<Object*>(userdata);

if(type == FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_END)
{
    for (int i=0; i < NUM_OBJECTS; i++)
    {
    if (objects[i].event)
          {
            result = objects[i].event->start();
            ERRCHECK(result);
          }
    }
}
return FMOD_OK;

}[/code:kaorpru7]

This is the error message i am getting.

1>main.obj : error LNK2019: unresolved external symbol "enum FMOD_RESULT __stdcall FMOD::myEventCallback(struct FMOD_EVENT *,enum FMOD_EVENT_CALLBACKTYPE,void *,void *,void *)" (?myEventCallback@FMOD@@YG?AW4FMOD_RESULT@@PAUFMOD_EVENT@@W4FMOD_EVENT_CALLBACKTYPE@@PAX22@Z) referenced in function "void __cdecl FMOD::doListenerMovement(void)" (?doListenerMovement@FMOD@@YAXXZ)

Iv had a look around the web
http://social.msdn.microsoft.com/forums … 66b1eebea/

and i am using the correct Subsystem setting, i feel this error is stemming for me being a div in the code above.
Any help would be much appreciated.
Thanks A

  • You must to post comments
0
0

Hi Aiden, welcome to the FMOD Forums!

[quote:2plvw16p]local function definitions are illegal.[/quote:2plvw16p]
That is correct, you cannot declare a function inside another function. These are known as lambda functions and the current C++ standard does not support them (however the upcoming C++0x standard will, but they are not really appropriate in this case anyway).

I’m not sure if you are familiar with callbacks and function pointers but since you said you are new to programming Just to give you some background: a ‘callback’ is a pointer to a function. All of the FMOD callbacks have to be global or static functions. So you define a function in your code which matches the function signature expected by FMOD and that allows FMOD to call your function.

Here is a quick example of how function pointers work:

[code:2plvw16p]
int myFunction(int val, char* text)
{
printf("myFunction called! text = %s\n", text);
}

void main()
{
// delcare a function pointer (this syntax is kinda weird)
int (myCallback)(int, char) = NULL;

// make the myCallback function pointer point at the myFunction function
myCallback = &myFunction;

// fire the callback a few times
myCallback("myCallback fired the first time");
myCallback("myCallback fired the second time");
myCallback("myCallback fired the third time");

}[/code:2plvw16p]

Here is a website that explains function pointers in depth: http://www.newty.de/fpt/index.html

The standard usage of an FMOD callback would be something like this:
[code:2plvw16p]
// Forward declare our callback
FMOD_RESULT F_CALLBACK myEventCallback( FMOD_EVENT * event,
FMOD_EVENT_CALLBACKTYPE type,
void * param1,
void * param2,
void * userdata );

void SoundManager::start()
{
result = fmodEventGroup->getEvent("Intro", FMOD_EVENT_DEFAULT, &intro);
ERRCHECK(result);

// Note: use the ampersand (&) to take the address of the function to get the 'function pointer'
// Note: pass the 'objects' array as the 'userdata' parameter so we can access it inside our callback
result = intro->setCallback(&myEventCallback, reinterpret_cast<void*>(objects));
ERRCHECK(result);

result = intro->start();
ERRCHECK(result);

}

FMOD_RESULT F_CALLBACK myEventCallback( FMOD_EVENT * event,
FMOD_EVENT_CALLBACKTYPE type,
void * param1,
void * param2,
void * userdata )
{
Object* objects = reinterpret_cast<Object*>(userdata);

if(callbackType == FMOD_EVENT_CALLBACKTYPE_SOUNDDEF_END)
{
    result = objects[i].event-&gt;start();
    ERRCHECK(result);
}

}
[/code:2plvw16p]

I have made the assumption that ‘objects’ was a C-style array of some class called ‘Object’.

If you take a look in the examples directory the following examples use the event callback:
programmer_sound
realtime_tweaking

Hope this helps, let us know if you have any further questions.

  • You must to post comments
Showing 5 results
Your Answer

Please first to submit.