Random footstep sound (quick answer)
by Brandon Maness · in Torque Game Engine · 06/08/2005 (12:08 am) · 9 replies
Ok, here is a quick answer to the multiple random footstep sounds question. NOTE: this has not been completely tested, and was done in about 5 min, but simply gives a very basic framework to build from. I'm not sure I would personally use a switch switch statement, but it keeps it simple.
Start by opening your player.cs file located in your server/scripts folder. Add some additional sound datablocks. In the below example, ImpactMySound1 and ImpactMySound2 were added around line 188.
And around line 654 add the two commented statements:
All we did above was add 2 ogg file datablocks and link them to FootMySound1 and FootMySound2. Now we just need to add a couple of things to the player.cc C++ file located in your engine/game folder. At the top define a random number around line 46:
And last but not least add some random logic to whatever type terrain you want. I added the randomness to the default case block located in Player::playFootstepSound around line 4000, but you could add it to something else if you like.
NOTE PLAYER.H CODE CHANGE BELOW!!
I'm not going to even begin to claim this is the way you should do this, but simply serves as a good starting point. I hope it helps. Again, this solution was created in about 5 minutes. It took longer to write this post than it did to add the random sound selection to the engine, so your mileage may vary!
B--
Start by opening your player.cs file located in your server/scripts folder. Add some additional sound datablocks. In the below example, ImpactMySound1 and ImpactMySound2 were added around line 188.
datablock AudioProfile(ExitingWaterLightSound)
{
filename = "~/data/sound/replaceme.wav";
description = AudioClose3d;
preload = true;
};
[b]//added next two dataBlocks <------------------------------------
datablock AudioProfile(ImpactMySound1)
{
filename = "~/data/sound/Ammo_pickup.ogg";
description = AudioClose3d;
preload = true;
};
datablock AudioProfile(ImpactMySound2)
{
filename = "~/data/sound/Crossbow_reload.ogg";
description = AudioClose3d;
preload = true;
};
[/b]
//----------------------------------------------------------------------------
// Splash
//----------------------------------------------------------------------------And around line 654 add the two commented statements:
//NOTE: some sounds commented out until wav's are available // Footstep Sounds FootSoftSound = FootLightSoftSound; FootHardSound = FootLightHardSound; FootMetalSound = FootLightMetalSound; FootSnowSound = FootLightSnowSound; FootShallowSound = FootLightShallowSplashSound; FootWadingSound = FootLightWadingSound; FootUnderwaterSound = FootLightUnderwaterSound; [b] FootMySound1 = ImpactMySound1; //added this <--------- FootMySound2 = ImpactMySound2; //and this <------------ [/b] //FootBubblesSound = FootLightBubblesSound; //movingBubblesSound = ArmorMoveBubblesSound; //waterBreathSound = WaterBreathMaleSound;
All we did above was add 2 ogg file datablocks and link them to FootMySound1 and FootMySound2. Now we just need to add a couple of things to the player.cc C++ file located in your engine/game folder. At the top define a random number around line 46:
#include "game/fx/splash.h" #include "game/fx/cameraFXMgr.h" //---------------------------------------------------------------------------- [b]static MRandomLCG myRandom(0x1); // Add this line here <---------------[/b] // Amount we try to stay out of walls by... static F32 sWeaponPushBack = 0.03;
And last but not least add some random logic to whatever type terrain you want. I added the randomness to the default case block located in Player::playFootstepSound around line 4000, but you could add it to something else if you like.
case 3: // Snow
alxPlay(mDataBlock->sound[PlayerData::FootSnow], &footMat);
break;
default: //Hard
[b]S32 myInt = myRandom.randI(0,1);
switch(myInt){
case 0:
alxPlay(mDataBlock->sound[PlayerData::MySound1], &footMat);
break;
case 1:
alxPlay(mDataBlock->sound[PlayerData::MySound2], &footMat);
break;
}[/b]
}
}NOTE PLAYER.H CODE CHANGE BELOW!!
I'm not going to even begin to claim this is the way you should do this, but simply serves as a good starting point. I hope it helps. Again, this solution was created in about 5 minutes. It took longer to write this post than it did to add the random sound selection to the engine, so your mileage may vary!
B--
About the author
#2
06/08/2005 (12:24 pm)
Thanks a lot for putting this together, I'll give it a run-through tonight following your example.
#3
Plus what does the default sound even do? In a clean install, there is no sound when the orc runs any place but on hard terrian, and it plays the footlighthardsound -> foothardsound -> foothard. As if that isn't confusing enough, why is it that they change the names so much, I'm getting really confused as to when I should use what name.
anyway, when I make your changes, he still makes that sound (even when I put the case statement inside the "hard" case).
Help!
06/09/2005 (3:20 am)
Just so you know, this definitely does not work the way you wrote it up. It gives me a good idea, but I'm still completely lost and can't figure out why it still calls foothard.Plus what does the default sound even do? In a clean install, there is no sound when the orc runs any place but on hard terrian, and it plays the footlighthardsound -> foothardsound -> foothard. As if that isn't confusing enough, why is it that they change the names so much, I'm getting really confused as to when I should use what name.
anyway, when I make your changes, he still makes that sound (even when I put the case statement inside the "hard" case).
Help!
#4
All the above code does is randomly pick either the Ammo_pickup.ogg or Crossbow_reload.ogg sound when the default surface case switch is true. If you don't have the two .ogg files in your example/starter.fps/data/sound folder they won't play.
As I mentioned in the original post, this is not a complete solution, but simply serves as an example of how to randomly get one of two sounds to play when the default case block is active. This case block should play when you are walking inside a building.
Let me explain the original switch(sound) block around line 3987, not the one I added, but the one that was there. As your player is walking the variable named sound is updated. 0 is soft, 1 is hard, 2 is metal, etc. If the variable sound is not equal to any of those then the defualt case block is executed. The GG team commented //hard after the default case block to tell you they were going to play the hard sound if the sound variable was not equal to 0 thru 3.
If your mission terrain does not have any additional texture descriptions, then the default case block is executed, otherwise, running in a building(.dif) will make the default case block execute, and you should hear one of the 2 sounds playing. It randomly picks one of the two to play, so you might hear the Crossbow_reload.ogg sound a couple of times, and then the Ammo_pickup sound, followed by the Crossbow_reload sound while you are running down a hallway or something.
The idea of the above example was to show you what you needed to add and where you needed to add it. If you want more random sounds to play when walking in soft terrain then use the above as an example to get it in there.
Let me give you some quick pointers about Torque debugging: First read the debugging tutorial here. Then use the Con::printf function to output a line to the console for each case block relating to the switch(sound). For example: In the case 0: // Soft block add Con::printf("Soft block executed"); Do this for each one, and load up your mission, walk around, and open up your console(' key) to see what has been printed to it. That will give you an idea about which block is being executed. From here you can add the random multiple sounds to whatever block you want.. Ideally the block that is being executed.
I played the Crossbox_reload, and Ammo_pickup sounds in the above example so that you would know when they are playing. If you have added your own .ogg files, you might want to make sure torque can play them. I originally made 2 .wav files and converted them to .ogg, but Torque did not play them. So for debugging purposes use the stock sounds that you know work!
Again, I did test this in TGE 1.3 and It does work. I would not have given you a non-working example. That would just be wrong. So, give it a try, and let me know how it goes. If you still can't get it to work, zip up you player.cc and player.cs files, and i'll take a look at them for you. Remember, check to make sure you have the original stock .ogg sound files in the sound folder!
B--
support@smdlabs.com
06/09/2005 (7:15 am)
@Thomas: Hmm... I thought you said you understood C++ and were rusty... I guess I should have commented it more for you. The above example does work. I tested it on TGE1.3 before I gave it to ya. I figured you could look at it and understand what it was doing, but here is a further explanation.All the above code does is randomly pick either the Ammo_pickup.ogg or Crossbow_reload.ogg sound when the default surface case switch is true. If you don't have the two .ogg files in your example/starter.fps/data/sound folder they won't play.
As I mentioned in the original post, this is not a complete solution, but simply serves as an example of how to randomly get one of two sounds to play when the default case block is active. This case block should play when you are walking inside a building.
Let me explain the original switch(sound) block around line 3987, not the one I added, but the one that was there. As your player is walking the variable named sound is updated. 0 is soft, 1 is hard, 2 is metal, etc. If the variable sound is not equal to any of those then the defualt case block is executed. The GG team commented //hard after the default case block to tell you they were going to play the hard sound if the sound variable was not equal to 0 thru 3.
If your mission terrain does not have any additional texture descriptions, then the default case block is executed, otherwise, running in a building(.dif) will make the default case block execute, and you should hear one of the 2 sounds playing. It randomly picks one of the two to play, so you might hear the Crossbow_reload.ogg sound a couple of times, and then the Ammo_pickup sound, followed by the Crossbow_reload sound while you are running down a hallway or something.
The idea of the above example was to show you what you needed to add and where you needed to add it. If you want more random sounds to play when walking in soft terrain then use the above as an example to get it in there.
Let me give you some quick pointers about Torque debugging: First read the debugging tutorial here. Then use the Con::printf function to output a line to the console for each case block relating to the switch(sound). For example: In the case 0: // Soft block add Con::printf("Soft block executed"); Do this for each one, and load up your mission, walk around, and open up your console(' key) to see what has been printed to it. That will give you an idea about which block is being executed. From here you can add the random multiple sounds to whatever block you want.. Ideally the block that is being executed.
I played the Crossbox_reload, and Ammo_pickup sounds in the above example so that you would know when they are playing. If you have added your own .ogg files, you might want to make sure torque can play them. I originally made 2 .wav files and converted them to .ogg, but Torque did not play them. So for debugging purposes use the stock sounds that you know work!
Again, I did test this in TGE 1.3 and It does work. I would not have given you a non-working example. That would just be wrong. So, give it a try, and let me know how it goes. If you still can't get it to work, zip up you player.cc and player.cs files, and i'll take a look at them for you. Remember, check to make sure you have the original stock .ogg sound files in the sound folder!
B--
support@smdlabs.com
#5
06/09/2005 (6:09 pm)
Edit: I may have fixed all of it, standby...
#6
Hope that helps you out.
B--
06/09/2005 (7:37 pm)
@Thomas: I am SOOO sorry!! You are right, here is the player.h additions.. Did I mention it was after midnight when I posted the solution.. Sorry again, here is the addition around line 126 of Player.hF32 groundImpactShakeDuration; ///< How long to shake
F32 groundImpactShakeFalloff; ///< How fast the shake disapates
/// Zounds!
enum Sounds {
FootSoft,
FootHard,
FootMetal,
FootSnow,
FootShallowSplash,
FootWading,
FootUnderWater,
FootBubbles,
MoveBubbles,
WaterBreath,
ImpactSoft,
ImpactHard,
ImpactMetal,
ImpactSnow,
ImpactWaterEasy,
ImpactWaterMedium,
ImpactWaterHard,
ExitWater,
[b] MySound1,
MySound2,
[/b]MaxSounds
};
AudioProfile* sound[MaxSounds];Hope that helps you out.
B--
#7
Anyway, your random function is a little different than what I would use normally, so I am wondering, does this support me placing more than 2 sounds into the random setup? Supposing I have the others set up the same way in the rest of the script, do I have to change anything in the random function or the function call?
By the way, I have everything working for 2 sounds :)
06/09/2005 (8:19 pm)
Yeah I had that figured out, I was just telling you so that people that looked later knew :)Anyway, your random function is a little different than what I would use normally, so I am wondering, does this support me placing more than 2 sounds into the random setup? Supposing I have the others set up the same way in the rest of the script, do I have to change anything in the random function or the function call?
By the way, I have everything working for 2 sounds :)
#8
If you added more sounds you would of course want to change the random number being generated, and add additinal case blocks for the additional sounds.
for example three sounds would look like this:
Then you would add a case 2: that looks like case 1 but has the new sound.
Hope that gets you going in the right direction. Let me know if you need any more help.
B--
06/09/2005 (9:16 pm)
Yes, you can just keep repeating the steps above with MySound3 for example, and you will have to make all the script, and C++ changes that you made with the first two sound additions.If you added more sounds you would of course want to change the random number being generated, and add additinal case blocks for the additional sounds.
for example three sounds would look like this:
S32 myInt = myRandom.randI(0,2);
Then you would add a case 2: that looks like case 1 but has the new sound.
Hope that gets you going in the right direction. Let me know if you need any more help.
B--
#9
06/11/2005 (3:29 pm)
Yeah, I had the rest of it in, I just wanted to know how to manipulate the "myRandom" function call. Thanks.
Torque 3D Owner Thomas Shaw