Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate

Changing default audio device


  • Please log in to reply
104 replies to this topic
Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
vitalyb, your code is full of errors under 7, can't get it to work

vitalyb
  • Members
  • 18 posts
  • Last active: Nov 23 2010 06:15 AM
  • Joined: 28 Mar 2006
That's not surprising... I did it for XP:

P.S The code works in XP, I assume some changes would be needed under Vista/7


I am sure it isn't too hard to change it to work for 7 though.
Vitaly

andrewilley
  • Members
  • 1 posts
  • Last active: Dec 18 2009 08:48 PM
  • Joined: 18 Dec 2009
Did anyone work out the equivalent registry keys for Windows 7 in order to preselect either Stereo output or SPDIF before launching a program?

I'm not worried about changing settings while the program is running, all I want to do is create two shortcuts, one to launch a mediaplayer with SPDIF already enabled if I'm using my second display (i.e. TV and surround amp) and the other with simple analogue Stereo already enabled when I'm using the PC monitor.

Andre

vitalyb
  • Members
  • 18 posts
  • Last active: Nov 23 2010 06:15 AM
  • Joined: 28 Mar 2006
Here is what I found for Win7 here (bottom):

I shelled a lot of money on my HTPC, and try to leverage it whenever possible. It sits in a rack in my utility room along with the receiver and cable box. It drives my 720p projector downstairs as well as a 24" panel in my office upstairs. I have 25' USB, DVI/HDMI, and audio cables connecting the display in each room to the PC. (The 8600GS has dual DVI outs.) By extending the Vista desktop across both displays, and using a simple batch file to toggle the 'Primary' display, I can switch back and forth and use the PC from whatever room I happen to be in.

One problem that appeared early on is audio. Because everything is DTS over SPDIF in my setup, there is no easy way to get analog audio upstairs for the panel. None of my sound cards will output both SPDIF and analog at the same time. It's always one or the other. The solution was to drive the projector room with my DTS card and the office with my 2nd (onboard) sound card. Using Vista Audio Switcher, I can now kick off a simple batch file that switches the primary display and also switches the primary audio card. The batch icons sit on the secondary desktop.

Display Changer by 12noon handles the desktop switching. Vista Audio Changer takes care of the audio.

Both applications have been added to the path. I use two batch files (upstairs.bat and downstairs.bat)

Upstairs.bat: -makes the panel primary and the projector secondary. Use onboard soundcard for audio.

dc64cmd.exe -monitor="\\.\DISPLAY1" -more -primary
dc64cmd.exe -monitor="\\.\DISPLAY2" -apply -right -secondary
AudioChangerGUI.exe -t "Speakers Realtek High Definition Audio" -x

Downstairs.bat - makes the projector primary and the panel secondary. Use Azuntech DTS sound card for audio to receiver.

dc64cmd.exe -monitor="\\.\DISPLAY2" -more -primary -force
dc64cmd.exe -monitor="\\.\DISPLAY1" -force -secondary -left -apply
AudioChangerGUI.exe -t "Speakers HDA XPLOSION 7.1" -x


Vitaly

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
I didn't know what to make out of that? Is it possible to switch audio play back devices using that?

vitalyb
  • Members
  • 18 posts
  • Last active: Nov 23 2010 06:15 AM
  • Joined: 28 Mar 2006
You can, using this application:

<!-- m -->http://vachanger.sou....net/index.html<!-- m -->
Vitaly

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
Nah, doesn't work on 7
And even if it did I still prefer ahk :D

vitalyb
  • Members
  • 18 posts
  • Last active: Nov 23 2010 06:15 AM
  • Joined: 28 Mar 2006
Why not use the Win7 snippet that was described here?
I admit it isn't the best kind and can be faulty (no string checking) but it works.

I just updated to windows 7 and needed a toggle version of this script. I mixed and matched what I had with the above posts and came up with this.

This will set the first device active if it isn't already.
If the first device is active then it will activate the 3rd device.

Additionally once a device is picked it plays a sound so you know which device is selected.

^+`::
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if(!isEnabled)
{
	ControlSend,SysListView321,{Down 2}
}
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return


Vitaly

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
It works and its what I use for now, but its not the best way I guess, same issue was with switching monitor but then socd cracked it and now it works perfect, take a look

http://www.autohotke...er=asc&start=45

vitalyb
  • Members
  • 18 posts
  • Last active: Nov 23 2010 06:15 AM
  • Joined: 28 Mar 2006
Awesome! It helped me too. Thanks.
Vitaly

Anon
  • Guests
  • Last active:
  • Joined: --
Here's some C# code to toggle between audio devices:

            List<string> deviceNames = new List<string>(); 
            RegistryKey volCtrl = Registry.CurrentUser.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control");
            foreach (string keyName in volCtrl.GetSubKeyNames())
            {
                if (keyName.Equals("Options", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                deviceNames.Add(keyName);
            }
            RegistryKey volDevice = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Multimedia\Sound Mapper",true);
            string currentDevice = (string)volDevice.GetValue("Playback");
            int currLocation = 0;
            for (int i = 0; i < deviceNames.Count; i++)
            {
                if (deviceNames[i] == currentDevice)
                {
                    currLocation = i;
                }
            }
            currLocation++;
            if (currLocation == deviceNames.Count)
            {
                currLocation = 0;
            }
            volDevice.SetValue("Playback", deviceNames[currLocation]);


Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009

Here's some C# code to toggle between audio devices:

            List<string> deviceNames = new List<string>(); 
            RegistryKey volCtrl = Registry.CurrentUser.OpenSubKey( @"Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control");
            foreach (string keyName in volCtrl.GetSubKeyNames())
            {
                if (keyName.Equals("Options", StringComparison.InvariantCultureIgnoreCase))
                {
                    continue;
                }
                deviceNames.Add(keyName);
            }
            RegistryKey volDevice = Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Multimedia\Sound Mapper",true);
            string currentDevice = (string)volDevice.GetValue("Playback");
            int currLocation = 0;
            for (int i = 0; i < deviceNames.Count; i++)
            {
                if (deviceNames[i] == currentDevice)
                {
                    currLocation = i;
                }
            }
            currLocation++;
            if (currLocation == deviceNames.Count)
            {
                currLocation = 0;
            }
            volDevice.SetValue("Playback", deviceNames[currLocation]);


How do I use this in ahk?

dredwerker
  • Guests
  • Last active:
  • Joined: --

I think this is pretty efficient. The sound dialog pops up, but for a split second only.

Here I've set it to F5 setting the first device on the list as default and F6 setting the second as default. Tweak it as needed.

#F5::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down}
    ControlClick,&Set Default
    ControlClick,OK
    return
#F6::
    Run, mmsys.cpl
    WinWait,Sound
    ControlSend,SysListView321,{Down 2}
    ControlClick,&Set Default
    ControlClick,OK
    return



oscarnx
  • Members
  • 1 posts
  • Last active: Mar 21 2010 10:36 AM
  • Joined: 21 Mar 2010
I'm running Win7 and AHK v1.0.48.05. I use this AHK-script to toggle between my analog output (computer speakers) and my digital output (home theater).

Instead of assigning a hotkey-combo for it, I assigned the .ahk-file to a key on my keyboard. I added 'exit' to the previous code to kill the ahk-script after it's run. I also changed the 'Down 2' to simply 'Down' in the ControlSend-command since I only have two enabled devices.

I especially like the tweak that it plays a sound on the enabled speakers! :)

*********
Run, mmsys.cpl
WinWait,Sound
ControlSend,SysListView321,{Down}
ControlGet, isEnabled, Enabled,,&Set Default
if(!isEnabled)
{
ControlSend,SysListView321,{Down}
}
ControlClick,&Set Default
ControlClick,OK
WinWaitClose
SoundPlay, *-1
return
exit
**********

Thanks for the script, it makes everything more smooth! :) :)

Gauss
  • Members
  • 203 posts
  • Last active: Jan 27 2012 12:49 PM
  • Joined: 10 Sep 2009
Nah, this is a noob way, there must be a way to do it in the registry or somewhere else, without seeing windows jumping around, its just a matter of time before some guru figures that out :D