C++ Question How to stop a splashdown sound loop?

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
Hi my friends!
I wrote this code:
Code:
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]
[FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] antares::clbkPreStep ([/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] simt, [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] simdt, [/COLOR][/SIZE][/FONT][/SIZE][/FONT][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff][FONT=Courier New][SIZE=2][COLOR=#0000ff]double[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000] mjd)[/COLOR]
[/SIZE][/FONT][/SIZE][/FONT]}
...
if[/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][/COLOR][/SIZE][/FONT][FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2][COLOR=#000000]([FONT=Courier New][SIZE=2][FONT=Courier New][SIZE=2]GroundContact()[/SIZE][/FONT][/SIZE][/FONT])PlayVesselWave3(MyID, SPLASHDOWN);[/COLOR]
...
}[/SIZE][/FONT][/SIZE][/FONT]

i suppose it to play a splashdown sound when the capsule touches the water.. the problem is that it repeats that sound infinitly.
How can i solve the problem?
Thanks!
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
The clbkPreStep is run every frame, and GroundContact returns true when vessel touches the ground (water), and it's always true when the vessel is on the ground (water), so you need a flag that will be toggled once the vessel touches or leaves the ground (water), like for example:
PHP:
void antares::clbkPreStep (double simt, double simdt, double mjd) {
	//...
	if (GroundContact ()) {
		if (notTouchedDown) {
			PlayVesselWave3 (MyID, SPLASHDOWN);
			notTouchedDown = false;
		}
	} else notTouchedDown = true;
	//...
}
Where notTouchedDown is a private bool member of antares class.

You can add to it a delay after which notTouchedDown will be reset to true instead of simply setting "notTouchedDown = true;", when vessel loses ground contact (by adding simdt to some another private double variable, and resetting notTouchedDown only after its value is greater than some chosen time - in the else case), to prevent playing the sound multiple times when the ground (water) contact is unstable.
 

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
You can add to it a delay after which notTouchedDown will be reset to true instead of simply setting "notTouchedDown = true;", when vessel loses ground contact (by adding simdt to some another private double variable, and resetting notTouchedDown only after its value is greater than some chosen time - in the else case), to prevent playing the sound multiple times when the ground (water) contact is unstable.

Sorry, i don't understand this part.. how can i use simdt to play the splashdown sound in a chosen time?
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
Sorry, i don't understand this part.. how can i use simdt to play the splashdown sound in a chosen time?
What I was writing was about adding a bit of [ame=http://en.wikipedia.org/wiki/Hysteresis]hysteresis[/ame] to changing the state of "notTouchedDown" back to true, so the sound doesn't play for example every other frame if the vessel is bouncing frequently, and not a delay for playing the sound.

An example for this with a half of a second (delayTime is a private double variable of antares class):
PHP:
void antares::clbkPreStep (double simt, double simdt, double mjd) {
	//...
	if (GroundContact ()) {
		if (notTouchedDown) {
			PlayVesselWave3 (MyID, SPLASHDOWN);
			notTouchedDown = false;
			delayTime = 0;
		}
	} else if (!notTouchedDown) {
		if (delayTime > 0.5) notTouchedDown = true;
		else delayTime += simdt;
	}
	//...
}


If you want to add a delay before the splash sound, you can do the opposite, so count time before it will play the sound, or add a silence before splash to the sound file, but that wasn't what I was writing about in the first place. You wanted to play the sound when capsule touches down the water, and I assume you don't want a delay there, do you?
 

fausto

FOI SuperMod
Joined
Jul 13, 2008
Messages
797
Reaction score
2
Points
0
Location
Monza (Milan)
Yes, i want the sound to play ONE time when the capsule touches the ground.. i used your code lines but the sound repeats and repeats again.. :(
 

orb

New member
News Reporter
Joined
Oct 30, 2009
Messages
14,020
Reaction score
4
Points
0
I haven't tested that code, so I could overlook something. The computer I'm writing from now isn't usually used to play/run Orbiter. I'll make a simple test in a few hours with ShuttlePB and with added that code, to check if the part containing PlayVesselWave3 is called multiple times after touchdown, but first I need to install OrbiterSound here.
 
Top