3d sounds: What am I doing wrong here (details and code in post)
by Matt W · in Torque Game Engine · 01/20/2002 (2:05 am) · 26 replies
Well, I've been hard at work on a relatively small part of our project (learning experience) but I'm having fun hehe.
I have been working on developing a cool looking "cloak" effect for the game I'm working on and I am trying to have 2 3d sounds play (one when cloak is turned on... and one when it is turned off)
I have used sounds before... but only in existing shapebase functions (damage, shoot, pickup... etc) and 2d sounds (music... mouse overs... simple stuff)
Now here's the code I use to toggle cloak on and off (including the sound playing)
====taken from commands.cs===============================
$PlayerCloak = true;
function serverCmdtoggleCloak(%client)
{
if (!$PlayerCloak)
{
%client.player.setCloaked($PlayerCloak);
%client.player.setShapeName(%client.name);
alxStop($cloakSoundHandle);
$cloakSoundHandle = alxPlay("CloakOff");
$PlayerCloak = true;
}
else
{
$PlayerCloak = true;
%client.player.setCloaked($PlayerCloak);
%client.player.setShapeName("");
alxStop($cloakSoundHandle);
$cloakSoundHandle = alxPlay("CloakOn");
$PlayerCloak = false;
}
}
=========================================================
The cloaking toggle works fine (hehe, it's simple code... so it better work right!) but the sound playing isn't working right.
Here is the sound profile/datablock to clear up and confusion on what I have values set to for these sounds:
========taken from defaultaudioprofiles.cs===============
new AudioProfile(CloakOn)
{
filename = "~/data/sound/cloakOn.wav";
description = AudioDefault3d;
preload = true;
};
new AudioProfile(CloakOff)
{
filename = "~/data/sound/buttonOver.wav";
description = AudioDefault3d;
preload = true;
};
=========================================================
I am using audio description "AudioDefault3d" as is used for the footsteps that come with the demo (just to make sure the profile isn't my problem)
Now if anyone can provide suggestions or some help I'd be eternally grateful.
What do I need to change in order ot get those sounds (cloakon.wav and cloakoff.wav) to play correctly as a 3d sound?
Thank you.
I have been working on developing a cool looking "cloak" effect for the game I'm working on and I am trying to have 2 3d sounds play (one when cloak is turned on... and one when it is turned off)
I have used sounds before... but only in existing shapebase functions (damage, shoot, pickup... etc) and 2d sounds (music... mouse overs... simple stuff)
Now here's the code I use to toggle cloak on and off (including the sound playing)
====taken from commands.cs===============================
$PlayerCloak = true;
function serverCmdtoggleCloak(%client)
{
if (!$PlayerCloak)
{
%client.player.setCloaked($PlayerCloak);
%client.player.setShapeName(%client.name);
alxStop($cloakSoundHandle);
$cloakSoundHandle = alxPlay("CloakOff");
$PlayerCloak = true;
}
else
{
$PlayerCloak = true;
%client.player.setCloaked($PlayerCloak);
%client.player.setShapeName("");
alxStop($cloakSoundHandle);
$cloakSoundHandle = alxPlay("CloakOn");
$PlayerCloak = false;
}
}
=========================================================
The cloaking toggle works fine (hehe, it's simple code... so it better work right!) but the sound playing isn't working right.
Here is the sound profile/datablock to clear up and confusion on what I have values set to for these sounds:
========taken from defaultaudioprofiles.cs===============
new AudioProfile(CloakOn)
{
filename = "~/data/sound/cloakOn.wav";
description = AudioDefault3d;
preload = true;
};
new AudioProfile(CloakOff)
{
filename = "~/data/sound/buttonOver.wav";
description = AudioDefault3d;
preload = true;
};
=========================================================
I am using audio description "AudioDefault3d" as is used for the footsteps that come with the demo (just to make sure the profile isn't my problem)
Now if anyone can provide suggestions or some help I'd be eternally grateful.
What do I need to change in order ot get those sounds (cloakon.wav and cloakoff.wav) to play correctly as a 3d sound?
Thank you.
#2
First - you cannot play sounds on the server, the server can only command clients to play sounds.
Second - using new on an audioProfile/Description makes them client only datablocks (great for gui sounds -- bad for sim sounds). If you want them to be server based datablocks you need to use this form:
datablock audioProfille(CloakOn) { ... }
Third - alx* functions are client only audio functions. So you need to use one of the following server based functions:
global functions (plays on all clients)
ServerPlay2D(%profile)
ServerPlay3D(%profile, %transform)
game connection based functions (plays on specified client)
%connection.play2d(%profile)
%connection.play3d(%profile, %transform)
object based functions (emits from object on all clients where that object is in scope)
%object->playAudio(%slot_number, %profile)
Hope this helps
--Rick
01/22/2002 (7:39 pm)
Couple things wrong here...First - you cannot play sounds on the server, the server can only command clients to play sounds.
Second - using new on an audioProfile/Description makes them client only datablocks (great for gui sounds -- bad for sim sounds). If you want them to be server based datablocks you need to use this form:
datablock audioProfille(CloakOn) { ... }
Third - alx* functions are client only audio functions. So you need to use one of the following server based functions:
global functions (plays on all clients)
ServerPlay2D(%profile)
ServerPlay3D(%profile, %transform)
game connection based functions (plays on specified client)
%connection.play2d(%profile)
%connection.play3d(%profile, %transform)
object based functions (emits from object on all clients where that object is in scope)
%object->playAudio(%slot_number, %profile)
Hope this helps
--Rick
#3
Some of these sounds are filler sounds taken from Counter-Strike and half-life, and a few I recorded myself with my own microphone.
As I type this I'm about to head into and make the changes Rick suggested.
Thank you.
01/22/2002 (7:59 pm)
All the files I am working with were either created 16 bit mono 22,050 khz. The exact same format as buttonOver and footstep.wav that came with the demo.Some of these sounds are filler sounds taken from Counter-Strike and half-life, and a few I recorded myself with my own microphone.
As I type this I'm about to head into and make the changes Rick suggested.
Thank you.
#4
16bit, 22k, mono are perfect for 3D sounds.
The only place I would use stereo sounds would maybe be the hud or the shell gui.
--Rick
01/22/2002 (8:08 pm)
It doesn't matter if they are stereo or not. Just a wase of memory if they are and you play them 3D positioned. 16bit, 22k, mono are perfect for 3D sounds.
The only place I would use stereo sounds would maybe be the hud or the shell gui.
--Rick
#5
What would I do to determine the coordinates the sound was emitting from?
01/22/2002 (8:10 pm)
One question, the "transform" is figured out how?What would I do to determine the coordinates the sound was emitting from?
#6
If you are playing a sound in some arbitrary place in space and using one of the functions that require a transform. The transform is a string of position + rotation in axis angle format.
"x y z axis_x axis_y axis_z angle"
The only time the axis parameters need to be anything but 0's is if your sound uses a sound cone. Very rare for script triggered sounds.
--Rick
01/22/2002 (8:20 pm)
If you are emitting from an object it will automatically inherit that objects transform.If you are playing a sound in some arbitrary place in space and using one of the functions that require a transform. The transform is a string of position + rotation in axis angle format.
"x y z axis_x axis_y axis_z angle"
The only time the axis parameters need to be anything but 0's is if your sound uses a sound cone. Very rare for script triggered sounds.
--Rick
#7
%transform = %client.player.getTransform;
ServerPlay3D(CloakOn, %transform);
HURRAY!
Works perfectly, and I really have to say this simple correspondence between GG staff and users REALLY makes me feel good in knowing that the cut you guys get on our products is actually going to people who are working hard! :)
Hurray for GG! My sounds are working :)
Oh, and Tactical Assault should be having a few shots for the screenshot gallery once we get our humvee skinned and the maps we have polished up.
01/22/2002 (8:28 pm)
hurray!%transform = %client.player.getTransform;
ServerPlay3D(CloakOn, %transform);
HURRAY!
Works perfectly, and I really have to say this simple correspondence between GG staff and users REALLY makes me feel good in knowing that the cut you guys get on our products is actually going to people who are working hard! :)
Hurray for GG! My sounds are working :)
Oh, and Tactical Assault should be having a few shots for the screenshot gallery once we get our humvee skinned and the maps we have polished up.
#8
ServerPlay3D will start playing a sound at the players current position, if the player moves there is no way to update the sounds position. ...and how are you going to stop the sound?
You could do it like this with just scripts:
%client.player.playAudio(%slot_number, %profile);
then later
%client.player.stopAudio(%slot_number);
OR ...you could use a little less network traffic and add a little C++ code that would start the sound when the cloak mask bit is set and stop it when the cloak mask bit is cleared. 1-bit of network traffic kind of hard to beat that :)
Looking forward to those screenshots!!!
--Rick
01/22/2002 (8:42 pm)
Glad I could help but I hope you don't mind if I help just a little more... :)ServerPlay3D will start playing a sound at the players current position, if the player moves there is no way to update the sounds position. ...and how are you going to stop the sound?
You could do it like this with just scripts:
%client.player.playAudio(%slot_number, %profile);
then later
%client.player.stopAudio(%slot_number);
OR ...you could use a little less network traffic and add a little C++ code that would start the sound when the cloak mask bit is set and stop it when the cloak mask bit is cleared. 1-bit of network traffic kind of hard to beat that :)
Looking forward to those screenshots!!!
--Rick
#9
Where or how do I find this?
This I think is pry what ends up confusing me most. All these variables tossed around, and I never am able to figure out where they come from or what they might contain! hehe.
Any info on %slot_number would be great.
01/22/2002 (10:06 pm)
You mention %slot_numberWhere or how do I find this?
This I think is pry what ends up confusing me most. All these variables tossed around, and I never am able to figure out where they come from or what they might contain! hehe.
Any info on %slot_number would be great.
#10
--Rick
01/22/2002 (10:15 pm)
Every shapeBase object can play/manage up to 4 sounds. The slot number is is just sound number 1-4.--Rick
#11
How do I access or assign slots?
I've been trying to look around the footstep sounds, but I can't see where sounds are actually played.
Any info on slots would be welcome!
01/22/2002 (10:35 pm)
Thank you, but one thing.How do I access or assign slots?
I've been trying to look around the footstep sounds, but I can't see where sounds are actually played.
Any info on slots would be welcome!
#12
01/22/2002 (10:37 pm)
I thought the stereo wav files wouldn't play properly as 3d sounds?? At least I thought I read that somewhere...
#13
// Clocks out
01/22/2002 (10:45 pm)
The problem with the stereo sounds in a 3d audioprofile is that the sound don't fade out over distance but rather plays at 100% volume and then cut off entirely when the max distance is reached.// Clocks out
#14
Sample below:
As for the slots you can just assign them yourself
ie.
01/23/2002 (1:33 am)
The section that plays footstep sounds is hard-coded. It is found in player.cc(.h)Sample below:
case 0: // Soft
alxPlay(mDataBlock->sound[PlayerData::FootSoft], &footMat);
break;
case 1: // Hard
alxPlay(mDataBlock->sound[PlayerData::FootHard], &footMat);
break;
case 2: // Metal
alxPlay(mDataBlock->sound[PlayerData::FootMetal], &footMat);
break;As for the slots you can just assign them yourself
ie.
$cloaksound = 0; $someothersound = 1; %client.player.playAudio($cloaksound, %profile); %client.player.playAudio($someothersound, %profile); <..> //Some other code here %client.player.stopAudio($cloaksound); %client.player.stopAudio($someothersound);
#15
Well, thanks for the slot info... and pointing out where the sound play goes in the c files really will help me out in saving some network traffic by playing set sounds from the source instead of scripts.
Thanks :)
01/23/2002 (6:27 pm)
ah... so the footsteps are not 3d world sounds, but only 2d client sounds?Well, thanks for the slot info... and pointing out where the sound play goes in the c files really will help me out in saving some network traffic by playing set sounds from the source instead of scripts.
Thanks :)
#16
--Rick
01/23/2002 (8:14 pm)
The foot sounds are 3D. Notice the footMat, that is the foot transformation matrix.--Rick
#17
I mean, a snow texture gets a snow sound... but how do I determine that in code? Half Life used a text file and listed all the textures that use special material types (snow, water, grass, metal, grate) and that was how HL based games handled it.
How do I "mark" textures to use different material types?
01/24/2002 (5:08 pm)
Okay, one question about the foot material matrix... how do we decide which textures are treated as which object?I mean, a snow texture gets a snow sound... but how do I determine that in code? Half Life used a text file and listed all the textures that use special material types (snow, water, grass, metal, grate) and that was how HL based games handled it.
How do I "mark" textures to use different material types?
#18
===========================================
addMaterialMapping("sand" , "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
addMaterialMapping("grass" , "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
addMaterialMapping("patchy" , "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
example\fps\data\terrains\scorched\propertyMap.cs
=========================================
addMaterialMapping("scorched_lt", "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
addMaterialMapping("scorched_dk", "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
Change the sound: 0 to sound: 1 or sound: 2
Play with it a bit. I'll post more information when I dig out my old notes
01/24/2002 (6:01 pm)
example\fps\data\terrains\grassland\propertyMap.cs ===========================================
addMaterialMapping("sand" , "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
addMaterialMapping("grass" , "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
addMaterialMapping("patchy" , "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
example\fps\data\terrains\scorched\propertyMap.cs
=========================================
addMaterialMapping("scorched_lt", "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
addMaterialMapping("scorched_dk", "sound: 0" , "color: 0.46 0.36 0.26 0.4 0.0");
Change the sound: 0 to sound: 1 or sound: 2
Play with it a bit. I'll post more information when I dig out my old notes
#19
I created a propertyMap.cs in /terrains/mech with the following:
addMaterialMapping( "metal55" , "sound:2" , "color: 0.46 0.36 0.26 0.4 0.0" );
and exec'd it in init.cs:
exec( "./terrains/mech/propertyMap.cs" );
and I'm still getting the same old footstep sound.
01/24/2002 (7:12 pm)
Also, the propertyMap.cs file has to be exec'd from /fps/data/init.cs I believe; but it doesn't seem to work;I created a propertyMap.cs in /terrains/mech with the following:
addMaterialMapping( "metal55" , "sound:2" , "color: 0.46 0.36 0.26 0.4 0.0" );
and exec'd it in init.cs:
exec( "./terrains/mech/propertyMap.cs" );
and I'm still getting the same old footstep sound.
#20
Try it with something other than footsteps. Footsteps is hardcoded in the engine - see a couple of notes above.
01/24/2002 (7:29 pm)
Desmond, Try it with something other than footsteps. Footsteps is hardcoded in the engine - see a couple of notes above.
Torque Owner Tim Gift