Thursday, October 1, 2015

The Sound of Silence

My Windows 7 home theater PC (HTCP) video and sound outputs both connect to my Sony receiver over HDMI, with the video routed by the receiver to the TV. Both the sound and video quality are excellent.

But there's a problem when switching between programs sourcing sound on the PC: The receiver makes a very loud pop/boom when the first sound is played after startup. After startup, the first couple seconds of program sound (such as a YouTube video) would be missed, though the sound would then continue without the pop/boom.

It took me a while to troubleshoot this phenomenon. It turns out that Windows completely stops outputting digital sound when there is no active sound source. That is to say, it does not output "silence" (a continuous sound stream containing data with a digital value of zero), but instead halts the entire Windows sound subsystem. So, when a program running on the HTPC starts to output sound, the Windows sound system has to be reinitialized, which can take a couple seconds.

At first, I suspected this was a Windows sound configuration issue. I did several searches and found no solution that involved changing system settings. I next looked for utilities or other apps that addressed the issue and found nothing.  Clearly, relatively few people run their sound through a receiver.

Under Linux, the fix would be simplicity itself: Run the sox program and tell it to output zeros.  Since I had Cygwin installed, it took only a moment to find that sox was indeed available under Cygwin, so I installed it, opened a terminal window, and entered the following command:

sox -n -d -q &

Ta-daa!  Problem fixed.  But I'd prefer the solution to be automatic, not manual.

The next step is to get sox to start when the HTPC boots, preferably so it will automatically restart sox if it ever exits.  Under Linux, this kind of thing is handled using cron or one of its successors.  I could install Cygwin cron, but is there a direct way to do this under Windows?

Sure!  Use the Windows 7 Task Scheduler.  You can follow this recipe combined with this one, or one of the many other similar recipes available.  Just be sure to run the task with Administrator privileges, which sox requires to access the sound hardware.