View Full Version : Does anyone know a way to retain audio when sh4 window loses focus?
themrwho
03-07-21, 07:35 PM
Hi,
My question is for Silent Hunter v.1.5 running on Windows 10. For this game, does anyone know a way to retain audio when sh4 window loses focus?
Extra info: As you might know, this is a design decision by developers - whether an application continues to emit audio when application window does not have focus. Usually this is a trivial thing to enable/disable for the dev team (or anyone with source code access). In fact some games even expose this, as a game-options-UI-setting (or sometimes as a not-so-apparent configuration tweak such as an .ini file or a startup parameter to the application launcher etc.). If there is a way for sh4 so far I have not found it hence the query.
Search results: I searched this forum and the web for before I post this thread. The only Subsim forums thread I managed to find on this matter was the one for sh5. Of course it does not help me with sh4 (and didn't help that guy with sh5).
SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > Silent Hunter 5 How to still hear game sound when game window is not focused on (alt-tabbed)? https://www.subsim.com/radioroom/showthread.php?t=174765
Background story: I have a dual-screen setup, I run sh4 in fullscreen borderless state (using the 1-pixel-less hack) on screen1 and I'm browsing the forums/web etc. on screen2. During long patrols with reduced time compression, most of the time nothing exciting is happening in the game so I listen to the radio/gramophone and browse forums etc.
With this setup I can visually see what's happening in the game but I'm missing out on radio/gramophone at all times and also because there is no crew audio announcements ("ship spotted!" etc.) that I can hear, I can miss a critical situation if I don't visually check out the screen for a while so if I can fix this missing audio issue I think my setup would be perfect!
Thanks in advance for any replies!
Mad Mardigan
03-07-21, 10:00 PM
Hi,
My question is for Silent Hunter v.1.5 running on Windows 10. For this game, does anyone know a way to retain audio when sh4 window loses focus?
Extra info: As you might know, this is a design decision by developers - whether an application continues to emit audio when application window does not have focus. Usually this is a trivial thing to enable/disable for the dev team (or anyone with source code access). In fact some games even expose this, as a game-options-UI-setting (or sometimes as a not-so-apparent configuration tweak such as an .ini file or a startup parameter to the application launcher etc.). If there is a way for sh4 so far I have not found it hence the query.
Search results: I searched this forum and the web for before I post this thread. The only Subsim forums thread I managed to find on this matter was the one for sh5. Of course it does not help me with sh4 (and didn't help that guy with sh5).
SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > Silent Hunter 5 How to still hear game sound when game window is not focused on (alt-tabbed)? https://www.subsim.com/radioroom/showthread.php?t=174765
Background story: I have a dual-screen setup, I run sh4 in fullscreen borderless state (using the 1-pixel-less hack) on screen1 and I'm browsing the forums/web etc. on screen2. During long patrols with reduced time compression, most of the time nothing exciting is happening in the game so I listen to the radio/gramophone and browse forums etc.
With this setup I can visually see what's happening in the game but I'm missing out on radio/gramophone at all times and also because there is no crew audio announcements ("ship spotted!" etc.) that I can hear, I can miss a critical situation if I don't visually check out the screen for a while so if I can fix this missing audio issue I think my setup would be perfect!
Thanks in advance for any replies!
Ahoy, themrwho... :Kaleun_Cheers:
Dunno, but.. if it can be done, set the focus sound wise to SH4... browsing posts & such.. doesn't really call for audio.. but.. that's just My suggestion... :yep: :hmmm:
M. M.
:Kaleun_Salute:
KaleunMarco
03-07-21, 11:03 PM
Hi,
My question is for Silent Hunter v.1.5 running on Windows 10. For this game, does anyone know a way to retain audio when sh4 window loses focus?
Extra info: As you might know, this is a design decision by developers - whether an application continues to emit audio when application window does not have focus. Usually this is a trivial thing to enable/disable for the dev team (or anyone with source code access). In fact some games even expose this, as a game-options-UI-setting (or sometimes as a not-so-apparent configuration tweak such as an .ini file or a startup parameter to the application launcher etc.). If there is a way for sh4 so far I have not found it hence the query.
Search results: I searched this forum and the web for before I post this thread. The only Subsim forums thread I managed to find on this matter was the one for sh5. Of course it does not help me with sh4 (and didn't help that guy with sh5).
SUBSIM Radio Room Forums > Silent Hunter 3 - 4 - 5 > Silent Hunter 5 How to still hear game sound when game window is not focused on (alt-tabbed)? https://www.subsim.com/radioroom/showthread.php?t=174765
Background story: I have a dual-screen setup, I run sh4 in fullscreen borderless state (using the 1-pixel-less hack) on screen1 and I'm browsing the forums/web etc. on screen2. During long patrols with reduced time compression, most of the time nothing exciting is happening in the game so I listen to the radio/gramophone and browse forums etc.
With this setup I can visually see what's happening in the game but I'm missing out on radio/gramophone at all times and also because there is no crew audio announcements ("ship spotted!" etc.) that I can hear, I can miss a critical situation if I don't visually check out the screen for a while so if I can fix this missing audio issue I think my setup would be perfect!
Thanks in advance for any replies!
uh, no offense intended, but you do not want to alt-tab out of SH4. Period. End of Story.
All sorts of bad things happen when a Kaleun shells out to Windows to go and do something non-SH4.
Do a search in Subsim or even Google for CTD and other assorted bad things and you will learn that the number one cause is shelling out/alt-tabbing.
good luck.
:Kaleun_Salute:
Mad Mardigan
03-08-21, 12:08 AM
uh, no offense intended, but you do not want to alt-tab out of SH4. Period. End of Story.
All sorts of bad things happen when a Kaleun shells out to Windows to go and do something non-SH4.
Do a search in Subsim or even Google for CTD and other assorted bad things and you will learn that the number one cause is shelling out/alt-tabbing.
good luck.
:Kaleun_Salute:
In this instance, KaleunMarco... themrwho, isn't alt tabbing out. They actually have a dual monitor set up & with that, it allows for each monitor, to do separate tasks.. in this case, SH4 & web browsing.
What they re trying to figure out, is with using their set up, in that manner.. is how to have audio on the monitor, running SH4.. as I understand it. On that, am not sure of what would need being done to accomplish that...:yep:
M. M.
:Kaleun_Salute:
themrwho
03-08-21, 01:25 AM
Thank you for the replies.
Dunno, but.. if it can be done, set the focus sound wise to SH4... browsing posts & such.. doesn't really call for audio.. but.. that's just My suggestion... :yep: :hmmm:
Browsing does not require audio <-- depends on what you're browsing, doesn't it :03: Yes, it could be text-only forums (as I mentioned earlier) but it also could be a YouTube video etc. that works better with audio.
In any case "does the other screen really require audio" is perhaps a nice discussion point but not my current focus or current problem.
The problem is: the moment focus is on another "window" (the other window could be a web browser with a forums page or a video in it, it could even be a simple notepad), that very moment audio from sh4 window is completely muted out. In other words, sh4 window emits audio only when it has "focus". It's audio capability is linked to whether it is "the active window".
uh, no offense intended, but you do not want to alt-tab out of SH4. Period. End of Story.
All sorts of bad things happen when a Kaleun shells out to Windows to go and do something non-SH4.
Do a search in Subsim or even Google for CTD and other assorted bad things and you will learn that the number one cause is shelling out/alt-tabbing.
Thank you for the warning I appreciate you are trying to warn against bad stuff and I remember those issues from sh3 era.
Having said that, it's all in the past for me - I currently have a very stable setup with zero CTD or other issues (that I am aware of) so far. While I acknowledge bad stuff can happen (such as CO2 issue etc.) since it has not happened to me yet, no need to curtail freedoms that help me enjoy long patrol periods. This is not twice as good as sh3, in my scale my current sh4 experience is 10x better than sh3 experience so I will continue on this road (of running sh4 in my one screen, doing other stuff on my other screen). It works great. Strongly recommended - just try it out. If you have "bad stuff" happening to you obviously stop doing that but so far my "bad stuff experienced" counter is at zero after playing hundreds of hours on this PC :up:
Mad Mardigan
03-08-21, 12:56 PM
Thank you for the replies.
Dunno, but.. if it can be done, set the focus sound wise to SH4... browsing posts & such.. doesn't really call for audio.. but.. that's just My suggestion... :yep: :hmmm:
Browsing does not require audio <-- depends on what you're browsing, doesn't it :03: Yes, it could be text-only forums (as I mentioned earlier) but it also could be a YouTube video etc. that works better with audio.
In any case "does the other screen really require audio" is perhaps a nice discussion point but not my current focus or current problem.
The problem is: the moment focus is on another "window" (the other window could be a web browser with a forums page or a video in it, it could even be a simple notepad), that very moment audio from sh4 window is completely muted out. In other words, sh4 window emits audio only when it has "focus". It's audio capability is linked to whether it is "the active window".
Ahoy themrwho...:Kaleun_Cheers:
Ok
Just spit balling this here...
Could also do what I am considering doing... Have another tower I am working on & having that 1 to be My more... hard core gaming go to rig. Had thought of then selling this 1 I am on now, off as someone else's starter.. but, on reflection... could still keep it around to use as 1 to use for like web browsing, email checking social media type stuff... so that definitely frees up the other rig, for as I outlined.. My go to game rig only.
Not saying you have to go that route as well.. but.. is something to consider.. just a suggestion. :hmmm: :yep:
On that note... best to you on this.. & Good huntin'...
M. M.
:Kaleun_Salute:
themrwho
03-08-21, 01:21 PM
Could also do what I am considering doing... Have another tower I am working on & having that 1 to be My more... hard core gaming go to rig. Had thought of then selling this 1 I am on now, off as someone else's starter.. but, on reflection... could still keep it around to use as 1 to use for like web browsing, email checking social media type stuff... so that definitely frees up the other rig, for as I outlined..
Hey thanks for getting back to me on this. That's a nice suggestion indeed. In fact I used to do that with a smallish laptop sitting on the desk. Later I moved on to tablet. It works great for consuming stuff (to watch a YouTube video, to read others AARs etc.). I think it can be better if it could all be done on one single PC though as there is limited desk space to have 2 fullsized keyboards on my desk (hence the switch from laptop to mini tablet earlier).
I am still hoping -at this point, more like dreaming about- a fix to this problem though so that these long sh4 cruises can be a background task WITH audio.... Web search shows many people had similar requirements/wishes, even for other games, here is one for Mass Effect from 8 years ago: https://gaming.stackexchange.com/q/129032
Too bad Ubisoft devs didn't make this a simple checkbox (or even a .ini setting etc.).
EDIT: found an example of what I was trying to explain earlier, as can be seen in this "answer", in another game engine for example, it is literally a "setting". In this case, it is, how many percent of audio volume do you wish to LOSE when game window loses focus --> https://answers.unrealengine.com/questions/66918/keep-audio-from-losing-focus.html
If it was a setting like that, in Silent Hunter 4, we could set it to zero and be done with it :(
KaleunMarco
03-08-21, 03:54 PM
I think it can be better if it could all be done on one single PC though as there is limited desk space to have 2 fullsized keyboards on my desk (hence the switch from laptop to mini tablet earlier).
look into a KVM in order to better utilize desk space.
i have been using KVM's since we invented them back in the 90's.
:Kaleun_Salute:
themrwho
03-08-21, 04:44 PM
look into a KVM in order to better utilize desk space.
i have been using KVM's since we invented them back in the 90's.
:Kaleun_Salute:
hmm thanks for the suggestion. I too used to use KVM in the 90s and early 2000s prior to "Cloud" taking over everything.
Today though, at my home, rather than adding a KVM (plus cables) to the mix, I could just keep using the laptop as a self contained 2nd set of computer (or tablet with its virtual keyboard - it's less comfy to type but also less desktop clutter).
Periscope depth in my heart though, I'm still hoping/dreaming a software solution to my problem that would help me get rid of 2nd laptop/tablet/PC altogether so that I can end up with just 1 computer with 2 screens; SH4 running on one with audio-in-the-background feature patrolling at low TC, and "other stuff" running on the other (focus active) screen.
To give any interested parties an update: I web searched some more today and found this "product" that someone was selling to people like me. It solves the same problem I have here but it is not for Silent Hunter but for Microsoft's Flight Simulator game:
Flight1 SoundStream is an ingenious little tool that keeps the Flight Simulator sound enabled even when FSX is running in the background. It lets you use add-on programs developed for Flight Simulator (such as moving maps) without interrupting the in-flight sound experience. Or you can read and answer an email or surf the web during a long flight - all this without your ears leaving the cockpit. No more missed ATC calls and any warning sounds, and of course you will hear that the engines are still running!
https://www.flight1.com/products.asp?product=soundstream
themrwho
03-09-21, 05:33 PM
I did some further research into this yesterday, I would like to share results below in case someone out there who has experience with Windows API/MFC/whatever-else-is-in-play-here wants to lend experience.
Found a potential hack as described in the 1st link below - it is essentially sending WM_ACTIVATE message to the window as per official Microsoft documentation in the 2nd URL. I have so far no evidence that this is implemented in the gamecode so I was not super hopeful but was thinking it's probably worth a try, what would I lose.
I still didn't get a chance to implement it in C++ but did look into quickly testing it with a 2 line AHK script as I noticed it is in the AutoHotkey message list (3rd URL).
Test result: basic messaging via AHK does work, at least it works for some messages (e.g.: WM_CLOSE/0x0010 indeed closes SH4 application just fine). Unfortunately sending WM_ACTIVATE via AHK did nothing.
At then end of the day, while I am not anywhere close to fixing the original problem described in the title of this thread, one good (practical) thing came out of all this effort... I discovered that I can message the game window with hide/unhide signals (easiest way would be using AHK and WinHide/WinShow signals). The practical implementation would be: "boss key" or in my case, more like "boss shortcut". During the day sometimes I fire up and play sh4 for short amount of time but the darn window is always on top thus it takes away 50% of my screen estate on a dual screen setup, forcing me to close the game as soon as I need to do something else on that screen. With this boss-shortcut hack, I can now press a key-combo to hide it completely. And, later on, press the same key-combo bring it back maybe 10 minutes later or maybe 5 hours later, after work hours. Less loading time, more playing time!
Links
1) https://stackoverflow.com/a/45496600
2) https://docs.microsoft.com/en-us/windows/win32/inputdev/wm-activate
3) https://www.autohotkey.com/docs/misc/SendMessageList.htm
propbeanie
03-12-21, 12:40 PM
https://www.youtube.com/watch?v=j12J3PCai5A
"It's not nice to fool with Microsoft!!!"
The issue has more to do with the game's programming paradigm. When it was written (Windows XP, and 32-bit), there were only "dreams" of multi-tasking, and "fake" alternatives to it, of which, most of the current technologies really are nothing more than more "efficient" ways to simulate multi-tasking, based mostly on the hardware resources available in the 'modern' computer... but I digress. SH4 is a single-core game, that assumes its address space is the same, no matter what you do in windows. It is for this reason that "swapping out" to the OS "kills" the audio stream, sometimes resulting in an address change of the buffer for the game (from Windows, which leads, guides and directs all aspects of one's computer life), which sometimes results in "odd" behavior when the game once again gains focus. Your current technique apparently minimizes these "issues", but it still might just be a roll of the dice before you get the CO2 not clearing, or the cloud of steam following your boat about the seas of the world, or anyone of a varied sort of maladies yet to be encountered. To keep the audio stream "alive", the game needs to keep "focus", which of course negates the computer's use for anything other than SH4 exclusively. :salute:
Mad Mardigan
03-12-21, 03:08 PM
https://www.youtube.com/watch?v=j12J3PCai5A
"It's not nice to fool with Microsoft!!!"
The issue has more to do with the game's programming paradigm. When it was written (Windows XP, and 32-bit), there were only "dreams" of multi-tasking, and "fake" alternatives to it, of which, most of the current technologies really are nothing more than more "efficient" ways to simulate multi-tasking, based mostly on the hardware resources available in the 'modern' computer... but I digress. SH4 is a single-core game, that assumes its address space is the same, no matter what you do in windows. It is for this reason that "swapping out" to the OS "kills" the audio stream, sometimes resulting in an address change of the buffer for the game (from Windows, which leads, guides and directs all aspects of one's computer life), which sometimes results in "odd" behavior when the game once again gains focus. Your current technique apparently minimizes these "issues", but it still might just be a roll of the dice before you get the CO2 not clearing, or the cloud of steam following your boat about the seas of the world, or anyone of a varied sort of maladies yet to be encountered. To keep the audio stream "alive", the game needs to keep "focus", which of course negates the computer's use for anything other than SH4 exclusively. :salute:
Which is why I recommended, seeing of using another computer (be it laptop or another desktop, if you have a big enough desk to handle 2 desktops on it... :yep:) laptop, would be a more workable, feasible solution... Barring that, a tablet would also work.. or heck, even your so called 'smart' phone.
Of course, that is up to the 1 trying to do what is being discussed about doing by the main poster... not throwing rocks at their aspirations, just saying what I see of as more.. advisable options. From My perspective... :shucks: :yep:
M. M.
:Kaleun_Salute:
3catcircus
03-12-21, 05:33 PM
What is the 1-pixel-less hack?
themrwho
03-12-21, 06:40 PM
"It's not nice to fool with Microsoft!!!"
The issue has more to do with the game's programming paradigm. When it was written (Windows XP, and 32-bit)...<snip>
Nice video :up: And yes, I understand this game is from a different age... With the current system resources, our computers of course can handle a SH4 and many extra tasks at the same time. While you explained the background of why it is implemented the way it is this thread is all about modifying the existing software to change its behaviour which may or may not succeed, eventually. I am happy to keep at it though, at least for now.
Which is why I recommended, seeing of using another computer (be it laptop or another desktop, if you have a big enough desk to handle 2 desktops on it...
Yup, that is the current "solution" and frankly it does work - can't argue with that.
If a software workaround can be found, I will be happy to reduce the total computer count by one - if one cannot be found, I will continue as is.
I have invested some time on this issue, and there is at least one more method I would like to try.
I will share the results here in case it benefits anyone else.
Meanwhile, this thread stays open, waiting for that miracle in case someone knows a way to implement this somehow
What is the 1-pixel-less hack?
https://www.subsim.com/radioroom/showpost.php?p=2690692&postcount=9
Edit:
<snip>Your current technique apparently minimizes these "issues", but it still might just be a roll of the dice before you get the CO2 not clearing, or the cloud of steam following your boat about the seas of the world, or anyone of a varied sort of maladies yet to be encountered.<snip>
You may be right in assuming that "the issues (such as CO2 bug) will eventually hit you" however I have had zero issues so far. I get that it would be pointless to say "I *feel* I will never have issues" but what I can say today is "zero obvious issues occurred so far" (that I am aware of).
Which makes me think: am I not having the issues due to the fullscreen borderless window approach I have taken? Are you using fullscreen or are you using 1-pixel-less (as described in the linked post above)?
If you have not tried the 1-pixel-less method yet, perhaps give it a try as I have been saying it seems to be perfect.
propbeanie
03-12-21, 08:59 PM
I have implemented the windowed mode on my desktop downstairs, dual-screen, and I also have not had issue (yet). Curiosity has gotten the better of me on more than one occasion, but not here yet. I'll let you know if I do have issues. Of course, as you say, the 'modern' pc is quite the Hercules when compared to what we had in 2007 and around that era. If I remember correctly, PCIe was in its infancy? So most computers were AGP, and a ATI 9800 was top notch stuff... lol
themrwho
03-12-21, 11:58 PM
Script linked below is a workaround for now: it does not fix the core issue, and I am still after a better solution but until then, hopefully this will do.
Tested this only for an hour, more testing is needed but initial results are good.
Script just makes it easier (via AutoHotkey automation) to re-activate sh4 window without doing anything or clicking anything -- works simply by "waiting".
Script URL: https://gitlab.com/themrwho/focus-sh4
Script has three settings:
0=off
1=slight effort (activate sh4 window after 5s inactivity)
2=focused effort (activate sh4 window after 0.25s inactivity)
A global desktop shortcut (SHIFT+F2) changes toggles the setting (increments it by 1, after max value 2, another hit takes it to level 0).
Human voice (mp3) announces the new setting level as feedback.
With quick testing, I found the default and aggressive setting 2 -which is best for having maximum amount sh4 audio- difficult to use for doing anything more than a single click in the "other window".
However it works great for its intended purpose: if you're watching stuff on YouTube and also playing sh4 on the other screen (more like idling/patrolling, waiting for a contact etc.) you can click to a different point in time in the video, then you will get your sh4 audio back almost instantly.
When script activates sh4 window, what happens to the other-window?
The other-window (let's say web browser) stays mouse-wheel-controllable and as long as your mouse pointer is only hovering over on that other screen (i.e.: if you do NOT click into that other-window) you can keep mouse wheel controlling it forever, it will not deactivate sh4 window and thus will not lose sh4 audio.
Practical example: if you are on a forums thread, you can mouse wheel up/down, keep scrolling up/down and read the whole thing.
You could do all that without this script anyway.
With this script in its aggressive default setting (level 2) you can even click on the NEXT PAGE button then the script, in quarter of a second, will re-activate sh4 window for you and you'll regain audio without lifting a finger.
Effortless automation, combined with an adequate delay seems to be working well in the sense that I can now both browse/read forums and webpages, watch YouTube and also not lose sh4 audio which is what I wanted in the first place.
What I still cannot do is use the keyboard, for example while typing this message I have had to set the script to setting 0 (automation turned off) otherwise it would keep reactivating sh4 window when I don't want it to.
That's why I am still after a better solution, if I find one I will share that too. Meanwhile always happy for any more tips/assistance.
Just to be clear to benefit from this script, you need a dual (or better) screen setup and (probably) need to be running sh4 with (almost)-fullscreen-borderless mode, using the 1-pixel-less hack described in post #14 in this thread. Only after that you can freely move your mouse in the other screen without losing sh4 audio.
themrwho
03-13-21, 04:10 PM
Playing the game now & testing this script which led to a few small improvements. The GitLab repo has been updated.
1) For announcing new focus effort level rather than using .MP3 files we are now using .WAV files (0.wav, 1.wav, 2.wav). This change make script 100% compatible pretty much with any Windows O/S you can play sh4 on - in other words potentially missing mp3 codec is a non-issue now.
2) After further testing, the announcement volume level bothered me as it was too high. I have modified the 3x wav files and made alternative versions which have audio gain reduced by 18dB.
Script by default tries to play the minus18dB WAV files but should you prefer original (loud) WAVs or loud MP3s then you can simply change the relevant lines to restore old behaviour.
With this change, announcement now is more like: "FYI this is the new level..."
Older version was more like 25th second of this clip:
https://youtu.be/oOoBomvuYnw?t=25
vBulletin® v3.8.11, Copyright ©2000-2025, vBulletin Solutions Inc.