Jump to content
Sign in to follow this  
Rocky

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 Patrick_Waugh

Ok, I'm trying this ELAPSED_SECONDS thing, but no joy.In the main .c file I have: FLOAT64 previous_seconds = 0; MODULE_VAR elapsed_seconds = { ELAPSED_SECONDS };and then in the subgauge .c file I have: case PANEL_SERVICE_PRE_UPDATE: // Update routine in gauge callback lookup_var(&elapsed_seconds); if(elapsed_seconds.var_value.n == previous_seconds) { // Game is paused StopBuffer(0, 1); StopBuffer(1, 1); } previous_seconds = elapsed_seconds.var_value.n; break;Obviously I'm doing something wrong, but not sure what.Patrick

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 Patrick_Waugh

Yes, the gauge is only on the main panel.So, it is strange that I am capturing the time, but that it seems to continue to update, even when paused.

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

How are your sounds being triggered?The code you quoted in the opening post will certainly work to turn the sounds off, but will do nothing to prevent the sounds from being started again.Doug

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

With this in the master gauge file: MODULE_VAR elapsed_seconds = { ELAPSED_SECONDS };Tried this:case PANEL_SERVICE_PRE_UPDATE: // Update gauge lookup_var(&elapsed_seconds); if(elapsed_seconds.var_value.n - elapsed_seconds.var_old.n <= 0) { // Game Paused StopBuffer(0, 1); StopBuffer(1, 1); } elapsed_seconds.var_old.n = elapsed_seconds.var_value.n;Alas, doesn't work. =)I'll try again later after I've rested and can read clearly again. Must be missing something.Patrick

Share this post


Link to post
Share on other sites
Guest Patrick_Waugh

Hmmmm I guess FS just keeps on truckin and doing callbacks when the game is paused.Well maybe what I need to do is check for the pause in the callbacks and not trigger the sounds if paused.I'll check into this possibility.I'm trigger looping sounds (warnings) in an ELEMENT_ICON's callback.Like this:FLOAT64 FSAPI engout_cb(PELEMENT_ICON pelement_icon){ // Select EngOut Annunciator icon, and display #define N1_MAX 16384 int isEngOut; int isPower; // EngOut if N1 < 55% of 16384 = 100% RPM static int MIN_N1 = (int)(N1_MAX * 0.55); isEngOut = (pelement_icon->source_var.var_value.n < MIN_N1); lookup_var(&electricity); isPower = !electricity.var_value.b; if(isEngOut) { // N1 < 55% if(isPower) { if(!IsBufferPlaying(0)) { if(!isHornMuted) PlayBuffer(0, 1); } return 1; } } // No power, or N1 > 55%, Make !BRIGHT StopBuffer(0, 1); if(isCautionLtTestBtnPushed) return 1; else return 0;}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... ;)


Fr. Bill    

AOPA Member: 07141481 AARP Member: 3209010556


     Avsim Board of Directors | Avsim Forums Moderator

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Tom Allensworth,
    Founder of AVSIM Online


  • Flight Simulation's Premier Resource!

    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!

    Click here for more information and to see all donations year to date.
×
×
  • Create New...