Game Development Community

Torque Audio

by Aleksander · in Torque Game Engine · 12/28/2005 (8:28 pm) · 2 replies

When I launch a demo (or other MODs) on my computer, I don't hear any sounds. But on another computers sounds work fine.

I looked for the problem on the forums. And I found that some people have the same problem. But nobody give a solution.

I tried to debug to find out the problem. And I found It! Let's look at the code:
"engine\audio\audio.cc", function "bool OpenALInit()", line with instruction "alGenSources(mRequestSources, mSource);"
An "mRequestSources" is a static variable which assigned
static U32 mRequestSources = MAX_AUDIOSOURCES; // number of sources to request from openAL
where
#define MAX_AUDIOSOURCES 16 // maximum number of concurrent sources

So, after "alGenSources" I used "alGetError", and it returned to me "AL_INVALID_VALUE". I changed "MAX_AUDIOSOURCES" to 8. Then I recompiled and reran the demo. And sounds began to work!!!

So, instead of "alGenSources(mRequestSources, mSource);", I have made such construction:

ALenum err = alGetError();
mRequestSources = MAX_AUDIOSOURCES;
while (true)
{
alGenSources(mRequestSources, mSource);
err = alGetError();
if (err == AL_NO_ERROR)
{
break;
}
mRequestSources--;
if (mRequestSources == 0)
{
OpenALShutdown();
return (false);
}
}
mNumSources = mRequestSources;

I checked that on my computer "mRequestSources" became equal to 14!
After that I have replaced all occurences of "MAX_AUDIOSOURCES" by "mRequestSources", for example, instead of

for (U32 i=0; i if(mHandle[i] && areEqualHandles(mHandle[i], handle))
return i;
return MAX_AUDIOSOURCES;

I have wrote

for (U32 i=0; i if(mHandle[i] && areEqualHandles(mHandle[i], handle))
return i;
return mRequestSources;

And all works fine for different computers.

#1
12/28/2005 (10:16 pm)
I just tried this and it does seem to work well.
#2
12/31/2005 (2:39 pm)
Awesome - thanks for debugging this one. It explains a lot of weirdness. :)

Issue #1014.