Hi,
I would stop aQTimer inside a channel callback when the sound finish to play
so I wrote a callback with the flag FMOD_CHANNEL_CALLBACKTYPE_END but it has no effect.
This is the code:
[code:1dn1zl53]FMOD_RESULT F_CALLBACK endCallback(FMOD_CHANNEL *channel,
FMOD_CHANNEL_CALLBACKTYPE type,
unsigned int commanddata1,
unsigned int commanddata2)
{
(void)commanddata1; // Unused (to avoid warnings)
(void)commanddata2; // Unused (to avoid warnings)
switch(type)
{
case FMOD_CHANNEL_CALLBACKTYPE_END:
{
std::cout << "In the END callback\n" ;
FMOD_RESULT result;
FMOD::Channel *currentChannel = (FMOD::Channel *)channel;
void *ud = NULL;
result = currentChannel->getUserData(&ud);
ERRCHECK(result);
WaveWidget* currentWave = (WaveWidget*)ud;
//currentWave->setChannel( NULL );
currentWave->stopTimer();
break;
}
default:
break;
}
return FMOD_OK;
}[/code:1dn1zl53]
I attach the callback to the channel here:
[code:1dn1zl53]FMOD::Channel* AudioDevice::playSound( FMOD::Sound *soundToPlay )
{
FMOD::Channel *channel = NULL;
// play the sound soundToPlay
FMOD_RESULT result = audioSystem->playSound( FMOD_CHANNEL_REUSE, soundToPlay, true, &channel );
// set a callback for the channel
channel->setCallback( (FMOD_CHANNEL_CALLBACK)&endCallback );
ERRCHECK( result );
std::cout << "Result: " << result;
return channel;
}[/code:1dn1zl53]
and I pass the userdata ( in my case a WaveWidget object containing the QTimer I would stop ) so:
[code:1dn1zl53]void WaveWidget::playSound()
{
FMOD_RESULT result;
m_wave->playSound( 0, 0 );
result = m_wave->getCurrentChannel()->setUserData((void*)this); // user data
timer->start( 16 );
}[/code:1dn1zl53]
My code never enter in the callback code even if the sound effectively stop to play.
Where my code is wrong?
Best Regards,
Franco
- franco.amato asked 8 years ago
- You must login to post comments
[code:3aydk2fv]
channel->setCallback( (FMOD_CHANNEL_CALLBACK)&endCallback ); [/code:3aydk2fv]
If you have to cast your callback you’re doing something wrong. Take another look at the types of the arguments for your callback.
-Pete
- Guest answered 8 years ago
- You must login to post comments
[quote="peter":5ds0sxbd][code:5ds0sxbd]
channel->setCallback( (FMOD_CHANNEL_CALLBACK)&endCallback ); [/code:5ds0sxbd]
If you have to cast your callback you’re doing something wrong. Take another look at the types of the arguments for your callback.
-Pete[/quote:5ds0sxbd]
I didn’t get you. In a past project I used the same systax and all goes well.
What’s wrong? I don’t have to cast in the setCallback call?
- franco.amato answered 8 years ago
- You must login to post comments
[quote="peter":2sfk0bvx][code:2sfk0bvx]
channel->setCallback( (FMOD_CHANNEL_CALLBACK)&endCallback ); [/code:2sfk0bvx]
If you have to cast your callback you’re doing something wrong. Take another look at the types of the arguments for your callback.
-Pete[/quote:2sfk0bvx]
I removed the cast and now I got a compiler error:
[quote:2sfk0bvx] error C2664: ‘FMOD::Channel::setCallback’ : cannot convert parameter 1 from ‘FMOD_RESULT (__stdcall *)(FMOD_CHANNEL *,FMOD_CHANNEL_CALLBACKTYPE,unsigned int,unsigned int)’ to ‘FMOD_CHANNEL_CALLBACK’
[/quote:2sfk0bvx]
- franco.amato answered 8 years ago
- You must login to post comments
[quote="franco":2b78emjc][quote="peter":2b78emjc][code:2b78emjc]
channel->setCallback( (FMOD_CHANNEL_CALLBACK)&endCallback ); [/code:2b78emjc]
If you have to cast your callback you’re doing something wrong. Take another look at the types of the arguments for your callback.
-Pete[/quote:2b78emjc]
I removed the cast and now I got a compiler error:
[quote:2b78emjc] error C2664: ‘FMOD::Channel::setCallback’ : cannot convert parameter 1 from ‘FMOD_RESULT (__stdcall *)(FMOD_CHANNEL *,FMOD_CHANNEL_CALLBACKTYPE,unsigned int,unsigned int)’ to ‘FMOD_CHANNEL_CALLBACK’
[/quote:2b78emjc][/quote:2b78emjc]
I solved the problem. I didn’t call update()
- franco.amato answered 8 years ago
- You must login to post comments
[quote="peter":1qp2ezte]Is the channel looping?[/quote:1qp2ezte]
no, is not looping
- franco.amato answered 8 years ago
- You must login to post comments
Please login first to submit.