Game Development Community

Playing music problems alxSourcef

by Clint S. Brewer · in Torque Game Engine · 09/12/2005 (11:52 am) · 10 replies

I'm having a bit of trouble trying to get some control over a sounds volume

I'm using tge 1.3

I'm working on setting up a music fading system.

Problem:
After setting the GAIN of an audio handle to be less than 1.0, when many other sounds start to play, my looping sound seems to be replaced by one of the other sounds, as though it was swapped out.


Here's the test I'm doing
new AudioDescription(AudioMusic)
 {
   volume   = 1.0;
   isLooping = true;
   isStreaming = true;
   is3D     = false;
   type     = $SimAudioType;
};

new AudioProfile(InterfaceStartJourneyMusic)
{
    filename    = "~/data/uegmade/sound/music/ambientGuitar.ogg";
    description = "AudioMusic";
    preload = true;
};

new AudioProfile(InGameDying :InterfaceStartJourneyMusic)
{
	filename    = "~/data/uegmade/sound/music/dying.ogg";
};


function testDeathFade()
{
	$deathFade = alxPlay(InGameDying);
	alxSourcef($deathFade, AL_GAIN, 0.8);
}


new AudioProfile(AudioButtonOverUEG)
{
   filename = "~/data/uegmade/sound/fx/interface/musicalOver.ogg";
   description = "AudioGui";
   preload = true;
};


To make the problem happen, I start up my game,
while in the main menu, bring up the console
type
testDeathFade();
enter

the music starts playing at 0.8 volume, correctly
now I run the mouse over my buttons that play the AudioButtonOverUEG sound
they play fine

now I run the mouse over them really fast, stressing the system
now my Dying music has stopped and I have a looping AudioButtonOverUEG sound going on.

the menu buttons still play the sound properly.


Now if I changes
alxSourcef($deathFade, AL_GAIN, 0.8);

to

alxSourcef($deathFade, AL_GAIN, 1.0);

and run the test again,
it works fine, the death music keeps playing.


Theory
Due to the lower volume, somehow my looping streaming audio profile is getting culled, and once it is culled it doesn't start playing again, now openAL just plays the next available profile, similar to the problem when a .ogg is corrupted and the next profile plays instead.

I'm looking over the culling code, but haven't found the problem yet.

any ideas?

Thanks
-clint

#1
09/12/2005 (11:54 am)
At the top of alxUpdateScores,
I see this comment:
//----------------------------------------------------------------------------------
// - update the score for each audio source.  this is used for culing sources.
//   normal ranges are between 0.f->1.f, voice/loading/music streams are scored
//   outside this range so that they will not be culled
// - does not scale by attenuated volumes

where in the code are the
"voice/loading/music streams" scored outside the range? Maybe that's my problem, I have my music in the same range for some reason.
#2
09/12/2005 (12:04 pm)
Ok I think I see what that comment means,
it passes in a bool, and if that is true,
then it skipps updating scores for looping and streaming sources

in alxUpdate, normally the bool is passed in as false so streams aren't scored,
but in alxCreateSource if we can't find a free resource, it looks like alxUpdateScores is called again passing in true, so the streams get scored..

not sure exactly why that is...
#3
09/12/2005 (12:23 pm)
A little more info:

if I switch it to a plain looping sound instead of a streaming sound,
it gets culled out, but then it pops back into existence as I'd want.

I think that what I want to do is specify false to alxUpdateScores in alxCreateSource unless we are creating a streaming or looping source.


now the secondary bug of what happens when a streaming source is culled needs to be looked at too, but I'll keep focus on one at a time.

any other ideas?
#4
09/12/2005 (12:44 pm)
I take it back, that comment and others insinuate that streams and loopers are scored >1 but that doesn't seem to be the case. at least I couldn't find the spot where they are.
#5
09/12/2005 (3:48 pm)
Ok, found the streaming issue, where if it was a streaming file it would mess up and start playing another file..


in the function void alxCloseHandles()

there is a section of code that pertains to streaming files that's commented out.

It doesn't say why, but I believe it's necessary to handle the streaming files there as well. I didn't really thoroughly analyze it :) but after tracing the problem and uncommenting those lines, my streaming problem went away.


now back to the culling issue :) yay
#6
09/12/2005 (4:37 pm)
Ah I lied...back to the streaming thing... one small change.
That large chunk does need to be uncommented in alxCloseHandles,
but you should comment out the call to freestream

//(*itr2)->freeStream();

I believe if we reach that point the stream will already be free and not need freeing here. This generates some openAL errors later on.

I suppose you could also debug further and find exactly why freeing a stream again generates errors, and if you find out do tell,

me....I like bandaids today!

now...seriously...back to the game playing. I mean culling streams problem...
#7
09/13/2005 (1:32 pm)
Ok for streaming / looping priority here's what I did.

Add a scorePriority variable, this is 0 for normal sounds 1 for looping and 2 for streaming,
although it should probably be read in from the description / profile to give you more control.

top of audio.cc
static U32                    mScorePriority[MAX_AUDIOSOURCES];                 // used to modify the scores, give a priority to sounds

in cullSource the calculation to find the best source becomes
if( (mScore[i] + mScorePriority[i]) < minVolume)
      {
         minVolume = mScore[i] + mScorePriority[i];
         best = i;
      }

in alxCreateSource after the mScore is set
mScorePriority[index] = 0;
   if(desc->mIsLooping)
	      mScorePriority[index] = 1;
   if(desc->mIsStreaming)
	      mScorePriority[index] = 2;

in alxLoopingUpdate after mScore is set

mScorePriority[index] = 1;

and likewise in alxStreamingUpdate
mScorePriority[index] = 2;

so now, non looping/ non streaming sounds will get culled first, then looping, then streaming.
It strikes me that this might not be a good thing as I add more sounds to the level.
I plan to use streaming sources for the larger music and ambient tracks, so I really don't want them culled, so a high priority for them is ok. But I'll be using looping sounds all over the place, and giving them a base priority of 1 might mean close sounds get culled while far away looping ones do not.

just a word of precaution if you decide to use that code above.
#8
09/13/2005 (7:25 pm)
Thanks a ton for sharing this code with us, Clint!
#9
09/13/2005 (11:26 pm)
Very welcome, It's the least I can do for all the updates and code everyone else shares.
#10
09/14/2005 (4:59 am)
Agree with Ben here !
And will also thank you for all the time you helped me out !