Audio problem
by Martin Andresen · in Torque Game Builder · 10/22/2007 (6:14 am) · 8 replies
We are in the middle of testing our game and are occasionaly getting a weird audio problem. Sometimes the game will suddenly begin looping the sound played, even though it is not supposed to be looped. All sounds are loaded into memory when game is started up, except music files which we stream. Sounds are not streamed. Maybe it is an interference between the music streams, which we loop, and an audio file being played? The sounds are played with alxPlay and use an AudioDescription with isLooping set to false and isStreaming set to false.
We use TGB 1.1.3 and OpenAL 1.1. The problem has been experienced on both Windows XP and Vista. Anyone else has seen problems like this or has any solutions or workarounds?
Any help or ideas would be greatly appreciated!
We use TGB 1.1.3 and OpenAL 1.1. The problem has been experienced on both Windows XP and Vista. Anyone else has seen problems like this or has any solutions or workarounds?
Any help or ideas would be greatly appreciated!
#2
10/22/2007 (8:37 am)
I implemented your suggestion, so hopefully that will be good enough to fix this problem. Thanks!
#3
The first leads I saw were in this thread:
http://www.torquepowered.com/community/forums/viewthread/34446
They seem to fix Looping Streaming Audio for the most part, Unfortunately, Non-looping streaming audio was also stuck as looping and would sometimes play another sound prior to repeating itself.
I've implemented some fixes in audio.cc, but I have only initial testing done to see if they are working.
after implementing the fixes in the above thread:
in audio.cc replace alxStreamingUpdate
that should be it.
01/20/2010 (2:38 pm)
I've been looking at this lately and think we have a solution to this problem.The first leads I saw were in this thread:
http://www.torquepowered.com/community/forums/viewthread/34446
They seem to fix Looping Streaming Audio for the most part, Unfortunately, Non-looping streaming audio was also stuck as looping and would sometimes play another sound prior to repeating itself.
I've implemented some fixes in audio.cc, but I have only initial testing done to see if they are working.
after implementing the fixes in the above thread:
in audio.cc replace alxStreamingUpdate
that should be it.
void alxStreamingUpdate()
{
// update buffer queues on active streamers
// update the loopers
for(StreamingList::iterator itr = mStreamingList.begin(); itr != mStreamingList.end(); itr++)
{
if((*itr)->mHandle & AUDIOHANDLE_INACTIVE_BIT)
continue;
(*itr)->updateBuffers();
}
static StreamingList culledList;
U32 updateTime = Platform::getRealMilliseconds();
// check if can wakeup the inactive loopers
if(mStreamingCulledList.size())
{
Point3F listener;
alxGetListenerPoint3F(AL_POSITION, &listener);
// get the 'sort' value for this sound (could be based on time played...),
// and add to the culled list
StreamingList::iterator itr;
culledList.clear();
for(itr = mStreamingCulledList.begin(); itr != mStreamingCulledList.end(); itr++)
{
if((*itr)->mScore <= MIN_UNCULL_GAIN)
continue;
if((updateTime - (*itr)->mCullTime) < MIN_UNCULL_PERIOD)
continue;
culledList.push_back(*itr);
}
if(!culledList.size())
return;
U32 index = MAX_AUDIOSOURCES;
if(culledList.size() > 1)
culledList.sort();
for(itr = culledList.begin(); itr != culledList.end(); itr++)
{
if(!findFreeSource(&index))
{
// score does not include master volume
if(!cullSource(&index, (*itr)->mScore))
break;
// check buffer
//if(!bool((*itr)->mBuffer))
//{
// remove from culled list
StreamingList::iterator tmp;
tmp = mStreamingCulledList.findImage((*itr)->mHandle);
AssertFatal(tmp, "alxStreamingUpdate: failed to find culled source");
mStreamingCulledList.erase_fast(tmp);
// remove from streaming list (and free)
tmp = mStreamingList.findImage((*itr)->mHandle);
if(tmp)
{
delete(*tmp);
mStreamingList.erase_fast(tmp);
}
continue;
//}
}
// remove from culled list
// DEVIN Added
if(!(*itr)->mDescription.mIsLooping){
StreamingList::iterator tmp;
tmp = mStreamingCulledList.findImage((*itr)->mHandle);
AssertFatal(tmp, "alxStreamingUpdate: failed to find culled source");
mStreamingCulledList.erase_fast(tmp);
// remove from streaming list (and free)
tmp = mStreamingList.findImage((*itr)->mHandle);
if(tmp)
{
delete(*tmp);
mStreamingList.erase_fast(tmp);
}
continue;
}
// END DEVIN
StreamingList::iterator tmp = mStreamingCulledList.findImage((*itr)->mHandle);
AssertFatal(tmp, "alxStreamingUpdate: failed to find culled source");
mStreamingCulledList.erase_fast(tmp);
// restore all state data
mHandle[index] = (*itr)->mHandle;
mHandle[index] |= AUDIOHANDLE_LOADING_BIT & AUDIOHANDLE_STREAMING_BIT;
mScore[index] = (*itr)->mScore;
mScorePriority[index] = 2; // DEVIN
mSourceVolume[index] = (*itr)->mDescription.mVolume;
mType[index] = (*itr)->mDescription.mType;
mSampleEnvironment[index] = (*itr)->mEnvironment;
ALuint source = mSource[index];
(*itr)->mSource = mSource[index];
alxSourcePlay(*itr); // DEVIN moved from above restore all state data.
// setup play info
alGetError();
if(mEnvironmentEnabled)
alxSourceEnvironment(source, *itr);
alxPlay(mHandle[index]);
}
}
}
#4
This doesnt work yet, eventually audio stops playing. I think it has something to do with the other threads fixes. I'll write back soon.
01/21/2010 (10:57 am)
Warning:This doesnt work yet, eventually audio stops playing. I think it has something to do with the other threads fixes. I'll write back soon.
#5
http://www.torquepowered.com/community/forums/viewthread/34446
It seems that fix was not allowing streaming audio to be culled ever.
01/21/2010 (12:00 pm)
I fixed it by removing the priority part of this threads fix:http://www.torquepowered.com/community/forums/viewthread/34446
It seems that fix was not allowing streaming audio to be culled ever.
#6
01/22/2010 (8:54 pm)
Since implementing this solution, we've found that some shorter, streamed, non-looping sounds will reliably crash TGB right after they are played. We're looking into it.
#7
01/25/2010 (11:52 am)
An addendum to Daniels post: this only seems to happen on Mac.
#8
http://www.torquepowered.com/community/resources/view/19227
01/26/2010 (11:41 am)
Ok, We've got the whole thing compile here:http://www.torquepowered.com/community/resources/view/19227
Torque Owner DragonSix