Found and fixed bug with looping 3d sounds!
by Josef Jahn · in Torque Game Engine · 08/22/2003 (11:16 am) · 11 replies
Hey all, great news!
I was finally able to get ALL looping sounds (vehicles, static, you name it) to work correctly - and on every openAL dll that I had (4 different versions, including the latest one).
I found out that the looping sound wasn't played depending on where it was initially spawned. Well it DID play, but on some strange location in the middle of the map, below the ground. First I tried "fixing" that by not supplying a transformation matrix with the initial alxPlay(), but that ruined left/right balance.
What finally fixed it was a change in audio.cc, in function alxCreateSource(). Look for these lines:
...and change this to...
Also note that I ALWAYS call "alxUpdateMaxDistance()" in alxUpdate() because otherwise the looping samples will never reach zero volume even if you're millions of miles away, and my code of this function looks like this:
Then I fixed the "stuttering" that happens on some audio cards by modifying the function "updateEngineSound" in wheeledVehicle.cc, hoverVehicle.cc and flyingVehicle.cc - Just comment out this line:
In short: do not modify the gain here, or you'll have a stuttering looping sound.
Whatcha think? Did I forget anything critical here? Does it work for you too?
BTW, I modified audio.cc to support a minimum sound distance. That way you can have different samples depending on how far away you are. That's really nice for big, distant explosions. Just tell me if you're interested ;)
I was finally able to get ALL looping sounds (vehicles, static, you name it) to work correctly - and on every openAL dll that I had (4 different versions, including the latest one).
I found out that the looping sound wasn't played depending on where it was initially spawned. Well it DID play, but on some strange location in the middle of the map, below the ground. First I tried "fixing" that by not supplying a transformation matrix with the initial alxPlay(), but that ruined left/right balance.
What finally fixed it was a change in audio.cc, in function alxCreateSource(). Look for these lines:
// try and find an available source: 0 volume loopers get added to inactive list if (volume > MIN_GAIN)
...and change this to...
// try and find an available source: 0 volume loopers get added to inactive list if (true)
Also note that I ALWAYS call "alxUpdateMaxDistance()" in alxUpdate() because otherwise the looping samples will never reach zero volume even if you're millions of miles away, and my code of this function looks like this:
void alxUpdateMaxDistance()
{
Point3F listener;
alGetListener3f(AL_POSITION, &listener.x, &listener.y, &listener.z);
for(U32 i = 0; i < mNumSources; i++)
{
if(mHandle[i] == NULL_AUDIOHANDLE)
continue;
LoopingList::iterator itr = mLoopingList.findImage(mHandle[i]);
if(itr && (*itr)->mDescription.mIs3D)
{
Point3F pos = (*itr)->mPosition - listener;
F32 dist = pos.magnitudeSafe();
F32 min = (*itr)->mDescription.mReferenceDistance;
F32 max = (*itr)->mDescription.mMaxDistance;
if(dist > max)
mSourceVolume[i] = 0.0f;
else if(dist > min)
mSourceVolume[i] = (*itr)->mDescription.mVolume * (min / dist);
else
mSourceVolume[i] = (*itr)->mDescription.mVolume;
F32 vol = mSourceVolume[i] * mAudioTypeVolume[mType[i]] * mMasterVolume;
alSourcef(mSource[i], AL_GAIN, vol);
}
}
}Then I fixed the "stuttering" that happens on some audio cards by modifying the function "updateEngineSound" in wheeledVehicle.cc, hoverVehicle.cc and flyingVehicle.cc - Just comment out this line:
//alxSourcef(mEngineSound, AL_GAIN_LINEAR, level);
In short: do not modify the gain here, or you'll have a stuttering looping sound.
Whatcha think? Did I forget anything critical here? Does it work for you too?
BTW, I modified audio.cc to support a minimum sound distance. That way you can have different samples depending on how far away you are. That's really nice for big, distant explosions. Just tell me if you're interested ;)
#2
12/13/2003 (11:08 am)
Awesome, Thanks!
#3
12/13/2003 (11:54 am)
Check it in to the head!
#4
12/13/2003 (11:58 am)
Yes Check it into the head!
#5
12/13/2003 (12:01 pm)
Wait till Monday. :)
#6
12/13/2003 (1:48 pm)
Yay, my first contribution to HEAD ;)
#7
12/14/2003 (9:58 am)
Hmmm, i tried this and it completely messed up my sound; It caused my player to sound like he was constantly shooting. However, it made the engine sound play which I haven't heard before, and, some of the sounds appeared to be clearer.
#8
12/14/2003 (12:08 pm)
Testing... Darn funny how it finds bugs. ;)
#9
12/14/2003 (3:18 pm)
I tried this and our music became like an audio emitter. It would only play when you were within a certain radius of where you spawned from. Also, it would loop 5 or so second of music instead of playing the whole track. Although, that could be our problem, not this code.
#10
Anyways, in case of doubt just skip the changes to updateMaxDistance. As I stated in my starting post, I implemented a system that allows different samples being played depending on distance - something I believe should be supported by stock Torque as well ;) - hence your mileage may vary on this back-ported feature-stripped snippet of code.
Experiment with it a little, though if your music acts like an audio emitter I don't think I'm to be blamed ;)
12/15/2003 (1:08 am)
Hmm... There must be something else changed in HEAD which causes these problems. I haven't been in touch with HEAD for a few months due to a strange, annoying thing called work.Anyways, in case of doubt just skip the changes to updateMaxDistance. As I stated in my starting post, I implemented a system that allows different samples being played depending on distance - something I believe should be supported by stock Torque as well ;) - hence your mileage may vary on this back-ported feature-stripped snippet of code.
Experiment with it a little, though if your music acts like an audio emitter I don't think I'm to be blamed ;)
#11
I need to use this AL_GAIN_LINEAR to adjust my engine sound...
10/08/2004 (4:29 am)
Did anyone find a cleaner way to stop stuttering ?I need to use this AL_GAIN_LINEAR to adjust my engine sound...
Torque Owner SeanT
Uneik Software