Game Development Community

Need help adding custom sound

by Ben · in Torque Game Engine · 01/23/2006 (5:43 pm) · 2 replies

I cant figure out how to add custom sound to torque using the audio emitter can some one plaese help

#1
02/16/2006 (9:12 am)
$musicHandle = alxPlay(mySoundProfile);
alxStop($musicHandle);
alxStopAll();

That should be all you need.

You'll of course need to set up audioProfile's. You can find an example of that in common/client/audioprofiles.cs (I think)

alternatively, search your game directory for "AudioProfile"
#2
02/16/2006 (10:24 pm)
I'll give this a go.

I will outline the basic steps to get an environmental audio sound into your mission, lets say wind. From this and Chris's post above you should be able to work out anything else you may need.

1) Open up server/scripts/audioProfiles.cs and to the bottom of the file add your AudioDescription

eg
datablock AudioDescription(WindLooping2D)
{
   volume = 1.0;
   isLooping = true;
   is3D = false;
   type = $SimAudioType;
};

NB the above step isn't entirely necessary as you could just use one of the AudioDescriptions that's already present, such as AudioLooping2D, however creating your own might help you understand how things work better and gives you more control down the track. Also take note of the last line that says type = $SimAudioType;, I will be going into more detail on this somewhere below.

2) Below the AudioDescription you just created, add an AudioProfile which will lead to that AudioDescription

eg
datablock AudioProfile(Wind)
{
   filename = "~/data/sound/wind.ogg";
   description = "WindLooping2D";
	preload = true;
};

Basically the AudioDescription specifies the path to your sound file. It also specifies which AudioDescription to use which contains volume, looping information etc.

Now, all you have to do is create your sound file, make sure the filename path in the AudioProfile is valid and open up your mission.

3) Once in the mission hit F11 to bring up the mission editor. Then hit F4, select mission objects, environment, audio emitter and place the object into the world. In my experience the only fields you should have to set are the 'Sound Profile', 'Sound Description' and 'Use profiles desc?' fields. Make sure 'Use profiles desc?' is checked and lead the 'Sound Profile' field to your AudioProfile, the 'Sound Description' field to your AudioDescription

Refer image below.

i5.photobucket.com/albums/y189/fjs/audioExample1.jpg
Click okay and the emitter will appear in the world and your sound should start playing

Refer image below.

i5.photobucket.com/albums/y189/fjs/audioExample2.jpg
That should be it, to control the sound through script you can use...
$simHandle = alxPlay(mySoundProfile);
alxStop($simHandle);
alxStopAll();
as mentioned above.

As for the $simHandle I mention in step 1, this is defined in client/scripts/audioProfiles.cs at the top of the file. Just duplicate the ones already there to make your own.

eg

$GuiAudioType     = 1;
$SimAudioType     = 2;
$MessageAudioType = 3;
$GadgetAudioType  = 4;
$FxAudioType      = 5;
$WeatherAudioType = 6;
$GunAudioType     = 7;
$MusicAudioType   = 8;


Then, if you needed to you could assign the wind sound I just showed you how to create to a $WeatherAudioType. This gives you more control when using the alx commands mentioned above to start and stop individual sounds.

eg

$weatherHandle = alxPlay(wind); //plays only the wind sound
alxStop($weatherHandle); //stops only the wind sound
alxStopAll(); // stops [b]ALL[/b] sounds

That should be all you need to know, sorry if I dumbed it down too much, just wanted to give you as much help as possible with minimal margin for error.