diff --git a/indra/llaudio/llaudioengine_openal.cpp b/indra/llaudio/llaudioengine_openal.cpp index b7905941136b84d7fc919e0668e32a5c58083f99..01839f29ac6e26fc9a93479cc5e30215970105d4 100644 --- a/indra/llaudio/llaudioengine_openal.cpp +++ b/indra/llaudio/llaudioengine_openal.cpp @@ -74,7 +74,7 @@ bool LLAudioEngine_OpenAL::init(const S32 num_channels, void* userdata, const st ALCdevice *device = alcGetContextsDevice(alcGetCurrentContext()); alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &major); - alcGetIntegerv(device, ALC_MAJOR_VERSION, 1, &minor); + alcGetIntegerv(device, ALC_MINOR_VERSION, 1, &minor); LL_INFOS() << "ALC version: " << major << "." << minor << LL_ENDL; LL_INFOS() << "ALC default device: " @@ -176,6 +176,8 @@ LLAudioChannelOpenAL::~LLAudioChannelOpenAL() void LLAudioChannelOpenAL::cleanup() { alSourceStop(mALSource); + alSourcei(mALSource, AL_BUFFER, AL_NONE); + mCurrentBufferp = NULL; } @@ -322,7 +324,14 @@ void LLAudioBufferOpenAL::cleanup() { if(mALBuffer != AL_NONE) { + alGetError(); // clear error alDeleteBuffers(1, &mALBuffer); + + ALenum error = alutGetError(); + if(ALC_NO_ERROR != error) + { + LL_WARNS("OpenAL") << "Error: " << alutGetErrorString( error ) << " when cleaning up a buffer" << LL_ENDL; + } mALBuffer = AL_NONE; } } @@ -439,6 +448,7 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) F64 pitch; F64 center_freq; ALenum error; + ALuint *buffers = NULL; if (!mEnableWind) return; @@ -452,7 +462,6 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) // wind comes in as Linden coordinate (+X = forward, +Y = left, +Z = up) // need to convert this to the conventional orientation DS3D and OpenAL use // where +X = right, +Y = up, +Z = backwards - wind_vec.setVec(-wind_vec.mV[1], wind_vec.mV[2], -wind_vec.mV[0]); pitch = 1.0 + mapWindVecToPitch(wind_vec); @@ -483,57 +492,67 @@ void LLAudioEngine_OpenAL::updateWind(LLVector3 wind_vec, F32 camera_altitude) //LL_INFOS() << "mNumEmptyWindALBuffers: " << mNumEmptyWindALBuffers <<" (" << unprocessed << ":" << processed << ")" << LL_ENDL; - while(processed--) // unqueue old buffers + //delete the old wind buffers + buffers = new ALuint[processed]; + alGetError(); /* clear error */ + alSourceUnqueueBuffers(mWindSource, processed, &buffers[0]); + error = alGetError(); + if(error != AL_NO_ERROR) { - ALuint buffer; - ALenum error; - alGetError(); /* clear error */ - alSourceUnqueueBuffers(mWindSource, 1, &buffer); - error = alGetError(); - if(error != AL_NO_ERROR) - { - LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() error swapping (unqueuing) buffers" << LL_ENDL; - } - else - { - alDeleteBuffers(1, &buffer); - } + LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() error swapping (unqueuing) buffers" << LL_ENDL; + } + else + { + alDeleteBuffers(processed, &buffers[0]); } + // We dont need to keep track of the buffers' id now. + delete[] buffers; + buffers = NULL; + //create the buffers for the empty wind buffers unprocessed += mNumEmptyWindALBuffers; - while (mNumEmptyWindALBuffers > 0) // fill+queue new buffers + buffers = new ALuint[mNumEmptyWindALBuffers]; + alGetError(); /* clear error */ + alGenBuffers(mNumEmptyWindALBuffers,&buffers[0]); + if((error=alGetError()) != AL_NO_ERROR) { - ALuint buffer; - alGetError(); /* clear error */ - alGenBuffers(1,&buffer); - if((error=alGetError()) != AL_NO_ERROR) - { - LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() Error creating wind buffer: " << error << LL_ENDL; - break; - } + LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() Error creating wind buffer: " << error << LL_ENDL; + //break; + } - alBufferData(buffer, - AL_FORMAT_STEREO16, - mWindGen->windGenerate(mWindBuf, - mWindBufSamples), - mWindBufBytes, - mWindBufFreq); + //fill the buffers with generated wind. + int errors = 0; + for(int i = 0; i < mNumEmptyWindALBuffers; i++) + { + alBufferData(buffers[i], + AL_FORMAT_STEREO16, + mWindGen->windGenerate(mWindBuf, + mWindBufSamples), + mWindBufBytes, + mWindBufFreq); error = alGetError(); if(error != AL_NO_ERROR) { LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() error swapping (bufferdata) buffers" << LL_ENDL; + errors++; } - - alSourceQueueBuffers(mWindSource, 1, &buffer); - error = alGetError(); - if(error != AL_NO_ERROR) - { - LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() error swapping (queuing) buffers" << LL_ENDL; - } + } - --mNumEmptyWindALBuffers; + //queue the buffers + alSourceQueueBuffers(mWindSource, mNumEmptyWindALBuffers, &buffers[0]); + error = alGetError(); + if(error != AL_NO_ERROR) + { + LL_WARNS() << "LLAudioEngine_OpenAL::updateWind() error swapping (queuing) buffers" << LL_ENDL; } + mNumEmptyWindALBuffers = errors; + // We dont need to keep track of the buffers' id now. + delete[] buffers; + buffers = NULL; + + + //restart playing if not playing ALint playing; alGetSourcei(mWindSource, AL_SOURCE_STATE, &playing); if(playing != AL_PLAYING)