Game Development Community

TGB Audio fades and pans

by Warthog · in Torque Game Builder · 12/17/2007 (5:29 pm) · 6 replies

Hi everyone,

Could someone please point me to the commands for fading audio in and out? When a character is about to enter the screen I want to fade in their audio and after they leave the screen I want to fade their sound out. I can't find any commands or tutorials related to this. Is it so simple I am missing it somehow?

Also, is there documentation somewhere for 3D audio so I could have a character's audio pan to the right if they move to the right side of the screen etc? If someone could please point me to this I would sure appreciate it!

Thanks!
Andy

#1
12/17/2007 (11:43 pm)
www.garagegames.com/mg/forums/result.thread.php?qt=69475

note VMplayer requires the source code.
#2
12/19/2007 (4:36 pm)
Thanks so much, that is a good start. I can't believe that there is no real documentation for the more advanced audio functions. It appears to be able to do 3D sound etc. but I have no idea how to set up or access these functions.

Is there some documentation that I am missing? How much of the TGE audio docs would apply? Although I can't access some things because I am not licensed for TGE, only TGB.
#3
01/17/2008 (11:09 am)
Warthog, here's how I handle fading:

function fadeOut(%channel)
{
alxSetChannelVolume(%channel, alxGetChannelVolume(%channel) - 0.05);

if ( alxGetChannelVolume(%channel) != 0)
$fadeOutSchedule = schedule(150, 0, fadeOut,%channel);
}

I don't know of any 3d audio abilities built into TGB though.
#4
02/08/2008 (11:47 pm)
Aaron - how do you know what channel your effects or music are playing in?

Let's say I want to fade out my music, but keep all other sound effects at the same volume, how is that done?
#5
02/09/2008 (9:27 am)
You need to save your handle in a global variable, so when you start your music do this, for example:
$levelmusic = alxPlay(gameMusic);
This global is now your 'handle' to that particular sound. Then add this to your game.cs or somewhere else convenient:
function fadeALHandle(%handle,%delay) {
	%currentvolume = alxGetSourcef(%handle,"AL_GAIN");
	if (%currentvolume > 0) {
		%currentvolume -= 0.1;
		alxSourcef(%handle, "AL_GAIN", %currentvolume);
		%fadeschedule = schedule(%delay, 0, fadeALHandle,%handle,%delay);
	}
}
Now you can fade any music by calling the function with the handle and the delay, which is how slow it fades. The higher the delay, the longer it will take to fade; 100 is pretty fast, 500 is very slow.

So in our example, you would call
fadeALHandle($levelmusic, 150);
to do your fade.

Greg
#6
02/09/2008 (6:50 pm)
Thank you very much Greg - that's very useful! I never realized what the alxSourcef function did before because it has no description in the help documentation. The audio section of the documentation really needs some attention from Garage Games.