Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Pausing sound (directsound) on pause of FS

Featured Replies

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!

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

>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.

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.

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

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.

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.

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).

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.

>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

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

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

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

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

  • Moderator

> 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

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.