Embedded DTS Sound
by Jon Jorajuria · 08/17/2006 (12:08 pm) · 7 comments
Download Code File
The embedded DTS sound resource shows an example on how to attach a sound to a dts shape via script. This is very useful when building a level with DTS objects that will have predetermined sound. An example of this would be a pier that is on a lake or ocean shore. A developer can embed the sound of lapping water in the DTS model, which enhances the scene's sound dynamics.
I will be showing you how to setup the audioprofiles and play the sound within the DTS object's scipt file. For reference on the audio functionality associated with TGE please refer to TDN. This resource contains a sample script, DTS model, and sound file.
Open your DTS object's scrip file, at the top add a new audio description:
The audio description datablock defines the properties for the sound we want to play. Based on the description the following properties have been set:
The sound volume is at max volume
The sound will loop
The sound is in 3d which affect how the sound will be presented to the player. (Position in the world produces a ranged sound effect)
The reference and max difference define how close or far away the player needs to be to hear the sound.
The type is defined and we are using one of the default torque audio types. This audio type is for simulation type sounds. **Note: By default you can define up to 32 different sound types.
Next we define the audio profile. Under the description add the following:
The audio profile defines where the file is located, the description associated with the sound, and whether or not it is preloaded. **Preloading sounds is a balancing act. If a sound is not preloaded a user may experience lag as the sound file is called an loaded into memory. However if too many sounds are preloaded into RAM, a user may experience performance issues.
The lat step is actually playing the sound. Create an onAdd function with the PlayAudio command:
When the object is added to the scene, the audio is played server side so that all players can hear the sound. The playaudio command also specifies which slot to play the sound from, in our case slot 0. Finally the command contains the audio profile to play.
To install the example script, sound, and DTS object perform the following:
Place the demoobject directory in ~/data/shapes
Place the testsnd.ogg file in ~/data/sound
Place the demoobject.cs file in ~/server/scripts
In game.cs under
add
Now go into the editor and add the DemoObject located in the Shapes/Misc tree.
The embedded DTS sound resource shows an example on how to attach a sound to a dts shape via script. This is very useful when building a level with DTS objects that will have predetermined sound. An example of this would be a pier that is on a lake or ocean shore. A developer can embed the sound of lapping water in the DTS model, which enhances the scene's sound dynamics.
I will be showing you how to setup the audioprofiles and play the sound within the DTS object's scipt file. For reference on the audio functionality associated with TGE please refer to TDN. This resource contains a sample script, DTS model, and sound file.
Open your DTS object's scrip file, at the top add a new audio description:
datablock AudioDescription(DemoObjectLooping3d)
{
volume = 1.0;
isLooping= true;
is3D = true;
ReferenceDistance= 5.0;
MaxDistance= 60.0;
type = $SimAudioType;
};The audio description datablock defines the properties for the sound we want to play. Based on the description the following properties have been set:
The sound volume is at max volume
The sound will loop
The sound is in 3d which affect how the sound will be presented to the player. (Position in the world produces a ranged sound effect)
The reference and max difference define how close or far away the player needs to be to hear the sound.
The type is defined and we are using one of the default torque audio types. This audio type is for simulation type sounds. **Note: By default you can define up to 32 different sound types.
Next we define the audio profile. Under the description add the following:
datablock AudioProfile(DemoObjectSound)
{
filename = "~/data/sound/testsnd.ogg";
description = DemoObjectLooping3d;
preload = true;
};The audio profile defines where the file is located, the description associated with the sound, and whether or not it is preloaded. **Preloading sounds is a balancing act. If a sound is not preloaded a user may experience lag as the sound file is called an loaded into memory. However if too many sounds are preloaded into RAM, a user may experience performance issues.
The lat step is actually playing the sound. Create an onAdd function with the PlayAudio command:
function DemoObject::onAdd(%this,%obj)
{
%obj.PlayAudio(0,DemoObjectSound);
}When the object is added to the scene, the audio is played server side so that all players can hear the sound. The playaudio command also specifies which slot to play the sound from, in our case slot 0. Finally the command contains the audio profile to play.
To install the example script, sound, and DTS object perform the following:
Place the demoobject directory in ~/data/shapes
Place the testsnd.ogg file in ~/data/sound
Place the demoobject.cs file in ~/server/scripts
In game.cs under
exec("./aiPlayer.cs");add
exec("./demoobject.cs");Now go into the editor and add the DemoObject located in the Shapes/Misc tree.
About the author
#2
10/17/2006 (3:29 pm)
Thanks for sharing. Very useful.
#3
One question thou!
If the dts moes, Forexample a car following a path the sound is not played
Any FIX?
02/27/2008 (4:06 am)
Great resourse. One question thou!
If the dts moes, Forexample a car following a path the sound is not played
Any FIX?
#4
This resource is great!!!!!
I had to put the
%obj.PlayAudio(0,DemoObjectSound);
into my bot.cs
02/27/2008 (4:10 am)
Go it fixed.This resource is great!!!!!
I had to put the
%obj.PlayAudio(0,DemoObjectSound);
into my bot.cs
#5
10/09/2008 (4:15 pm)
is this supported in tge 1.5.x? because I can't get it to work, and I'm somewhat of a tge scripting pro. Clearly the method is there but doesn't seem to work.
#6
1 minor edit here though
datablock AudioProfile(DemoObjectSound)
{
filename = "~/data/sound/testsnd.ogg";
description = DemoObjectLooping3d;
volume = 1; <---------------------------------------------'volume' is not supported in the 'AudioProfile' data
preload = true;
};
10/09/2008 (5:42 pm)
heh, nvm. got it working :)1 minor edit here though
datablock AudioProfile(DemoObjectSound)
{
filename = "~/data/sound/testsnd.ogg";
description = DemoObjectLooping3d;
volume = 1; <---------------------------------------------'volume' is not supported in the 'AudioProfile' data
preload = true;
};

Torque Owner AllynMcelrath