alxPlay() BUG
by Vern Jensen · in Torque Game Builder · 01/15/2009 (11:37 am) · 5 replies
I've mentioned this before, but did a little more testing, and can confirm this is indeed a bug.
Step 1: Use alxPlay() to play a looping background audio file. (I happen to be using .ogg.)
Step 2: Add the code below, using two of your favorite non-looping sound effects:
moveMap.bindCmd(keyboard, "b", "alxPlay(explosionSnd);", "");
moveMap.bindCmd(keyboard, "n", "alxPlay(insectDeath2Snd);", "");
While the program is running and music is playing, type "b" and "n" keys repeatedly about 9 times very quickly, i.e. in less than a second. Music will stop and start over. Giving it an AudioProfile with a different "type" does not do anything.
Any ideas what I can change in the engine to avoid this bug???
Step 1: Use alxPlay() to play a looping background audio file. (I happen to be using .ogg.)
Step 2: Add the code below, using two of your favorite non-looping sound effects:
moveMap.bindCmd(keyboard, "b", "alxPlay(explosionSnd);", "");
moveMap.bindCmd(keyboard, "n", "alxPlay(insectDeath2Snd);", "");
While the program is running and music is playing, type "b" and "n" keys repeatedly about 9 times very quickly, i.e. in less than a second. Music will stop and start over. Giving it an AudioProfile with a different "type" does not do anything.
Any ideas what I can change in the engine to avoid this bug???
#2
01/15/2009 (2:35 pm)
I tried this out and don't have the bug your talking about. The looping file just continues to play while the non-looping files play repeatedly. It doesn't start over. Can you post the audio file code you're using. Also could you post your computer audio specs, so we could if a hardware problem. (What sound card do you have?)
#3
If that's not the problem, sure I can post my code, but it'd probably be better for me to post the audio files I'm using.
01/15/2009 (2:52 pm)
I'm running on a Mac. Maybe it's a Mac-specific bug? (Hence why no one else has reported it yet?)If that's not the problem, sure I can post my code, but it'd probably be better for me to post the audio files I'm using.
#4
01/16/2009 (1:47 am)
I also had this problem (and many others with the TGB audio subsystem) while developing Zompocalypse. TGB Audio is a legacy system and has a variety of problems over a variety of hardware types.
#5
01/16/2009 (12:18 pm)
What were some of the other audio problems you had? And how did you resolve them?
Torque Owner Vern Jensen
/source/audio/audio.cc
Apparently a long time ago, there used to be code in audio.cc that would put the mScore[index] for a source at a high enough value that looping sounds (i.e. music) would never be culled in order to play new sounds. But somehow this code got removed somewhere. My "solution" however uses recursion and could cause a crash if all channels are filled with looping sounds. In my game this will never happen, so it's not a potential issue, but if your game that might happen, then don't use this quick fix. There are many other ways to avoid the problem without using recursion.
To apply my fix, search for the method "cullSource" in audio.cc and change the middle of that method to:
[code]
// check if culling a looper
LoopingList::iterator itr = mLoopingList.findImage(mHandle[best]);
if(itr)
{
// check if culling an inactive looper
if(mHandle[best] & AUDIOHANDLE_INACTIVE_BIT)
{
AssertFatal(!mLoopingInactiveList.findImage(mHandle[best]), "cullSource: image already in inactive list");
AssertFatal(!mLoopingCulledList.findImage(mHandle[best]), "cullSource: image should not be in culled list");
mLoopingInactiveList.push_back(*itr);
}
else
{
// EDIT BY VERN TO ENSURE THAT LOOPING SOUNDS ARE NEVER CULLED (ended early to make room for new sounds).
// This avoids a bug where music would stop and start over if too many other sfx played and filled up all 16 channels.
// (*itr)->mHandle |= AUDIOHANDLE_INACTIVE_BIT;
// AssertFatal(!mLoopingCulledList.findImage(mHandle[best]), "cullSource: image already in culled list");
// AssertFatal(!mLoopingInactiveList.findImage(mHandle[best]), "cullSource: image should not be in inactive list");
// (*itr)->mCullTime = Platform::getRealMilliseconds();
// mLoopingCulledList.push_back(*itr);
mScore[best] += 2.0; // Make the next call to cullSource NOT consider this looping sound as one that can be culled
return cullSource(index, volume);
}
}
[code]
Notice that I simply commented out a number of lines of code, and then added 2 new lines below that.