audioaudio-streamingopenaladpcm

OpenAL: alBufferData returns AL_INVALID_VALUE even though input variables *look* OK?


So, I'm building a threaded IMA ADPCM decoder streaming audio data to OpenAL (see below for short description) but I've run into some trouble.

One of my issues is that sometimes my call to alBufferData:

alBufferData(*bufferID, format, pcmData, sizeInBytes, bitRate);

returns AL_INVALID_VALUE even though, when checking the parameters they look, e.g., like this:

bufferID='109770616', format='AL_FORMAT_STEREO16', dataPtr='109754188', sizeInBytes='8164'

Any clues, anyone? The actual sound being played sort of stutteres when this happens, and the error usually happens ~10 times in a row (on the same sound). It also usually happens when I repeatedly start the same sound (for example when shooting short bursts with an LMG... ;))

Quick simplified tour of the streaming-decoder-module-thing

How a sound gets played:

  1. A sound is triggered to play.
  2. One bufferSize worth of audio is decoded and the rest is queued for further decoding.
  3. OpenAL is triggered to start playing the sound.

The decoding/streaming loop

  1. For each sound queued for decoding, decode bufferSize worth of audio.
  2. The decoded audio is added to an alBuffer (see call above) with the appropriate bufferID.

Solution

  • if it's not too late I'll tell you the similar problems I had with BufferData and here's how I fixed it. Although, keep in mind, I don't know the specifics of your threaded program.

    Invalid value is returned for a number of reasons, the ones I know of are...
    -Queuing new buffers (to a streaming source) if the source already has a bufferID assigned (because it gets set to static if you set buffer id). If so, remove the ID in the source property.
    -Changing the buffer format mid play. You can't change any buffer setting (fmt,samplerate) except for the buffer data itself once a source starts playing, even if it is on another queued one.

    It sounds like you might be changing one of these settings in another thread.

    Another thing that may cause pops is replaying the sound. Calling play again just stops the source cold, then rewinds the current buffer and starts playing from the beginning. Playing a gun sound like that won't sound like you want it (layered i assume). 2 options, mix the remaining gun sound into the buffer then replay it, but this might not work. another fool proof is just to use multiple sources and rotate which ones get called on each gun fire.

    good luck on your project.