Jump to content

  • Log In with Google      Sign In   
  • Create Account

OpenGL + OpenAL


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
9 replies to this topic

#1 rehcarlos   Members   -  Reputation: 118

Like
0Likes
Like

Posted 07 July 2013 - 10:07 AM

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,

 



Sponsor:

#2 kauna   Crossbones+   -  Reputation: 2557

Like
0Likes
Like

Posted 07 July 2013 - 11:22 AM

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!


Edited by kauna, 07 July 2013 - 11:23 AM.


#3 rehcarlos   Members   -  Reputation: 118

Like
0Likes
Like

Posted 07 July 2013 - 12:01 PM

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?


Edited by rehcarlos, 07 July 2013 - 12:01 PM.


#4 Chananya Freiman   Members   -  Reputation: 140

Like
0Likes
Like

Posted 07 July 2013 - 12:15 PM

Probably by just not running a do-while?

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


Edited by Chananya Freiman, 07 July 2013 - 12:15 PM.


#5 rehcarlos   Members   -  Reputation: 118

Like
0Likes
Like

Posted 07 July 2013 - 12:17 PM

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 :/



#6 Chananya Freiman   Members   -  Reputation: 140

Like
0Likes
Like

Posted 07 July 2013 - 12:34 PM

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.



#7 rehcarlos   Members   -  Reputation: 118

Like
0Likes
Like

Posted 07 July 2013 - 12:40 PM

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



#8 Chananya Freiman   Members   -  Reputation: 140

Like
0Likes
Like

Posted 07 July 2013 - 12:46 PM

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
}

Edited by Chananya Freiman, 07 July 2013 - 12:53 PM.


#9 kauna   Crossbones+   -  Reputation: 2557

Like
0Likes
Like

Posted 07 July 2013 - 01:01 PM


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!



#10 rehcarlos   Members   -  Reputation: 118

Like
1Likes
Like

Posted 07 July 2013 - 01:04 PM

You're right kauna

 

anyway, Freiman got it right

 

its finally working how I wanted it to :D

 

thanks everybody






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS