0

I am trying to implement streaming audio and I've run into a problem where OpenAL is giving me an error codes seems impossible given the information in the documentation.

int buffersProcessed = 0;
alGetSourcei(m_Source, AL_BUFFERS_PROCESSED, &buffersProcessed);
PrintALError();

int toAddBufferIndex;

// Remove the first buffer from the queue and move it to 
//the end after buffering new data.
if (buffersProcessed > 0)
{
    ALuint unqueued;
    alSourceUnqueueBuffers(m_Source, 1, &unqueued);
                       /////////////////////////////////
    PrintALError();    // Prints AL_INVALID_OPERATION //
                       /////////////////////////////////
    toAddBufferIndex = firstBufferIndex;
}

According to the documentation [PDF], AL_INVALID_OPERATION means: "There is no current context." This seems like it can't be true because OpenAL has been, and continues to play other audio just fine!

Just to be sure, I called ALCcontext* temp = alcGetCurrentContext( ); here and it returned a valid context.

Is there some other error condition that's possible here that's not mentioned in the docs?

More details: The sound source is playing when this code is being called, but the impression I got from reading the spec is you can safely unqueue processed buffers while the source is playing. PrintALError is just a wrapper for alGetError that prints if there is any error.

I am on a Mac (OS 10.8.3), in case it matters.

Tim R.
  • 1,570
  • 2
  • 15
  • 33
  • It may just be that getting the error code when a function is successful is undefined? So the function may be successful, but you print the error code anyway so it's not valid. You should check if the function fail before printing an error. – Some programmer dude May 30 '13 at 11:51
  • 1
    alGetError() is the way of checking if the function failed in OpenAL, and that's what PrintALError does. Calling PrintALError when there is no error gets the error code AL_NO_ERROR and I do not print anything in that case. – Tim R. May 30 '13 at 11:55

2 Answers2

0

So far what I've gathered is that it seems this OpenAL implementation incorrectly throws an error if you unqueue a buffer while the source is playing. The spec says that you should be able to unqueue a buffer that has been marked as processing while the source is playing:

Removal of a given queue entry is not possible unless either the source is stopped (in which case then entire queue is considered processed), or if the queue entry has already been processed (AL_PLAYING or AL_PAUSED source).

On that basis I'm gonna say this is probably a bug in my OpenAL implementation. I'm gonna leave the question open in case someone can give a more concrete answer though.

Tim R.
  • 1,570
  • 2
  • 15
  • 33
-1

To handle condition for multiple buffers use a loop. Following works on iOS and linux :



// UN queue used buffers

ALint buffers_processed = 0;

alGetSourcei(streaming_source, AL_BUFFERS_PROCESSED, & buffers_processed);   // get source parameter num used buffs

while (buffers_processed > 0) {     // we have a consumed buffer so we need to replenish


    ALuint unqueued_buffer;

    alSourceUnqueueBuffers(streaming_source, 1, & unqueued_buffer);

    available_AL_buffer_array_curr_index--;

    available_AL_buffer_array[available_AL_buffer_array_curr_index] = unqueued_buffer;

    buffers_processed--;
}
Scott Stensland
  • 26,870
  • 12
  • 93
  • 104
  • Did you read the question? My loop is elsewhere, I have to unqueue just one buffer because of the way the engine is structured. – Tim R. May 31 '13 at 00:54