Firelight Technologies FMOD Studio API
FMOD_SYSTEM_CALLBACK
Callback for system events.
C/C++ Syntax
FMOD_RESULT F_CALLBACK FMOD_SYSTEM_CALLBACK(
FMOD_SYSTEM *system,
FMOD_SYSTEM_CALLBACK_TYPE type,
void *commanddata1,
void *commanddata2,
void *userdata
);
Parameters
system
Pointer to a system handle.
type
The type of callback. Refer to FMOD_SYSTEM_CALLBACK_TYPE.
commanddata1
The first callback type specific data generated by the callback. See remarks for meaning.
commanddata2
The second callback type specific data generated by the callback. See remarks for meaning.
userdata
The userdata assigned into the given system, or NULL if not set. See remarks for more information.
Return Values
If the function succeeds then the return value is FMOD_OK.
If the function fails then the return value will be one of the values defined in the FMOD_RESULT enumeration.
Remarks
C++ Users. Cast FMOD_SYSTEM *
to FMOD::System *
inside the callback and use as normal.
'userdata' is the userdata assigned to the system from System::setUserData function. In the case of multiple FMOD systems being created, some callbacks may not have the system context in which case this variable will be last userdata set into any system.
'commanddata1' and 'commanddata2' meanings.
These 2 values are set by the callback depending on what is happening in the callback and the type of callback.
- FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED
commanddata1: Always 0.
commanddata2: Always 0. - FMOD_SYSTEM_CALLBACK_MEMORYALLOCATIONFAILED
commanddata1: A string (char*) which represents the file and line number of the allocation inside FMOD.
commanddata2: The size (int) of the requested allocation. - FMOD_SYSTEM_CALLBACK_THREADCREATED
commanddata1: The handle of the created thread. See notes below for thread handle types
commanddata2: A string (char*) which represents the name of the thread. - FMOD_SYSTEM_CALLBACK_THREADDESTROYED
commanddata1: The handle of the destroyed thread. See notes below for thread handle types
commanddata2: A string (char*) which represents the name of the thread. - FMOD_SYSTEM_CALLBACK_BADDSPCONNECTION
commanddata1: Pointer to a FMOD::DSP object that was the target of the DSP connection.
commanddata2: Pointer to a FMOD::DSP object that was the source of the DSP connection. - FMOD_SYSTEM_CALLBACK_PREMIX
commanddata1: 0.
commanddata2: 0. - FMOD_SYSTEM_CALLBACK_MIDMIX
commanddata1: 0.
commanddata2: 0. - FMOD_SYSTEM_CALLBACK_POSTMIX
commanddata1: 0.
commanddata2: 0. - FMOD_SYSTEM_CALLBACK_ERROR
commanddata1: Pointer to a FMOD_ERRORCALLBACK_INFO structure with extra information about the error.
commanddata2: 0.
Note! For FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED, the user must call System::update for the callback to trigger! See FMOD_SYSTEM_CALLBACK_TYPE for details.
Note! For FMOD_SYSTEM_CALLBACK_THREADCREATED and FMOD_SYSTEM_CALLBACK_THREADDESTROYED, the handle that is returned (via commanddata1) is different on each platform. The types to cast to are as follows.
- Mac, Linux, iOS, Android: pthread_t
- PS3: sys_ppu_thread_t
- PS4: ScePthread
- WiiU: OSThread
- Win, Xbox360, XboxOne: HANDLE
- WinStore: IAsyncAction
- PSVita: FMOD_OS_Thread
This is a custom struct you can define astypedef struct FMOD_OS_Thread { SceUID id; int (*func)(void *param); void *param; };
Here is an example of a system callback.
FMOD_RESULT F_CALLBACK systemcallback(FMOD_SYSTEM *system, FMOD_SYSTEM_CALLBACK_TYPE type, void *commanddata1, void *commanddata2, void* userdata)
{
FMOD::System *sys = (FMOD::System *)system;
switch (type)
{
case FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED:
{
int numdrivers;
printf("NOTE : FMOD_SYSTEM_CALLBACK_DEVICELISTCHANGED occurred.\n");
sys->getNumDrivers(&numdrivers);
printf("Numdevices = %d\n", numdrivers);
break;
}
case FMOD_SYSTEM_CALLBACK_MEMORYALLOCATIONFAILED:
{
printf("ERROR : FMOD_SYSTEM_CALLBACK_MEMORYALLOCATIONFAILED occurred.\n");
printf("%s.\n", commanddata1);
printf("%d bytes.\n", commanddata2);
break;
}
case FMOD_SYSTEM_CALLBACK_THREADCREATED:
{
printf("NOTE : FMOD_SYSTEM_CALLBACK_THREADCREATED occurred.\n");
printf("Thread ID = %d\n", (int)commanddata1);
printf("Thread Name = %s\n", (char *)commanddata2);
break;
}
case FMOD_SYSTEM_CALLBACK_THREADDESTROYED:
{
printf("NOTE : FMOD_SYSTEM_CALLBACK_THREADDESTROYED occurred.\n");
printf("Thread ID = %d\n", (int)commanddata1);
printf("Thread Name = %s\n", (char *)commanddata2);
break;
}
case FMOD_SYSTEM_CALLBACK_BADDSPCONNECTION:
{
FMOD::DSP *source = (FMOD::DSP *)commanddata1;
FMOD::DSP *dest = (FMOD::DSP *)commanddata2;
printf("ERROR : FMOD_SYSTEM_CALLBACK_BADDSPCONNECTION occurred.\n");
if (source)
{
char name[256];
source->getInfo(name, 0,0,0,0);
printf("SOURCE = %s\n", name);
}
if (dest)
{
char name[256];
dest->getInfo(name, 0,0,0,0);
printf("DEST = %s\n", name);
}
break;
}
case FMOD_SYSTEM_CALLBACK_PREMIX:
{
printf("NOTE : FMOD_SYSTEM_CALLBACK_PREMIX occurred.\n");
break;
}
case FMOD_SYSTEM_CALLBACK_MIDMIX:
{
printf("NOTE : FMOD_SYSTEM_CALLBACK_MIDMIX occurred.\n");
break;
}
case FMOD_SYSTEM_CALLBACK_POSTMIX:
{
printf("NOTE : FMOD_SYSTEM_CALLBACK_POSTMIX occurred.\n");
break;
}
case FMOD_SYSTEM_CALLBACK_ERROR:
{
FMOD_ERRORCALLBACK_INFO* info = (FMOD_ERRORCALLBACK_INFO*)commanddata1;
printf("NOTE : FMOD_SYSTEM_CALLBACK_ERROR occurred.\n");
printf(" ERROR (%d) from %s(%s) with instance %p (type %d)\n", info->result, info->functionname, info->functionparams, info->instance, info->instancetype);
break;
}
}
return FMOD_OK;
}
See Also
Version 1.10.03 Built on Feb 1, 2018