I cant believe this is not documented.play3d,stop looping sound
by Highlander · in Torque Game Engine · 05/23/2007 (11:41 pm) · 10 replies
Searching for "ServerPlay2D" and "ServerPlay3D" brings up surprisingly little results. I went on TDN and found a few paragraphs about defining a an audio profile but the section on how to actually play sounds seems to be under construction.
The best resource I found was actually on some european website in german:
http://www.gametheory.ch/index.jsp?positionId=17509&displayOption=noframework
it seems from that site that I need to use serverplay for playing external sounds (i.e, engines, jets, etc) and alxplay for internal sounds (control buzzers, computer voices, etc).
Why doesn't the ServerPlay3d sound play? I get an an error saying
"starter.fps/client/scripts/default.bind.cs (199): Unable to find object: '' attempting to call function 'getTransform' "
How can I start a looping serverplay2d/3d sound when i push a button and stop it when i release the button?
in player.cs:
datablock AudioProfile(jumpJets)
{
filename = "~/data/sound/jjcontinuous.wav";
//description = AudioClose3d;
description = AudioDefaultLooping3d;
volume = 1.0;
is3D = true;
ReferenceDistance= 20.0;
MaxDistance= 100.0;
type = $SimAudioType;
preload = true;
isLooping = true;
};
in default.bind.cs:
function jump(%val)
{
$mvTriggerCount2++;
ServerPlay2D("jumpJets",%obj.getTransform());
//ServerPlay3D("jumpJets",%obj.getTransform());
}
The best resource I found was actually on some european website in german:
http://www.gametheory.ch/index.jsp?positionId=17509&displayOption=noframework
it seems from that site that I need to use serverplay for playing external sounds (i.e, engines, jets, etc) and alxplay for internal sounds (control buzzers, computer voices, etc).
Why doesn't the ServerPlay3d sound play? I get an an error saying
"starter.fps/client/scripts/default.bind.cs (199): Unable to find object: '' attempting to call function 'getTransform' "
How can I start a looping serverplay2d/3d sound when i push a button and stop it when i release the button?
in player.cs:
datablock AudioProfile(jumpJets)
{
filename = "~/data/sound/jjcontinuous.wav";
//description = AudioClose3d;
description = AudioDefaultLooping3d;
volume = 1.0;
is3D = true;
ReferenceDistance= 20.0;
MaxDistance= 100.0;
type = $SimAudioType;
preload = true;
isLooping = true;
};
in default.bind.cs:
function jump(%val)
{
$mvTriggerCount2++;
ServerPlay2D("jumpJets",%obj.getTransform());
//ServerPlay3D("jumpJets",%obj.getTransform());
}
#2
05/24/2007 (12:18 am)
Additionally, you don't need the transform of the object for playing a 2D sound (ServerPlay2D) as it's a 2D sound.ServerPlay2D(%profile); ServerPlay3D(%profile,%transform);
#3
05/24/2007 (1:22 am)
Here's a quick way of doing what you want. The sound is played whilst the jump key is held down and will stop upon release.//----------------------------------------------------------------------------
// In server/audioProfiles.cs
datablock AudioDescription(JetSoundFX)
{
volume = 1;
isLooping = true;
is3D = true;
ReferenceDistance = 20.0;
MaxDistance = 100.0;
type = $SimAudioType;
};
datablock AudioProfile(JumpJets)
{
filename = "~/data/sound/jjcontinuous.wav";
description = "JetSoundFX";
preload = true;
};
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// In default.bind.cs:
function Jump(%val)
{
$mvTriggerCount2++;
if(%val)
commandToServer('PlayJetSound');
else
commandToServer('StopJetSound');
}
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Somewhere in a server side script, commands.cs will do:
function serverCmdPlayJetSound(%client)
{
%client.player.playAudio(0, jumpJets);
}
function serverCmdStopJetSound(%client)
{
%client.player.stopAudio(0);
}
//----------------------------------------------------------------------------
#4
05/24/2007 (2:22 am)
Lastly, if you're using a 3D sound ensure that it is mono file. Only use stereo sounds with 2D profiles, it makes complete sense when you think about it.
#5
05/24/2007 (7:32 am)
Wow, great help Tim!! I gave it a shot and discovered another problem: when you abruptly cut off the sound with stopAudio, it often makes a cracking sound because the audio waveform is high just before you cut it off. Is there a way of fading the sound out over say a second? I assume this would entail changing the volume at the server, but I don't see how you can control the audio.
#6
You could write a dirty scripted solution that alters the volume of a channel using a looping, schedule function.
Better yet, try this resoure: Add pausing, seeking, and dynamic volume to Torque audio code
It does a very good job of fixing some audio problems in Torque and adding in some much needed features.
05/24/2007 (7:44 am)
No default method to fade audio in and out exists that I know of. You could write a dirty scripted solution that alters the volume of a channel using a looping, schedule function.
Better yet, try this resoure: Add pausing, seeking, and dynamic volume to Torque audio code
It does a very good job of fixing some audio problems in Torque and adding in some much needed features.
#7
Not sure if this resource will help as it is for music more then sound effects but it adds a lot of functionality to the sound system. Maybe have a look and see if any of that helps.
05/24/2007 (7:45 am)
www.garagegames.com/index.php?sec=mg&mod=resource&page=view&qid=9560Not sure if this resource will help as it is for music more then sound effects but it adds a lot of functionality to the sound system. Maybe have a look and see if any of that helps.
#8
05/24/2007 (9:46 am)
Tim, I read over that resource, but it seems to me that it only affects the alx sound component. From my earlier reading I thought that the alx stuff was only for client-only, internal sounds, as opposed to sounds like jet engines and car engines that are external to the player's character (can be heard by all the other players) and move with the character. Am I mistaken?
#9
05/25/2007 (4:12 am)
Hey, the code that Tim posted, I am wondering in multiplayer if it will put the sound in the right place. I don't see any transform, so when the jet sound plays, isn't it going to play for each other character as if they are generating it?
#10
05/25/2007 (4:18 am)
The transform is all handled in source with the playAudio function and should work across a network - though I haven't tested it.
Torque Owner Tim Heldna