Switching buffers dynamically

View: New views
4 Messages — Rating Filter:   Alert me  

Switching buffers dynamically

by bpazolli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hey, I am trying to switch buffer data dynamically (i.e. during program execution). I tried just using an alBufferData command to link new data to the existing buffer; that didn't work. I then tried deleting the buffer & source using their respective alDelete commands and then building new ones with the new buffer date; that didn't work. So I am at a loss as to how I can actually switch. Do I have to stop playback or some other step? I don't know.

Any help appreciated,
Ben Pazolli

Re: Switching buffers dynamically

by Jason Daly :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

bpazolli wrote:
> Hey, I am trying to switch buffer data dynamically (i.e. during program
> execution). I tried just using an alBufferData command to link new data to
> the existing buffer; that didn't work. I then tried deleting the buffer &
> source using their respective alDelete commands and then building new ones
> with the new buffer date; that didn't work. So I am at a loss as to how I
> can actually switch. Do I have to stop playback or some other step? I don't
> know.
>  

alBufferData works fine for updating a buffer's data during execution.  
Most likely, your buffer is still assigned to a source while you're
trying to change it, which isn't permitted.  If you're statically
assigning the buffer to a source, remove it with alSourcei(sid,
AL_BUFFER, 0).  If you're using the buffer queue, unqueue the buffer
(using alUnqueueBuffers() ).

If that's not the problem, check the error code after the alBufferData
command (call alGetError before the alBufferData call to reset the error
state, then call it again after the alBufferData call to get the error
code).

--"J"

_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Switching buffers dynamically

by Chris Robinson-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Saturday 09 May 2009 8:57:38 pm bpazolli wrote:
> Hey, I am trying to switch buffer data dynamically (i.e. during program
> execution). I tried just using an alBufferData command to link new data to
> the existing buffer; that didn't work. I then tried deleting the buffer &
> source using their respective alDelete commands and then building new ones
> with the new buffer date; that didn't work. So I am at a loss as to how I
> can actually switch. Do I have to stop playback or some other step? I don't
> know.

Yes, you have to stop the source. If you want to modify/delete a buffer, it
has to be detached from the source (call alSourcei(source, AL_BUFFER, 0); on
all sources it's currently set on), which can only be done when the source is
stopped. You can also just set a different buffer on the source (which
implicitly detaches the previous buffer), while it's stopped.
_______________________________________________
Openal mailing list
Openal@...
http://opensource.creative.com/mailman/listinfo/openal

Re: Switching buffers dynamically

by bpazolli :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


Jason Daly wrote:
alBufferData works fine for updating a buffer's data during execution.  
Most likely, your buffer is still assigned to a source while you're
trying to change it, which isn't permitted.  If you're statically
assigning the buffer to a source, remove it with alSourcei(sid,
AL_BUFFER, 0).  If you're using the buffer queue, unqueue the buffer
(using alUnqueueBuffers() ).

If that's not the problem, check the error code after the alBufferData
command (call alGetError before the alBufferData call to reset the error
state, then call it again after the alBufferData call to get the error
code).
That was the problem it all works now. Thanks all. I also had to alSourceStop before removing the buffer to get it to work.

Thank You All,
Ben Pazolli