Upon alt-tabbing out of Silent HIll 2 (which is run via dxwnd ofc) the sound is lost (gameplay still works).
Is it possible to force sound to play when window focus is lost?
Thanks!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hopefully yes, I have to have a look. Maybe the game uses DirectSound and needs some fix.
In the meanwhile, would you mind to try the Input / "Unacquire input devices on focus lost" flag? That flag should also force the Acquire of the device when the focus is gained again, maybe that could have a positive effect also on the sound.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Browsing the source code, I recall that I made a fix for a maybe similar problem in "Arxel Tribe", patching some DirectSound method. I didn't replicate the trick for DirectSound8: can you tall me what version of DirectSound the program is using? In alternative, could you post me just the exe file alone, so that I can analize dll dependencies?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Interesting: the program uses DirectSound, but it doesn't reference the calls by name, but rather by ordinal number. So, I believe that at ordinal 0000000B there should be something like DirectSoundCreate or something similar (see screenshot).
No worry, I've managed such a situation already.
By the way, while I build a patch, you may improve the situation by avoiding the program that it lost focus: it is possible that the "Do not notify on task switch" avoid losing sound, but with the side effect that monsters won't stay quiet while you do something else ....
Weird. The thing doesn't happen to me: alt-tabbing in and out, I never lose the sound, if not temporarily until you click again on the window. In any case, I forgot to tell you that the "Unacquire input devices on focus lost" flag works only after you hook the proper DirectInput dll, so in this case you should check the "Hook dinput8" flag as well.
P.s. did you know that the Direct3D / "Disable fogging" option can completely eliminate the fog from the game?
"Unacquire input devices on focus lost" with "Hook dinput8" flag set doesn't make any difference for me. Sound still disappears when I alt-tab out of the window. Wierd!
"Do not notify on task switch" also doesn't have any impact on the sound issue.
Direct3D / "Disable fogging" works for me, cool stuff!
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I got a doubt (too bad it didn't come yesterday evening, when I was having all pieces at reach): I made my tests with the Director's Cut edition of the game. This evening I will compare the two executables, yours and mine: maybe there was a patch in between....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I made a lot of wrong assumptions.
First one, that we have the same game. The two exe are different! To doublecheck, I tried my game installation using your exe, but the sound is still ok. I'll put here my exe (Director's Cut edition), just in case it has some sound fix in it.
Second error: linking dsound doesn't necessarily mean a DirectSount interface: I looked in a more recent dll file and see what I got: at ordinal 0B there is the call to DirectSoundCreate8! This opens the possibility of wrapping this new interface and check what it is possible to do.
Have faith ....
No thanks: it happens that this game has two interesting features:
1) has DirectSound8 problems to fix
2) has dll entries linked by ordinal number
Both problems were left unresolved, but are potentially very interesting and useful in other possible cases, so don't be surprised if I'm going to dedicate a lot of effort to this specific case.
Stay tuned for news (I would suggest to subscribe for mail updates to this thread: news will come, but maybe not so soon!)
see ya
GHO
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
First step completed: I think I learnt how to hook calls that are linked by ordinal number rather than by name. In this specific case, I was able to hook the call to DirectSoundCreate8 and the method SetCooperativeLevel.
Now the problem is: what could I do to fix the sound problem? Apparently the cooperative level is PRIORITY tipe, whic is good for windowed applications, and in affect I got no problems on my pc.
Is anyone able to suggest what could be the cause of the problem and what should be done to eliminate it? Once known that, I will implement.
@Bigmanjapan - one question: is the problem caused by DxWnd or does it happen also without and in fullscreen mode, for instance alt-tabbing different applications?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Sad news: the fact it doesn't depend on DxWnd, plus the fact that it doesn't happen to me, makes it definitely harder to fix!
Try gogling a little about the problem. I couldn't find anything very specific, but for instance look at this: http://steamcommunity.com/app/295110/discussions/0/613948093884425889/
It could be interesting to verify whether the Alt-tab causes a sound stop for the game or if it just sets the volume to zero....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I think I made a mistake there in explaining my issue.
If I alt-tab out of SH2 window, then sound disappears, but if I alt-tab back, the sound is back.
My wish was on making sound not dissappear at all, even during alt-tab.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
That would be possible (maybe, just in theory) if the game doesn't stop.
The game engine does the exact contrary: as soon as it loses focus, it stops itself, ready to recover when the focus is gained again.
I can see if it's possible to avoid this, but you must be aware that while you listen to music looking at some other window, some monster may cut you in pieces. Well, not really YOU, but your character in the game, of course ....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Did this ever get fixed? Im currently playing The Longest Journey while streaming the game with capturing the dxwnd window. I figured out most of the issues but the last one remaining is that id like the sound to keep going while i leave the window to answer chat or anything during cutscenes. The game already keeps running while out of focus just the audio stops and gets back when i click the window again. Id really like a solution to this.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Interesting issue, not yet faced: in theory the "Do not notify on task switch" should avoid the program to notice that it has lost focus, but I believe that this is not enough, maybe DirectSound has other ways to tell wheter the sound should be played or not. I'll try something ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
DSBCAPS_GLOBALFOCUS The buffer is a global sound buffer. With this
flag set, an application using DirectSound can continue to play its
buffers if the user switches focus to another application, even if the new
application uses DirectSound. The one exception is if you switch focus to
a DirectSound application that uses the DSSCL_WRITEPRIMARY flag for its
cooperative level. In this case, the global sounds from other applications
will not be audible.
Of course, this holds for DirectSound8 only and under the condition that the DSBCAPS_GLOBALFOCUS capability is supported. I wonder if there's some equivalent for other older interfaces. In any case, setting this flag will require some digging into the DirectSound objects, it will take a little while ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
W.I.P.: I admit that I never paied much attention to sound problems, but before adding new features I'll have to fix the hooking schema: apart from many little bugs, I noticed now that hooking some games (by enabling the "Hook DirectSound" flag) some games become muted and the log is filled with errors. There must be some further bug ....
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
An interesting twist, though it brings my completion status a little backward: most of the stuff I wrote to hook DirectSound is wrong and causes the program to stay silent or, worse, to crash. The problem seems tricky but hopefully I found it: the DirectSound and DirectSoundBuffer method pointers are not fixed, for instance there are different values for the different buffer types, like primary buffer and other buffers. Since the sound play while the task is in background requires a particular buffer capability, it is mandatory that I fix this hooking code first and try to produce the desired effect later.
Of course, since capabilities are involved, there is some risk that Benjamin's wish could depend on the program or on the hardware, so it is not garanteed that it eventually will work as desired, but we can try ...
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Here is some result, at last.
Once fixed the DirectSound hooking schema and added a pair of GLOBALFOCUS flags things are starting to run properly, at least with some games.
You can test how things are going with the games that interest you and report back the result.
These the instructions:
1) download and install (that is, replace) the files in the attached archive over the last v2.04.69 release
2) configure the games in expert mode (I suppose you did that already), go to the Sound configuration tab where you'll have to set the flags as in the attached picture. In detail, you have to hook DirectSound for sure (flag "Hook DirectSound"), then you can force the globalfocus mode capability: default leaves the game setting untouched, ON produces the effect that you desire, OFF the exact opposite.
3) Please, consider that the game may have global focus ON but stop producing music when it loses the focus: in that case you'll have also to check the "Do not notify on task switch" flag in the Main panel so that the game doesn't realize to have been switched.
4) Please, consider also that this feature is preliminary and limited to DirectSound only, so for instance no DirectSound8 for the moment.
So i tried out using the version and settings you gave me but the issue is still the same. If i click out of the window the game keeps running but the sound dies.
I want to tell though that Videos (The Intro for example) are not affected by that (regardless of sound flags). If i click elsewhere during the Intro the video's sound keeps going. Only in the actual game and during conversations the sound stops. When i tried to uncheck the "Do not notify on task switch" again with the new sound settings on, the game just stops completely when out of focus.
Im attaching the settings i use for the longest journey to this (hope it works). Those are the best working settings so far. I fixed the mouse from stuttering and leaving trails.
Other issues i still have is that the mouse icon gets split sometimes on screen (theres a gap between top and bottom of the mouse cursor) and that the "smooth edges on screen fonts" option in windows preferences gets disabled everytime i start the game.
I did not check other games for this issue yet im only referring to the GOG version of "The Longest Journey".
Hello!
Upon alt-tabbing out of Silent HIll 2 (which is run via dxwnd ofc) the sound is lost (gameplay still works).
Is it possible to force sound to play when window focus is lost?
Thanks!
Hopefully yes, I have to have a look. Maybe the game uses DirectSound and needs some fix.
In the meanwhile, would you mind to try the Input / "Unacquire input devices on focus lost" flag? That flag should also force the Acquire of the device when the focus is gained again, maybe that could have a positive effect also on the sound.
"Unacquire input devices on focus lost" flag has no effect.
And the game has no downloadable demo. Ok, It will take a little more ....
Please, be patient!
Browsing the source code, I recall that I made a fix for a maybe similar problem in "Arxel Tribe", patching some DirectSound method. I didn't replicate the trick for DirectSound8: can you tall me what version of DirectSound the program is using? In alternative, could you post me just the exe file alone, so that I can analize dll dependencies?
Here you go.
Interesting: the program uses DirectSound, but it doesn't reference the calls by name, but rather by ordinal number. So, I believe that at ordinal 0000000B there should be something like DirectSoundCreate or something similar (see screenshot).
No worry, I've managed such a situation already.
By the way, while I build a patch, you may improve the situation by avoiding the program that it lost focus: it is possible that the "Do not notify on task switch" avoid losing sound, but with the side effect that monsters won't stay quiet while you do something else ....
Last edit: gho 2016-03-08
Weird. The thing doesn't happen to me: alt-tabbing in and out, I never lose the sound, if not temporarily until you click again on the window. In any case, I forgot to tell you that the "Unacquire input devices on focus lost" flag works only after you hook the proper DirectInput dll, so in this case you should check the "Hook dinput8" flag as well.
P.s. did you know that the Direct3D / "Disable fogging" option can completely eliminate the fog from the game?
Last edit: gho 2016-03-08
"Unacquire input devices on focus lost" with "Hook dinput8" flag set doesn't make any difference for me. Sound still disappears when I alt-tab out of the window. Wierd!
"Do not notify on task switch" also doesn't have any impact on the sound issue.
Direct3D / "Disable fogging" works for me, cool stuff!
I got a doubt (too bad it didn't come yesterday evening, when I was having all pieces at reach): I made my tests with the Director's Cut edition of the game. This evening I will compare the two executables, yours and mine: maybe there was a patch in between....
I made a lot of wrong assumptions.
First one, that we have the same game. The two exe are different! To doublecheck, I tried my game installation using your exe, but the sound is still ok. I'll put here my exe (Director's Cut edition), just in case it has some sound fix in it.
Second error: linking dsound doesn't necessarily mean a DirectSount interface: I looked in a more recent dll file and see what I got: at ordinal 0B there is the call to DirectSoundCreate8! This opens the possibility of wrapping this new interface and check what it is possible to do.
Have faith ....
I did a test with your exe file — still no luck, sound disappears.
I use Win 7 64 if that might help.
Thanks for your effort.
No thanks: it happens that this game has two interesting features:
1) has DirectSound8 problems to fix
2) has dll entries linked by ordinal number
Both problems were left unresolved, but are potentially very interesting and useful in other possible cases, so don't be surprised if I'm going to dedicate a lot of effort to this specific case.
Stay tuned for news (I would suggest to subscribe for mail updates to this thread: news will come, but maybe not so soon!)
see ya
GHO
First step completed: I think I learnt how to hook calls that are linked by ordinal number rather than by name. In this specific case, I was able to hook the call to DirectSoundCreate8 and the method SetCooperativeLevel.
Now the problem is: what could I do to fix the sound problem? Apparently the cooperative level is PRIORITY tipe, whic is good for windowed applications, and in affect I got no problems on my pc.
Is anyone able to suggest what could be the cause of the problem and what should be done to eliminate it? Once known that, I will implement.
@Bigmanjapan - one question: is the problem caused by DxWnd or does it happen also without and in fullscreen mode, for instance alt-tabbing different applications?
Sound in SH2 always disappears during alt-tabbing. Doesn't matter if I play in fullscreen or use DxWnd / D3DWindower.
Sad news: the fact it doesn't depend on DxWnd, plus the fact that it doesn't happen to me, makes it definitely harder to fix!
Try gogling a little about the problem. I couldn't find anything very specific, but for instance look at this: http://steamcommunity.com/app/295110/discussions/0/613948093884425889/
It could be interesting to verify whether the Alt-tab causes a sound stop for the game or if it just sets the volume to zero....
I think I made a mistake there in explaining my issue.
If I alt-tab out of SH2 window, then sound disappears, but if I alt-tab back, the sound is back.
My wish was on making sound not dissappear at all, even during alt-tab.
That would be possible (maybe, just in theory) if the game doesn't stop.
The game engine does the exact contrary: as soon as it loses focus, it stops itself, ready to recover when the focus is gained again.
I can see if it's possible to avoid this, but you must be aware that while you listen to music looking at some other window, some monster may cut you in pieces. Well, not really YOU, but your character in the game, of course ....
Did this ever get fixed? Im currently playing The Longest Journey while streaming the game with capturing the dxwnd window. I figured out most of the issues but the last one remaining is that id like the sound to keep going while i leave the window to answer chat or anything during cutscenes. The game already keeps running while out of focus just the audio stops and gets back when i click the window again. Id really like a solution to this.
Interesting issue, not yet faced: in theory the "Do not notify on task switch" should avoid the program to notice that it has lost focus, but I believe that this is not enough, maybe DirectSound has other ways to tell wheter the sound should be played or not. I'll try something ...
I'm writing this for my memory. Here's what I found here: https://msdn.microsoft.com/en-us/library/windows/desktop/microsoft.directx_sdk.reference.dsbcaps(v=vs.85).aspx
Of course, this holds for DirectSound8 only and under the condition that the DSBCAPS_GLOBALFOCUS capability is supported. I wonder if there's some equivalent for other older interfaces. In any case, setting this flag will require some digging into the DirectSound objects, it will take a little while ...
W.I.P.: I admit that I never paied much attention to sound problems, but before adding new features I'll have to fix the hooking schema: apart from many little bugs, I noticed now that hooking some games (by enabling the "Hook DirectSound" flag) some games become muted and the log is filled with errors. There must be some further bug ....
An interesting twist, though it brings my completion status a little backward: most of the stuff I wrote to hook DirectSound is wrong and causes the program to stay silent or, worse, to crash. The problem seems tricky but hopefully I found it: the DirectSound and DirectSoundBuffer method pointers are not fixed, for instance there are different values for the different buffer types, like primary buffer and other buffers. Since the sound play while the task is in background requires a particular buffer capability, it is mandatory that I fix this hooking code first and try to produce the desired effect later.
Of course, since capabilities are involved, there is some risk that Benjamin's wish could depend on the program or on the hardware, so it is not garanteed that it eventually will work as desired, but we can try ...
Here is some result, at last.
Once fixed the DirectSound hooking schema and added a pair of GLOBALFOCUS flags things are starting to run properly, at least with some games.
You can test how things are going with the games that interest you and report back the result.
These the instructions:
1) download and install (that is, replace) the files in the attached archive over the last v2.04.69 release
2) configure the games in expert mode (I suppose you did that already), go to the Sound configuration tab where you'll have to set the flags as in the attached picture. In detail, you have to hook DirectSound for sure (flag "Hook DirectSound"), then you can force the globalfocus mode capability: default leaves the game setting untouched, ON produces the effect that you desire, OFF the exact opposite.
3) Please, consider that the game may have global focus ON but stop producing music when it loses the focus: in that case you'll have also to check the "Do not notify on task switch" flag in the Main panel so that the game doesn't realize to have been switched.
4) Please, consider also that this feature is preliminary and limited to DirectSound only, so for instance no DirectSound8 for the moment.
I'm waiting for news from you.
Last edit: gho 2018-03-09
Hey thanks for adressing the issue!
So i tried out using the version and settings you gave me but the issue is still the same. If i click out of the window the game keeps running but the sound dies.
I want to tell though that Videos (The Intro for example) are not affected by that (regardless of sound flags). If i click elsewhere during the Intro the video's sound keeps going. Only in the actual game and during conversations the sound stops. When i tried to uncheck the "Do not notify on task switch" again with the new sound settings on, the game just stops completely when out of focus.
Im attaching the settings i use for the longest journey to this (hope it works). Those are the best working settings so far. I fixed the mouse from stuttering and leaving trails.
Other issues i still have is that the mouse icon gets split sometimes on screen (theres a gap between top and bottom of the mouse cursor) and that the "smooth edges on screen fonts" option in windows preferences gets disabled everytime i start the game.
I did not check other games for this issue yet im only referring to the GOG version of "The Longest Journey".
Last edit: Benjamin Petry 2018-03-12