![]() |
|
Stopping sounds when switching out of my app. |
Andrei Ellman
Member #3,434
April 2003
|
Hi, Whenever I switch out of my program (Allegro 4.2.2, Windows 2000) using ALT-TAB the sound-buffer is looped continuously so the currently playing collection of samples stutters until I switch back to the program. This happens in both windowed and fullscreen modes. This also happens when I focus another window. As well as my app, it happens in the Allegro demo-game too. Midis however do manage to silence themselves when switched out - it's just the samples that keep looping. I tried writing a switch-out callback that loops through all my samples and stop_sample()'s them, but this does not work when switching out. However, when I call the function for doing so from within the main context of the program it successfully stops all sounds. I also placed a TRACE-message in my switch-out handler, and the message is printed in the debug-window before the app is switched out. This means that both the code for stopping the samples and the switch-out callback appear to be working. Here's the code I use for stopping the sound void chStopAllSounds(void) { int nI; int nNumSounds = _chGetNumSamples(); for(nI=0;nI<nNumSounds;nI++) { ChSFXDatum *sfxdp = &(g_sfxdaTheSoundEffects[nI]); stop_sample(sfxdp->splTheSample); } } Here's the switch-out callback: void aeSwitchOutCallback(void) { /* Stop all sounds */ chStopAllSounds(); TRACE(TPREFIX_I "A display switch-out message was recieved.\n"); } And finally, the code for setting up the switch-out callback
And finally, the code for initialising the Allegro sound-engine if(install_sound(DIGI_AUTODETECT, MIDI_AUTODETECT, NULL)) { TRACE(TPREFIX_E "Error Initialising Sound: %s\n", allegro_error); return AERVAL_AIEEE; // Sound-related error-message instead? } The Allegro sound-driver used is AXA and the MIDI driver is W32M Anyone know how to make the sound stop playing when I switch out? AE. [EDIT: PS. My soundcard is a "SB Live! Value"] -- |
Elverion
Member #6,239
September 2005
![]() |
Is there any reason you can't use set_display_switch_mode(SWITCH_BACKGROUND)? Then you wouldn't have to worry about stopping the sounds. -- |
bamccaig
Member #7,536
July 2006
![]() |
The sound shouldn't necessarily stop playing when you switch out. I know that Counter-Strike: Source's sounds continue even after you switch out. However, if the sounds are looping erroneously or something that would be a problem. Otherwise, I wouldn't worry about silencing the game when you switch. Games are generally not intended to be running unless the user is playing them. If they are playing them they probably want the sound (unless they don't in which case they can either mute the system or mute your game (if that functionality exists). -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Audric
Member #907
January 2001
|
What you experience is not the normal behavior. |
Andrei Ellman
Member #3,434
April 2003
|
Elverion said: Is there any reason you can't use set_display_switch_mode(SWITCH_BACKGROUND)? Then you wouldn't have to worry about stopping the sounds. What if I'm running fullscreen and I don't want the action to continue while my game is minimised? I could of course set a flag in my switch out callback that pauses the game and resumes it on switch-in, but would prefer just to make the sounds stop. bamccaig said: However, if the sounds are looping erroneously or something that would be a problem. That's what they're doing. The sound-buffer just keeps looping continuously until I return to my game. bamccaig said: Otherwise, I wouldn't worry about silencing the game when you switch. Games are generally not intended to be running unless the user is playing them. But the point is that the stuttering sound-buffer is annoying and should be silenced automatically. Audric said: Win98, though. I'll try it the next time I boot up in Win98. Only tried Win2K so far. AE. -- |
Richard Phipps
Member #1,632
November 2001
![]() |
I've had this myself. I can't remember of the top of my head how I solved it, but I think the switch out callback gets called twice, so I ended up making that function only set a variable and then dealt with that variable to stop/restart sound in the main loop. Does that help? |
Audric
Member #907
January 2001
|
Ok i checked on the laptop (win 2000) : sound is "stuck" when window loses focus / minimize etc. |
Richard Phipps
Member #1,632
November 2001
![]() |
Ah! I found this old Neon Wars (OpenLayer version) code. Hope it helps:
|
Andrei Ellman
Member #3,434
April 2003
|
I just tried this on Win98SE (Allegro 4.2.2) and the same problem occurs (even with the Allegro demo game). However, if I minimise, I briefly get a stutter, the sound then plays normally for about 1 second and then starts stuttering again. This happens in both fullscreen and windowed modes, and in windowed modes, happens regardless of whether I use the DXWN or GDIB graphics drivers. I think this may be a bug in Allegro. Richard Phipps said: SWITCH_BACKGROUND I was hoping to be able to use SWITCH_PAUSE instead as then my game does not take up any CPU time when switched out. Although I suppose your method can be used as a workaround if I place a "rest(1000)" or something in my main loop (plus it has the advantage that I could make my game chartacters have falling-asleep animations when the game is switched out). Incidentally, does Allegro have the ability to tell the difference between a minimised window and a window switched to the background? AE. [EDIT: PS. My soundcard is a "SB Live! Value"] [EDIT2:] Audric said:
Allegro suspends MIDI, and cuts all sounds short. Sounds do not resume on return. Is that Win98SE or the first Win98 edition? -- |
Audric
Member #907
January 2001
|
Win98SE, Sound Blaster Live 1024. Now on the Windows 2000 laptop it's a whole different matter, the sound buffer instantly enters an endless loop - very easy to reproduce. On both platforms, I made almost all my tests in windowed mode (click on other window to switch focus), as in fullscreen Alt-tabbing is slow to register. |
Milan Mimica
Member #3,877
September 2003
![]() |
Phipps said: but I think the switch out callback gets called twice Has been fixed in 4.2.2.
-- |
bamccaig
Member #7,536
July 2006
![]() |
I can't believe people are still using Windows 98... -- acc.js | al4anim - Allegro 4 Animation library | Allegro 5 VS/NuGet Guide | Allegro.cc Mockup | Allegro.cc <code> Tag | Allegro 4 Timer Example (w/ Semaphores) | Allegro 5 "Winpkg" (MSVC readme) | Bambot | Blog | C++ STL Container Flowchart | Castopulence Software | Check Return Values | Derail? | Is This A Discussion? Flow Chart | Filesystem Hierarchy Standard | Clean Code Talks - Global State and Singletons | How To Use Header Files | GNU/Linux (Debian, Fedora, Gentoo) | rot (rot13, rot47, rotN) | Streaming |
Richard Phipps
Member #1,632
November 2001
![]() |
Hmm.. no idea then! IMHO there are major issues with sound and window control in Allegro. |
Andrei Ellman
Member #3,434
April 2003
|
Looks like it's a bug in Allegro then. I've notified the devs. Cookie time. AE. -- |
Audric
Member #907
January 2001
|
I made some more serious tests in the default windows background mode : On either OS and Allegro version, DUMB playback stutters when the window doesn't have the focus - I guess I'll have to call al_pause_duh() and al_resume_duh() when switched out and in. |
|