Game Development Community

Music fading?

by Andy Schatz · in Torque Game Engine · 07/07/2005 (4:30 pm) · 8 replies

I haven't been able to find any console functions for fading music/ambient tracks in and out. Has anyone coded this that would be willing to post it as a resource?

All I have found is alxPlay and alxStop.

#1
07/08/2005 (7:03 am)
I dont know about a fading function , can't you prefade your tracks ?
#2
07/08/2005 (7:14 am)
@ Billy:

Perhaps he's wanting to loop a given track 'x' number of times before fading...

-------------------

I think there are some $Pref variables that store volume levels as set by the user.

Perhaps you could create one for music and create a simple function that slowly decrements the value?

~ Just a thought.
#3
07/08/2005 (7:31 am)
We have done it the way Kirby describes. You create a function that increments or adds to the volume, slowly.. which makes it fade in or out.
#4
07/08/2005 (8:59 am)
@Billy- I can't prefade it, the music loops while you are in the UI and when the level loads I need to fade out the music and fade in the ambient SFX, like Kirby said

@Kirby/Stefan- yes, I'll have to fade the volume on that one channel. I know its not hard to write but it seemed like something that SHOULD have been implemented already so I didn't want to redo work. Thanks!
#5
07/08/2005 (1:19 pm)
I did this a while back, although I faded out the global volume. The idea was to fade out the music, as well as all of the other environmental sounds at the end of each level.

I made a function like this in client/scripts:

function clientCmdSetVolume(%vol)
{
alxListener(AL_GAIN_LINEAR, %vol);
}

If the server tells all of the clients to run this function every second at 1, 0.9, 0.8, 0.7, 0.6... ect, the result is a nice sound fade-out effect.

At the beginning of every level I would fade in the sound the same way.
#6
07/08/2005 (1:21 pm)
I wouldn't. Terribly uneffective and bandwidth-eating. I would loop the function a set amount of times instead, on the client.
#7
07/08/2005 (4:34 pm)
You can do that with a simple schedule othervise , with alxsetchannelvolume.
But you need to add a special channel for music .
And use a clientcommand.
#8
08/28/2005 (7:18 am)
Andy,

I would recommend implementing a solution in code. That way, you can directly access the openal functions and fade between tracks (or in this case, streaming openal sources) quite easily with a much larger degree of reliability in timing.
In addition, with code, you could control the transitions from the server part of the code, and send the changes (fadeout level, sources playing, etc) directly to the client(s), as and when the music changes (providing you are knowledgeable in coding a NetObject).

As for if there is a resource out there that already does this, i don't recall anyone who has made such a thing and released it.