Teridon's Miscellaneous Hacks

Use a program or batch script to switch speaker setup from 5.1 surround to headphones

Dec 22, 2007 by Teridon

I occassionally play the game Counterstrike Source. When I do, I like to use headphones instead of my 5.1 setup, so I can hear enemies coming better. Windows doesn't seem to provide an easy way of switching the speaker configuration from 5.1 to headphones. I also couldn't find any tools on the net to do it for you. The only way seems to be to open the Sound control panel, click the Advanced button, and select the desired speaker setup from the pulldown. You can also switch the speaker type in-game, but (at least on my computer) when you do it the audio is muted for about a minute before it comes back!

I got very tired of this, so I figured out how to switch from 5.1 surround to stereo headphones using a batch script and a saved registry file. Similarly, I also wrote another batch script for switching between stereo headphones and 5.1 surround. I hope to someday soon write a script to automate the process, but for now -- follow the steps below to do the same for your system.

I finally found this helpful page from Microsoft, which indicated that these settings are stored in the registry. MS provides a function "IDirectSound::SetSpeakerConfig" to change it using a program, but writing a whole program for such a simple thing seemed like overkill. It turns out that setting the correct registry values also works!

That said, I found this post on mp3car.com that tells you how to write a very small program to do it. After downloading Microsoft Visual C# 2008 Express Edition, documentation, and the DirectX SDK, I now have two separate applications that will switch the speaker configuration between 5.1 and headphones. Unfortunately they do not correctly set the "Speaker Type". As far as I can tell, that's not a problem. It may impact DirectSound3D effects.

Download "Set Stereo Headphone Sound" v1.0.0.2

Download "Set 5.1 Surround Sound" v1.0.0.2

Note: These applications check for updates automatically. Also, they require MS Installer 3.1 and .NET Framework 3.5. If you don't have them, the setup program will automatically download them. Once installed, the programs will be available via your Start menu.

If for some reason you still want to use the registry method, you're in for a long manual setup process. But once you have it setup, it works well.

To find the right registry values, open regedit and navigate to

HKLM\SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Enum\PCI\

If you only have one sound card, then there is probably only one folder under PCI. If so, great! Just open it up and drill down to "DirectSound". If there is more than one (perhaps you have two sound cards?) you can just search for DirectSound. If you have more than one card, you'll have to figure out which is the right one.

There are two keys that change under DirectSound when you change your speaker settings in the Control Panel -- "Speaker Configuration", and "Speaker Type".

Right-click on the "DirectSound" folder and select "Export".

Make sure the export range is "Selected branch", and the "save as type" is "Registration Files (*.reg)". The file name should be whatever your current speaker settings are (e.g. "5.1 sound.reg"). Change your speaker settings using the Control panel to the one you want to swap to (e.g. "Stereo headphones"), then export the DirectSound registry folder again. This time save it as "headphones.reg".

Optionally, you can edit the registry files you just made and remove everything except the "Speaker Configuration" and "Speaker Type" settings. Again, this is optional; if you leave the other stuff in, it won't hurt anything.

At this point, your saved registry file for "5.1 sound" should look something like this:

Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Enum\PCI\VEN_1102&DEV_0004&SUBSYS_20021102&REV_04\4&13699180&0&2848\DirectSound\Speaker Configuration] "Speaker Configuration"=dword:00000006 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Hardware Profiles\Current\System\CurrentControlSet\Enum\PCI\VEN_1102&DEV_0004&SUBSYS_20021102&REV_04\4&13699180&0&2848\DirectSound\Speaker Type] "Speaker Type"=dword:0000000B

Note: your PCI vendor values will likely be different, so don't just use my file! Follow the steps above to make your own registry files!

At this point, you can just double-click the reg file to set your speaker configuration. However, Windows will prompt you twice with "Are you sure...", and "Information .. was added to the registry". If you want to avoid these prompts, you have to make a batch file to import the reg files using the command-line tool "reg".

Open up a text editor and enter

reg import "5.1 sound.reg"

and save it to the same directory as the reg file. Note that the quotes are important if you have spaces in the filename! Optionally, you can use the full path to the registry file, and save the batch file to your desktop or Quick Launch folder. Rename the text file to use ".bat" as the extension.

Do the same for the other reg file, except obviously use "headphones.reg":

reg import "headphones.reg"

You can check to make sure each batch file works by looking at the speaker configuration in the control panel. Note that the "Advanced Audio Properties" dialog won't update automatically if you have it open when you run the batch file. You have to close the dialog, then click "Advanced" again to see the change.