0
0

I would like to play a user loaded sound for x number of ms.
How do I tell fmod to play the sound for a desired amount of time?

Is adding a syncpoint only way of dealing with this?

  • You must to post comments
0
0

Trying to give this a go but have runned into problems.
I have set a syncpoint like this
[code:2ntm2kuw][...]
FMOD_EVENT *fmodevent;
FMOD_SYNCPOINT *ptr;
FMOD_SYSTEM *fmodsystem;
FMOD_SOUND *sound;
FMOD_CHANNEL *channel = 0;
FMOD_RESULT result;
[...]
FMOD_RESULT F_CALLBACK eventcallback(FMOD_EVENT *fmodevent, FMOD_EVENT_CALLBACKTYPE type, void *param1, void *param2, void *userdata)
{
alert( "Got a callback!" );
return FMOD_OK;
}
[...]
result = FMOD_System_Create(&fmodsystem);
result = FMOD_System_Init(fmodsystem, 32, FMOD_INIT_NORMAL, NULL);
result = FMOD_Event_SetCallback(fmodevent, eventcallback, 0);
[...]
result = FMOD_System_CreateSound(fmodsystem, Soundpaths[i], FMOD_HARDWARE, 0, &sound);
result = FMOD_Sound_AddSyncPoint(sound,2000, FMOD_TIMEUNIT_MS, "myname", &ptr);
result = FMOD_System_PlaySound(fmodsystem, FMOD_CHANNEL_FREE, sound, 0, &channel);
[...][/code:2ntm2kuw]
My callback function never gets called from this syncpoint. Am I doing this right?

I should get a event from a added syncpoint?

  • You must to post comments
0
0

You seem to have the event system mixed up with the low level API. You shouldn’t be trying to use [i:2oey6a3n]event[/i:2oey6a3n] callbacks with FMOD_SOUND objects. You want to be using [i:2oey6a3n]channel [/i:2oey6a3n]callbacks with the low level API.

remove the following lines:
[code:2oey6a3n]FMOD_EVENT *fmodevent; [/code:2oey6a3n][code:2oey6a3n]result = FMOD_Event_SetCallback(fmodevent, eventcallback, 0); [/code:2oey6a3n]

change the callback to this:
[code:2oey6a3n]FMOD_RESULT F_CALLBACK channelcallback(FMOD_CHANNEL * channel, FMOD_CHANNEL_CALLBACKTYPE type, unsigned int commanddata1, unsigned int commanddata2)
{
alert( "Got a callback!" );
return FMOD_OK;
}[/code:2oey6a3n]

change the end to this[code:2oey6a3n]// put the sound in a channel (make sure it’s paused)
result = FMOD_System_PlaySound(fmodsystem, FMOD_CHANNEL_FREE, sound, true, &channel);
// set the callback before starting the sound so no sync points are missed
result = FMOD_Channel_SetCallback(channel, channelcallback);
// unpause the channel
result = FMOD_Channel_SetPaused(false);
[/code:2oey6a3n]

  • You must to post comments
0
0

Thans for your help Peter!

I’m trying your suggestions but getting warnings, any thoughts?
[code:3suy0fu9]warning C4113: ‘FMOD_RESULT (__stdcall *)(FMOD_CHANNEL *,FMOD_CHANNEL_CALLBACKTYPE,int,void *,void *)’ differs in parameter lists from ‘FMOD_CHANNEL_CALLBACK’
warning C4020: ‘FMOD_Channel_SetCallback’ : too many actual parameters[/code:3suy0fu9]

Also, do I have to do systemupdate in order for it to catch the event?

  • You must to post comments
0
0

[quote:zcek0v98]
Also, do I have to do systemupdate in order for it to catch the event?[/quote:zcek0v98]
Yes. You must call system update to trigger callbacks.

for the C4113 warning you should change[code:zcek0v98]FMOD_CHANNEL_CALLBACKTYPE type, int command, void * commanddata1, void * commanddata2[/code:zcek0v98]to[code:zcek0v98]FMOD_CHANNEL_CALLBACKTYPE type, unsigned int commanddata1, unsigned int commanddata2[/code:zcek0v98]

For the C4020 change[code:zcek0v98]FMOD_Channel_SetCallback(channel, channelcallback, 0); [/code:zcek0v98]to[code:zcek0v98]FMOD_Channel_SetCallback(channel, channelcallback); [/code:zcek0v98]

The code I posted was based on old documentation. Sorry about that, I’ll fix up my post.

-Pete

  • You must to post comments
0
0

Thanks alot!
Its now working properly and I’m getting a callback from the syncpoint.

I do however get warning from
result = FMOD_Channel_SetCallback(channel, channelcallback);

1>c:\sdk\fmod\test\main.c(593) : warning C4028: formal parameter 3 different from declaration
1>c:\sdk\fmod\test\main.c(593) : warning C4028: formal parameter 4 different from declaration

edit
Tried setting callbacktype to syncpoint like this:
result = FMOD_Channel_SetCallback(FMOD_CHANNEL_CALLBACKTYPE_SYNCPOINT, channelcallback);
With this change the callback doesnt get called at all. Using it right?

  • You must to post comments
0
0

You have changed this:
[code:3n21ee2z]FMOD_Channel_SetCallback(channel, channelcallback); [/code:3n21ee2z] to this:[code:3n21ee2z]result = FMOD_Channel_SetCallback(FMOD_CHANNEL_CALLBACKTYPE_SYNCPOINT, channelcallback); [/code:3n21ee2z]
So my code is setting the callback for the ‘channel’ object, you are attempting to set a callback for the ‘FMOD_CHANNEL_CALLBACKTYPE_SYNCPOINT’ enumeration. If you look the value of result after this line it will most likely be something like FMOD_ERR_INVALID_HANDLE, when there is an FMOD_ERR returned in result it means you’re doing something wrong. It’s good practice to have an ERR_CHECK function like the examples use so that you can catch these errors.

If you only want to receive the syncpoint callbacks that is done inside your callback.

[code:3n21ee2z]FMOD_RESULT F_CALLBACK channelcallback(FMOD_CHANNEL * channel, FMOD_CHANNEL_CALLBACKTYPE type, unsigned int commanddata1, unsigned int commanddata2)
{
if (type == FMOD_CHANNEL_CALLBACKTYPE_SYNCPOINT)
alert( "Got a sync point callback!" );

return FMOD_OK;

}[/code:3n21ee2z]

[quote:3n21ee2z]
1>c:\sdk\fmod\test\main.c(593) : warning C4028: formal parameter 3 different from declaration [/quote:3n21ee2z]
You shouldn’t be getting any warnings. I ran a quick test and I got errors using that code. Try changing
[code:3n21ee2z]unsigned int commanddata1, unsigned int commanddata2[/code:3n21ee2z]
to
[code:3n21ee2z]void *commanddata1, void *commanddata2[/code:3n21ee2z]

-Pete

  • You must to post comments
0
0

Warnings are now gone

Thanks you very much, your support has been great!

  • You must to post comments
Showing 7 results
Your Answer

Please first to submit.