My laptop's sound driver, among many others, has this absolutely infuriating behavior where it puts the sound card to sleep after a particular amount of silence (mine's seemingly after 5 seconds), causing a screen reader user to miss the beginning of speech, an audio file, a notification, or anything else they may be trying to listen to. To solve this, this practically microscopic C program was born. Simply run it, and it'll start piping silent audio through your default sound card, thus completely eliminating this aggravating sleep behavior. It should also respect device changes (e.g. unplugging headphones). To close it, simply click on the tray icon, and select exit. It doesn't get much simpler than that.
Batch scripts for building with MSVC 2022 and PellesC are included in the repository. Probably no one here cares about MSVC, but if you want to use it, either install your build tools portably with the portable build tools installer to C:\BuildTools, or change the path. For the pelles script, nothing is needed other than having \PellesC\Bin on your path.
With both Pelles C and MSVC, the binary is just 6 KB, including an embedded WAV resource! Quite impressive!
https://github.com/trypsynth/SleepSoundly/
Forgot to mention in my first post, but a goal of mine was making this use no CRT. I succeeded, having to write a custom memset implementation if I wanted to use {0} to zero-initialize my structs without having to do it for all the fields manually, but that was easy. It only applied to MSVC, so I'm considering just ditching MSVC and using Pelles as my main and only C compiler.
// Allows for {0} initialization without the CRT.
void* __cdecl memset(void* dest, int value, size_t count) {
unsigned char* p = dest;
while (count--) *p++ = (unsigned char)value;
return dest;
}
It can probably be made faster, and I welcome ways to do so, but it's only for zeroing two structures, so I didn't worry about it too much. And, like I said, Pelles is awesome, and doesn't internally use memset when you use {0}...thanks Microsoft... so it's a moot point.
Pelles C optimization replace memset with very simple code.
Also there are predefined names in linker for entry code.
In Pelles C project things are simpler.
With simple things compiling things are easier with cc.exe
cc.exe -Ze SleepSoundly.c SleepSoundly.rc
with these changes:
#pragma comment (lib, "user32.lib")
#pragma comment (lib, "shell32.lib")
#pragma comment (lib, "winmm.lib")
#pragma comment (linker, "-subsystem:windows")
...
int __cdecl WinMainCRTStartup(void)
Both versions at same time
SET PATH=C:\code\PellesC13rc3\bin
SET INCLUDE=C:\code\PellesC13rc3\include;C:\code\PellesC13rc3\include\Win
SET LIB=C:\code\PellesC13rc3\lib;C:\code\PellesC13rc3\lib\Win
cc.exe -x -Tx86-coff -Ze SleepSoundly.c SleepSoundly.rc
SET LIB=C:\code\PellesC13rc3\lib;C:\code\PellesC13rc3\lib\Win64
cc.exe -x -Tx64-coff -Ze SleepSoundly.c SleepSoundly.rc -FeSleepSoundly64.exe
PAUSE
Hi Timo,
Very cool, thanks for sharing! I await the (hopeful) eventuality where I can actually use the Pelles IDE and ditch these batch files :D