Pausing sound (directsound) on pause of FS

Recommended Posts

Guest Patrick_Waugh

I notice now that I have working gauges with sound, that if a sound buffer is playing when I pause FS, directx just happily keeps playing it.To pause the sound on pause should I just capture the 'p' keypress using directinput, or is there a better way?PatrickP.S. I got so excited about finally getting it, that I must have created artwork for 30 gauges last night!

Share this post

Link to post

Share on other sites

Track the value in the ELAPSED_SECONDS variable. If it is the same as the last time you looked, then the sim is paused and you need to turn your sounds off. If the value is different, then sim time is moving and you are good to go.If you want to look for keystrokes, you will need to set up an event hook to trap the PAUSE related FS commands - I might have mapped another key to the PAUSE command (not likely) or set one of the buttons on my game controller to issue the PAUSE command (entirely plausible.)Doug

Share this post

Link to post

Share on other sites

Guest Patrick_Waugh

>Track the value in the ELAPSED_SECONDS variable. If it is>the same as the last time you looked, then the sim is paused>and you need to turn your sounds off. If the value is>different, then sim time is moving and you are good to go.Ah wonderful, very clean.>If you want to look for keystrokes, you will need to set up an>event hook to trap the PAUSE related FS commands - I might>have mapped another key to the PAUSE command (not likely) or>set one of the buttons on my game controller to issue the>PAUSE command (entirely plausible.)Excellent points to remember.Thanks Doug.

Share this post

Link to post

Share on other sites

Guest bartels

You can also hook into the interpreted keys with a GAUGE_KEY_EVENT_HANDLER so you don't have to rely on associated keys and buttons, but let FS do the interpretation for you. On the other hand I would also use ELAPSED_SECONDS for a number of reasons.

Share this post

Link to post

Share on other sites

Guest bartels

You shure you have your gauge only once in the panel (including virtual cockpit), if it is more then once it will be called once for each appearance and in that case no time will pass, it will only pass till the next update cycle.

Share this post

Link to post

Share on other sites

Guest bartels

Strange, I haveMODULE_VAR elapsed_seconds = {ELAPSED_SECONDS};outside any callback function and FLOAT64 deltat=0;... lookup_var(&elapsed_seconds); deltat=elapsed_seconds.var_value.n-elapsed_seconds.var_old.n; //save previous time elapsed_seconds.var_old.n=elapsed_seconds.var_value.n;.... if(deltat>0)// time has elapsed since last time stepinside the gauge callback function, works without flaw. In pause state deltat is 0. According to the debugger, deltat is around 0.0555 (depends on sim rate).

Share this post

Link to post

Share on other sites

Guest bartels

Independent on FS specialities, checking floats on equality is always critical. Floats are only precise to a certain extend, e.g. a human would say 1.9999999999999999999999999999999999999999999... is equal to 2 but C thinks otherwise. You might need to introduce a certain small margin to check for equality.

Share this post

Link to post

Share on other sites

Guest Patrick_Waugh

>Independent on FS specialities, checking floats on equality>is always critical. Floats are only precise to a certain>extend, e.g. a human would say>1.9999999999999999999999999999999999999999999... is equal to 2>but C thinks otherwise. You might need to introduce a certain>small margin to check for equality.Yes, I thought of this, but thought (for reasons I can't now remember) that it would not be an issue. However, I notice your code checks for a delta vs. and equality condition, so I'll try that and see.Thanks, appreciate the guidance.Patrick

Share this post

Link to post

Share on other sites

Guest Patrick_Waugh

Works now.I used the above code to set a gloabal variable BOOL isPaused, and then test for !isPaused before turning on warnings.Didn't expect that FS would be doing callbacks while paused, but I guess given that it still must redraw the window, it makes sense.Patrick

Share this post

Link to post

Share on other sites

> if(elapsed_seconds.var_value.n - elapsed_seconds.var_old.n>Alas, doesn't work. =)EDIT: never mind... I wrote nonsense... ;)I didn't read the entire thread and the elapsed_seconds.var_old.n threw me off for a moment... I've never seen such an inelegant structure... ;)

Share this post

Link to post

Share on other sites

I didn't read the whole thread in detail, but I may have an explanation: you code (in case of PRE_DRAW event) may be called several times even if FS is not paused. If your gauge is fast and doesn't take too much CPU power, FS can call it (PRE_DRAW) several times in the same refresh cycle.If you just look at the ELAPSED_SECONDS variable, you may think FS is paused when it isn't...Eric

AVSIM is a free service to the flight simulation community. AVSIM is staffed completely by volunteers and all funds donated to AVSIM go directly back to supporting the community. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. Thank you for your support!

Donation Goals

AVSIM's 2019 Fundraising Goal

Donate to our annual general fund. This donation keeps our doors open and providing you service 24 x 7 x 365. Your donation here helps to pay our bandwidth costs, emergency funding, and other general costs that crop up from time to time. We reset this goal every new year for the following year's goal.