OpenGL + OpenAL

Started by
8 comments, last by rehcarlos 10 years, 9 months ago

I have a scene that is modified when mouse left button is clicked.

My problem is: this modified scene was supposed to appear with a sound, but the scene waits the sounds to finish before it renders itself.

I'm using this function:


do {
        alGetSourcei(source, AL_SOURCE_STATE, &state);
 } while (state == AL_PLAYING);

Of course, this function tells the program to wait. But what alternative could I use? if I remove this function, the sound isnt played

I even tried to create a function sound(), that is called after glutPostRedisplay but it still waits the sound complete to render

Thanks in advance,

Advertisement

Yes, obviously you program waits until the sound is played.

I assume that you call "alSourcePlay(source)" before the wait loop?

Do you check for errors? OpenAL is very sensitive about passed parameters. Check errors after each function call.

Cheers!

Yes, I'm using alSourcePlay(source) before the loop

I dont think I have errors... because the program is following the instructions... but... how can I play a sound without using that do-while that is stopping my scene?

Probably by just not running a do-while?

Every frame call it once while checking if it finished playing.

I tried without the loop, but the sound isnt even played :/

I believe that what happens is:

play

delete buffers

delete source

But the delete buffers/source happens so fast that the sound is killed; is just my opinion though :/

Why would you delete the buffers and source before the sound finishes?

That's the whole point of the state argument.

Only when the state is not AL_PLAYING do you delete them.

You are completely right Freiman, thats the point of the loop, but this loop makes my scene stop, until sound is over. I need sound and scene to run together

What I need is a alternative to that loop

You don't need a loop...

Every frame check once if the sound finished running. Only if it finished, THEN you can delete the buffer and source.


alGetSourcei(source, AL_SOURCE_STATE, &state);

if (state != AL_PLAYING) {
    // Delete the buffer and source here
    // But you probably want to do something smarter like not calling alGetSourcei for this source anymore, that's up to you
}


I dont think I have errors... because the program is following the instructions... but... how can I play a sound without using that do-while that is stopping my scene?

Well, think differently. As I stated earlier, use error check after each OpenAL call, although it may not be part of this particular problem.

Indeed, if you delete the source just after calling play, the sound will stop logically ie. the program is following the instructions.

You should show a bigger piece of code in order to know what happening inside your program.

Cheer!

You're right kauna

anyway, Freiman got it right

its finally working how I wanted it to :D

thanks everybody

This topic is closed to new replies.

Advertisement