0
0

Hi guys,

I’ve searched through the forums and API for an answer but I can’t solve this. I am using the FMOD api for C. I have a play button which when pressed must play a WAV. I would like to trigger a callback when this ends. I can play the WAV fine but the callback isn’t triggered.

The code behind the Play button is as follows:

[code:2msqxbbh]

// initialize default output device
InitSystem();

FMOD_SOUND *sound;
FMOD_RESULT result;
FMOD_CHANNEL *channel;

result = FMOD_System_CreateStream(audio_sys, "myFile.wav", FMOD_DEFAULT, 0, &sound);
ERRCHECK(result);

result = FMOD_System_PlaySound(audio_sys, FMOD_CHANNEL_FREE, sound, FALSE, &channel);
ERRCHECK(result);

result = FMOD_Channel_SetCallback(channel, mycallback);
ERRCHECK(result);

FMOD_System_Update(audio_sys);
[/code:2msqxbbh]

And my callback function is as follows:

[code:2msqxbbh]

FMOD_RESULT F_CALLBACK mycallback(FMOD_CHANNEL *channel, FMOD_CHANNEL_CALLBACKTYPE type, void *commanddata1, void *commanddata2)
{
MessageBox(main_handle, "hello", 0, 0);
return FMOD_OK;
}
[/code:2msqxbbh]

As I said, the wav file plays fine, it’s just that the callback is never triggered.

I read somewhere that you have to call FMOD_System_Update() for the callbacks to work … and I am doing that as you can see from the code. I don’t have this in a loop, I only call this once … maybe this is the problem? If so I’m not sure how to do this without resorting to threads (I’d really like to avoid using threads) since this is a Windows application not a console application.

Any help would be appreciated.

Alan.

  • You must to post comments
0
0

Some more background. I’m trying to do this because I have a pool of WAV files that I want to be played one after the other without any gaps in a seamless manner. The next WAV file to be played can only be identified a few ms before the current one ends.

I was hoping to choose and fire the next WAV file from the END callback of the current WAV. Will this provide seamless playback with no gaps? Or is there a better way of doing this?

Cheers,

Alan.

  • You must to post comments
0
0

Hi vellamatic,

You’ve really got two questions there:

  1. Calling FMOD_System_Update() once is insufficient. You need to call it repeatedly. Take a look at the examples that are installed with FMOD, and you’ll see how they all call update in a loop.

  2. Triggering the next sound from a callback will probably not accomplish what you’re trying to do. There will be gaps in between the sounds. There are, however, a few ways to accomplish:

– Take a look at the realtimestiching example. The example works with streams, but I believe (please somebody from FMOD correct me if I’m wrong) that the same functionality now works with samples as well.
– Use FMOD_Channel_SetDelay() with FMOD_DELAYTYPE_DSPCLOCK_START to start the sounds sequentially at a precise time.

Hope that helps!

  • You must to post comments
0
0

[quote="Adiss":hgs5i5cw]1. Calling FMOD_System_Update() once is insufficient. You need to call it repeatedly. Take a look at the examples that are installed with FMOD, and you’ll see how they all call update in a loop.[/quote:hgs5i5cw]

But that would mean that I would have to start a thread to create such a loop … something which I would have liked to avoid.

[quote="Adiss":hgs5i5cw]Take a look at the realtimestiching example. The example works with streams, but I believe (please somebody from FMOD correct me if I’m wrong) that the same functionality now works with samples as well.
– Use FMOD_Channel_SetDelay() with FMOD_DELAYTYPE_DSPCLOCK_START to start the sounds sequentially at a precise time.

Hope that helps![/quote:hgs5i5cw]

I have a constraint that I only know which WAV file to play next just before the current one ends. Does the above respect this constraint?

  • You must to post comments
0
0

[quote:38wxhpxz]But that would mean that I would have to start a thread to create such a loop … something which I would have liked to avoid. [/quote:38wxhpxz]
Unfortunately it is unavoidable. FMOD needs to be updated somewhere, rather than creating our own internal thread, we put the onus on the user to poll System::update. This model suits game development better since they generally run everything inside the render loop anyway. Even event driven applications have a loop somewhere to fire the events, that is where you should update the FMOD System.

[quote:38wxhpxz]I have a constraint that I only know which WAV file to play next just before the current one ends. Does the above respect this constraint?[/quote:38wxhpxz]
When the channel finished callback is fired, the sound has really ended. Since it is called from the main thread, the mixer thread has already started mixing the next block so trying to do seamless stitching from callbacks is the wrong approach. The SetDelay technique will work fine but you will need to know which one is next slightly before it ends, this is how we implemented our interactive music system. There is a demonstration of this technique on the wiki:
http://52.88.2.202/wiki/index.php5?tit … h_setDelay

  • You must to post comments
0
0

Hi Peter,

The setDelay example you linked to sounds like its exactly what I need. However I’m having a hard time understanding what the general idea behind the code is.

Do I understand it correctly that in this code all the different channels are scheduled to play one after the other at the start? If so how can you change the content of, say, the 3rd channel just before the 2nd one ends if all channels are scheduled at the begining?

Also, can I use this method for iPhone?

Alan.

  • You must to post comments
0
0

Hi Allen,

All FMOD features are fully supported on iPhone.

The sequencer example is designed so you can append sounds to the sequence while it is playing.

A collegue of mine suggested that you could even just use the inbuilt sentencing feature: ‘Sound::setSubSoundSentence’. There is a complete example of this feature in the RealTimeStitching example.

  • You must to post comments
0
0

Hey guys. I managed to get the whole thing working using setDelay as suggested. I can now sync perfectly. Thanks for all your invaluable help.

One last question, this time regarding memory management. The API says the channel handles don’t need to be stored as these are freed automatically. Does this happen when the channel ends? Or when the system is released? What about sounds … when are these released?

Cheers,

Alan.

  • You must to post comments
0
0

Hi Alan, I’m glad you hear you got it all working.

Channels can be automatically ‘freed’ for a number of reasons including:
Playback of that channel completed.
The channel was reusued (playSound with FMOD_CHANNEL_REUSE)
The channel was stolen (when you create more channels then the maximum specified in System::init, FMOD will steal other channels)
System was released.

Channels are very light weight so don’t worry too much about them, your main concern should be the creation and release of FMOD::Sound objects.

  • You must to post comments
Showing 8 results
Your Answer

Please first to submit.