0
0

Hello,
I have searched this forum for my specific question, but i couldn’t find any answers. So, if i am asking something already discussed, please excuse me, an point me in the right direction.
I am developing a game in C++, and i need to playback a couple sounds and music (specifically mp3’s) the thing is it needs to be done in asyncronous mode, is this possible?
Thank you very much

  • You must to post comments
0
0

Pretty much all of FMOD’s functionality is asynchronous by default. That is, when you call something like System::playsound(), it returns immediately, and the details of playing the sound are handled by FMOD in another thread.

You can also have FMOD load files asynchronously by passing FMOD_NONBLOCKING into the System::createSound() call. You then get a callback when the sound is finished loading, or you can query it from the main thread.

All that said, for most functionality to work properly, you will have to call System::update() frequently in your main thread.

Hope that helps!

  • You must to post comments
0
0

Thank you very much for our response.
Just to clear things up. Every example bundled with the FMOD installer plays the sounds this way:
[code:2sb4tibz]
result = system->createSound("./drumloop.wav", FMOD_HARDWARE, 0, &sound1);
do
{
if (kbhit())
{
result = system->playSound(FMOD_CHANNEL_FREE, sound1, false, &channel);
.
.
}end while();
[/code:2sb4tibz]
So, i should create the thread, or should i just do this?
[code:2sb4tibz]
void Class::func()
{
this->result = this->sistema->createSound("sound-path",FMOD_NONBLOCKING, 0, this->(&sound));
ERRCHECK(this->result);
}
void Class::func2()
{
this->result = system->playSound(FMOD_CHANNEL_FREE, this->sound, false, this->(&canal));
}
[/code:2sb4tibz]

It compiles, but at run-time i get an FMODerror 55.

  • You must to post comments
0
0

[quote="horacv":2otlupa6][code:2otlupa6]
void Class::func()
{
this->result = this->sistema->createSound("sound-path",FMOD_NONBLOCKING, 0, this->(&sound));
ERRCHECK(this->result);
}
void Class::func2()
{
this->result = system->playSound(FMOD_CHANNEL_FREE, this->sound, false, this->(&canal));
}
[/code:2otlupa6]

It compiles, but at run-time i get an FMODerror 55.[/quote:2otlupa6]

FMOD error 55 is FMOD_ERR_NOTREADY, which should provide a hint as to what is going wrong – you need to wait for the sound to be ready before you can play it. The reason you need to wait is because you specified FMOD_NONBLOCKING in the call to createSound – if you don’t specify FMOD_NONBLOCKING, createSound won’t return until the sound is ready. You can check if the sound is ready by calling Sound::getOpenState.

Ben

  • You must to post comments
0
0

I understand. The thing is, i wanted to load the sounds at start up, and use them later in the game. So, the two functions aren’t really being called one after the other. I solved the problem this way:

[code:1m6joo4s]void Class::LoadSounds()
{
result = system->createSound(this->get_sound_path(sound_index),
FMOD_HARDWARE,
0,
&sound[i]);
.
.
}
void Class::PlaySound(int sound_id)
{
result = system->playSound(FMOD_CHANNEL_FREE,
sonido[sound_id],
false,
&channel);

ERRCHECK(result);
.
.
}[/code:1m6joo4s]

and it worked like a charm.
The only thing is, my little game is slowly becoming an mp3/ogg player.
thank you very much for your help.

  • You must to post comments
Showing 4 results
Your Answer

Please first to submit.