0
0

Hi

I was hoping someone had a example of using a callback to detect when a sound or song is finished playing. I would like to be able to automatically play a sound when the current one is finished. I havent used a callback before and could use some help.

Thanks in advance!

  • You must to post comments
0
0

noone is familiar with the callback system in fmod?

  • You must to post comments
0
0

Could you please tell us which programming language you are using?
You could also look here in the documentation:
http://fmod.org/docs/HTML/FSOUND_Stream … lback.html
Not sure, but one of the samples will probably have the callback.

And in case you are using Delphi here is some code:
[code:17iww62p]
// Set the endcallback function
FSOUND_Stream_SetEndCallback(StreamHandle, StreamEndCallback, Channel);
// StreamHandle is the stream pointer (PFSoundStream)
// StreamEndCallback is the function that needs to be called
// Channel the channel of course

// The endcallback function
function StreamEndCallback(Stream: PFSoundStream; Buff: Pointer; Len, Param: Integer): ByteBool; stdcall;
begin
// Code to stop the player, or start the next file, goes here
Result := True;
end;

[/code:17iww62p]

Good luck

  • You must to post comments
0
0

Thanks for the reply Brett, sorry i forgot to mention Im using C++. Thanks for the link. Ill try to implement your suggestions!

  • You must to post comments
0
0

Thanks for the help! Callback is working perfectly.

  • You must to post comments
0
0

I have a couple more questions about the callback system. I got the callback to work with the older version of FMOD but with FMOD Ex Im having a bit of trouble with it still.

For the old version I used
[code:2wknbvxb]

signed char F_CALLBACKAPI endcallback(FSOUND_STREAM stream, void *buff,
int len,
void *param)
{
CBasePlayer *plr = (CBasePlayer
)param;

plr->m_Cycle = (int*)1;

}

FSOUND_Stream_SetEndCallback(m_Stream, endcallback, this);

[/code:2wknbvxb]

It fires at the end of a sound and works perfectly.

With the FMOD Ex how do I accomplish the same? I have looked in the documentation and found

[code:2wknbvxb]

m_Channel->setCallback(FMOD_CHANNEL_CALLBACK_END, 0, /myCallbackFunc/);

FMOD_RESULT FMOD_CHANNEL_CALLBACK(FMOD::Channel *channel, unsigned int evdata, FMOD_CHANNEL_CALLBACK_TYPE type);

[/code:2wknbvxb]

I dont understand how I need to delcare and define my callback function and set it with setCallback();

Also is it possible to pass data to my callback function like in the old version where a void* was used?

Thanks in advance!

  • You must to post comments
0
0

Im sorry, I guess its just something simple that I dont have a grasp on. If your talking about the first arg in:

[code:1nni2515]
FMOD_RESULT FMOD_CHANNEL_CALLBACK(FMOD::Channel *channel, unsigned int evdata, FMOD_CHANNEL_CALLBACK_TYPE type);
[/code:1nni2515]

It says it requires “FMOD::Channel *channel”. Other than that Im not sure what you are refering to.

From what I understand you use:

[code:1nni2515]
m_Channel->setCallback(FMOD_CHANNEL_CALLBACK_END, 0, myCallbackFunc);
[/code:1nni2515]

and pass my function I want called at the end of a sound as the last argument. What I dont understand is how to use:

[code:1nni2515]
FMOD_RESULT FMOD_CHANNEL_CALLBACK(FMOD::Channel *channel, unsigned int evdata, FMOD_CHANNEL_CALLBACK_TYPE type);
[/code:1nni2515]

When I try to use the “setCallback” function it says it cant convert the last argument into a “FMOD_CHANNEL_CALLBACK”. Is “FMOD_CHANNEL_CALLBACK(…)” used to create the function that I want called at the end of a sound. Using the idea of the old version of FMOD I tried using:

[code:1nni2515]
FMOD_RESULT FMOD_CHANNEL_CALLBACK myFunc(...)
{
/code/
}

m_Channel->setCallback(FMOD_CHANNEL_CALLBACK_END, 0, myFunc);
[/code:1nni2515]

That is apparently not correct. Is it possible for you to show me how to setup the callback and a function to be called by the callback? I have checked all the examples in the release and there arent any examples of a end callback.

I appreciate your time and am sorry if Im just being a knuckle head!
Thanks

  • You must to post comments
0
0

Thanks much Brett, I got the callback function to fire off properly. I still have one question for you. You mentioned earlier to use “setUserData” and “getUserData” to pass the callback data instead of a void*. I tried using:

[code:3ejjf5wn]
m_Result = m_System->playSound(FMOD_CHANNEL_FREE, m_Sound, true, &m_Channel);
ERRCHECK(m_Result,PLAY_SOUND);

m_Result = m_Channel->setCallback(FMOD_CHANNEL_CALLBACK_END,0,endCallbackFunc);
ERRCHECK(m_Result,SET_CALLBACK);

m_Result = m_Channel->setUserData(this);

ERRCHECK(m_Result,SET_USERDATA);
[/code:3ejjf5wn]

[code:3ejjf5wn]
FMOD_RESULT F_CALLBACK endCallbackFunc(FMOD_CHANNEL *channel, unsigned int evdata, FMOD_CHANNEL_CALLBACK_TYPE type)
{
FMOD::Channel *chan = (FMOD::Channel *)channel;

void **ud = NULL;
chan->getUserData(ud);
CBasePlayer *plr = (CBasePlayer*)ud;

plr->m_Cycle = 1;

//MessageBox(NULL,"End of sound",NULL,MB_OK);
return FMOD_OK; 

}
[/code:3ejjf5wn]

This compiles fine but when it fires the callback function it causes a “Access Violation” error when it gets to “plr->m_Cycle = 1;”. I am assuming it has something to do with me improperly using “setUserData” and “getUserData”. I need to access the m_Cycle variable to change its value so a worker thread will know to cycle to the next sound. Does it look like I am using “setUserData” and “getUserData” properly?

Thanks in advance!

  • You must to post comments
0
0

Thank you Brett, you have been very helpful. Everything is working nicely now. I used:

[code:3r9pmng6]
FMOD_RESULT F_CALLBACK endCallbackFunc(FMOD_CHANNEL *channel, unsigned int evdata, FMOD_CHANNEL_CALLBACK_TYPE type)
{
FMOD_RESULT result;
FMOD::Channel *chan = (FMOD::Channel *)channel;

void *bp = NULL;    
result = chan->getUserData(&bp);
ERRCHECK(result,GET_USERDATA);

CBasePlayer *plr = (CBasePlayer*)bp;
plr->m_Cycle = 1;

return FMOD_OK; 

}
[/code:3r9pmng6]

The support the FMOD team provides is uncomparable. Thanks again!

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.