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

萝らか妹 提交于 2021-02-07 19:24:26

问题


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.

回答1:


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.




回答2:


Since I stumbled over the same error and this question is the first that appears in search engines, I'd like to quickly post the problem I ran into in hope that it is useful to others. I use stb_vorbis (from https://github.com/nothings/stb) with OpenAL and when I tried to feed the data into OpenAL, I got the same AL_INVALID_VALUE error. It turned out that the buffers have to be a multiple of 4 (at least on the soft_al implementation and with AL_FORMAT_STEREO16 (might be different for other implementations / formats).

bufferSize = stb_vorbis_decode_filename("sound.ogg", &channels, &sampleFrequency, &pcmData);

// Adjust the bufferSize to a multiple of 4
bufferSize = bufferSize - bufferSize%4;

alBufferData(mySoundBuffer, AL_FORMAT_STEREO16, pcmData, bufferSize, sampleFrequency);

I got it working by trial and error, so if you run into this error, you might want to check this as well.

Kind regards, Moritz



来源:https://stackoverflow.com/questions/10996917/openal-albufferdata-returns-al-invalid-value-even-though-input-variables-look

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!