Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • September 03, 2015, 01:50:09 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: Audio output device manager  (Read 20296 times)

aljhenry

  • Supporting Member
  • Joined in 2007
  • **
  • Posts: 1
    • View Profile
    • Donate to Member
Audio output device manager
« on: April 23, 2007, 09:02:00 AM »
hi folks,

I have an annoyance that you may be able to help me with, there may even be software out there to solve this already.

I work on a laptop with a docking station in work, the docking station has desktop speakers through which i play music if I'm alone in the office, then I have USB headphones which I use to listen to music while people are in the office and for Skype. When i go home I listen to music through the internal laptop speaker or connect to an amplifier through my headphone jack.

My problem is that when switching between these output modes I often have to fiddle around for ages to get sound out of the appropriate device. Plug into the headphone jack means i have to restart itunes. Skype gives me real hassle and I can't seem to work out the correct procedure or sequence to plugging things in and starting programs.....

In windows (XP) there does not appear to be a central (or even useful) audio output manager, where the output device (or port) can be readily selected from a list of possibilities. That volume control thingy in the tray is useless...

Can anyone suggest existing software that could help me? or can someone write a wee bit of code that might allow me to keep my hair for another couple of years.

Thanks in advance,
al


Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 812
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #1 on: April 23, 2007, 03:55:56 PM »
hi aljhenry,

If I understand what you write correctly you have three different sound devices. If so, then maybe I can help. You can switch between audio devices in Windows XP here:
control panel > sound and audio device properties > audio > default device
a.png
Any application running before you change the device (like a browser) must usually be closed and restarted for the change to take effect on its audio. So the process would each time be:
1. change device
2. restart/start the application you want to play the sound from

My stationary home computer has two audio devices that I switch between daily.  I wrote a script in AHK (autohotkey.com) to speed up the switching. Since the script includes the device names on my particular system, it must be modified a bit to work on your system. The script changes the default device by changing a registry key:
HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback

Here's the core of my script:
Code: [Select]
#SingleInstance force
dev1 = Realtek AC97 Audio
dev2 = C-Media USB Headphone Set%A_Space%%A_Space%
RegRead, x, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback
If x = %dev1%
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %dev2%
TrayTip, ,%dev2%, 2,
}
else
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %dev1%
TrayTip, ,%dev1%, 2,
}
sleep 2000
If you have 3 audio devices, it could in your case look something like this:
Code: [Select]
#SingleInstance force
dev1 = name-of-device-1
dev2 = name-of-device-2
dev3 = name-of-device-3
RegRead, x, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback
If x = %dev1%
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %dev2%
TrayTip, ,%dev2%, 2,
}
if x = %dev2%
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %dev3%
TrayTip, ,%dev3%, 2,
}
if x = %dev3%
{
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %dev1%
TrayTip, ,%dev1%, 2,
}
sleep 2000
Where you should replace "name-of-device-1" and so on with the name of your audio devices as they are displayed in the sound and audio device properties. Be sure to check if there are spaces at the end of the device names! If there are spaces, add "%A_Space%" (without the quotes) in the AHK script for each space. For example, one of my audio devices is called "C-Media USB Headphone Set  " in the audio device properties and in the registry. Therefore, I have "C-Media USB Headphone Set%A_Space%%A_Space%" in the code above (again, without the quotes).

You then put the script file on the desktop and doubleclick to switch audio device.

Was this of any help?
« Last Edit: April 23, 2007, 04:00:20 PM by Nod5 »

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,219
    • View Profile
    • Coding Snacks by Lanux128
    • Donate to Member
Re: Audio output device manager
« Reply #2 on: April 23, 2007, 09:22:47 PM »
there was a similar request here: DONE: A shortcut/hotkey to switch between audio devices?

maybe it will help you.. :)

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 812
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #3 on: April 24, 2007, 07:28:59 AM »
lanux128, ok I hadn't seen that thread. This means aljhenry now has two script solutions to choose between. :Thmbsup: An advantage with the script above is that no audio device properties window pops up.

Come to think of it, one way to improve both scripts would be to somehow bypass the need to setup device name(s) manually in the script. When I do a quick search in the registry I find my devices listed here:

[HKEY_CURRENT_USER\Software\Microsoft\ActiveMovie\devenum\{33D9A762-90C8-11D0-BD43-00A0C911CE86}]
like this:
[HKEY_CURRENT_USER\Software\Microsoft\ActiveMovie\devenum\{33D9A762-90C8-11D0-BD43-00A0C911CE86}\C-Media USB Headphone Set  ]
"FriendlyName"="C-Media USB Headphone Set  "
[HKEY_CURRENT_USER\Software\Microsoft\ActiveMovie\devenum\{33D9A762-90C8-11D0-BD43-00A0C911CE86}\Realtek AC97 Audio]
"FriendlyName"="Realtek AC97 Audio"

Does anyone know if that location is the same for all XP installs? If so, then it would be easy to write a script that automatically grabs the names of all audio devices and then switches between them.

edit: I also find them here:
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control\C-Media USB Headphone Set  ]
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control\Realtek AC97 Audio]


edit2:
Ok, I just put this together. Works fine on my XP system but note that it relies on the fact that my audio device names are listed in the registry at the last location noted above. It would be great if someone could quickly check if that registry location lists audio device names on his/her PC too.

Code: [Select]
#SingleInstance force
AutoTrim, Off
;________GET AUDIO DEVICE NAMES INTO ARRAY________________
xcount = 1
Loop, HKEY_CURRENT_USER , Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control,2,0
{
if A_LoopRegName = Options                 ;ignore subkey "Options"
 continue
dev%xcount% = %A_LoopRegName%     ;put audio device name in array
xcount += 1
}
xcount -= 1

;________GET CURRENT AUDIO DEVICE NAME____________________
RegRead, x, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback

;________LOOP OVER ARRAY. IF MATCH, SWITCH TO NEXT________
Loop, %xcount%
{
if dev%A_index% != %x%                ;not match current device?
 continue
xc := A_index + 1
if xc > %xcount%
xc = 1
xnew := dev%xc%                           ;name of new device
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %xnew%
TrayTip, ,%xnew%, 2,
break
}
sleep 2000
« Last Edit: April 24, 2007, 01:27:25 PM by Nod5 »

lanux128

  • Global Moderator
  • Joined in 2005
  • *****
  • Posts: 6,219
    • View Profile
    • Coding Snacks by Lanux128
    • Donate to Member
Re: Audio output device manager
« Reply #4 on: April 24, 2007, 09:40:28 PM »
Nod5, actually your solution is more elegant.. :up: the reason i linked the other thread is just to highlight that this feature is much needed.. :) btw, how do you change the output device?

skrommel

  • Fastest code in the west
  • Developer
  • Joined in 2005
  • ***
  • Posts: 886
    • View Profile
    • 1 Hour Software by skrommel
    • Donate to Member
Re: Audio output device manager
« Reply #5 on: April 25, 2007, 01:31:14 AM »
 :) But you would still have to restart the already running programs, wouldn't you? What is needed is a virtual soundcard.

Skrommel
Please stop by my site at  1 Hour Software by skrommel  for downloads and more info.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 812
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #6 on: April 25, 2007, 02:44:16 AM »
lanux128,
"btw, how do you change the output device?"
Not sure what you mean here. This line in the script does it specifically:
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %xnew%
After you change that (by just running the script), windows uses the specified device as default.
Maybe you meant recording device? If so, then there's a registry key that I think will work similarly (though I haven't tried it):
[HKEY_CURRENT_USER\Software\Microsoft\Multimedia\Sound Mapper]
"Record"="C-Media USB Headphone Set  "


skrommel, yes sadly the running programs must be restarted to be affected by the change. I've seen some programs that bypass the default device setting and choose output device on the fly but I don't know how to implement that in a script. One idea though: the trial for Virtual Audio Cable ( http://software.muzy...ng/vac.html#download ) includes the small tool audiorepeater.exe that can virtually sent audio from one device to another. Maybe a script could utilize that.
« Last Edit: April 25, 2007, 02:54:47 AM by Nod5 »

zYx

  • Participant
  • Joined in 2008
  • *
  • default avatar
  • Posts: 2
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #7 on: December 04, 2008, 05:44:46 AM »
Hi,

is it possible to do it in vista?

Thanks

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 812
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #8 on: January 07, 2009, 10:10:42 AM »
zYx, did you try my AHK script above? I don't have Vista and so can't check if it works there (please post feedback here if you try it!)

In this ( http://www.donationc....msg144877#msg144877 ) sibling thread an autoit script was posted that explicitly works in Vista so another alternative is to try that.


superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,031
  • Is your software in my list?
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #9 on: January 07, 2009, 10:28:28 AM »
There's a freeware thing out there for this.  Let me try to remember and I'll post back.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,031
  • Is your software in my list?
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #10 on: January 07, 2009, 10:33:22 AM »
Here you go:

calvindienern

  • Participant
  • Joined in 2009
  • *
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #11 on: January 10, 2009, 11:02:58 AM »
Hi Nod5, tried your second script right out of the box and worked first time! thanks heaps.

I checked the reg settings, my hive has the following:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control\Logitech USB Headset
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control\Realtek HD Audio output
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control\Options

but guessing the Options key is ignored.

Thanks for your help!

edit whoops, didn't see
Quote
if A_LoopRegName = Options                 ;ignore subkey "Options" in the code
. makes sense now
« Last Edit: January 10, 2009, 11:10:29 AM by calvindienern »

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 812
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #12 on: January 13, 2009, 02:36:27 PM »
@calvindienern: Great that it works for you. I use the script daily myself.

But even better would be to get something like pulseaudio working so that we can change audio output on the fly, with no application restarts needed (see my failed attempt to get that up and running in this thread: http://www.donationc...ex.php?topic=14100.0 )

elchabacupra

  • Participant
  • Joined in 2009
  • *
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #13 on: February 07, 2009, 05:55:10 PM »
@Nod5,



Come to think of it, one way to improve both scripts would be to somehow bypass the need to setup device name(s) manually in the script...

edit2:
Ok, I just put this together. Works fine on my XP system but note that it relies on the fact that my audio device names are listed in the registry at the last location noted above. It would be great if someone could quickly check if that registry location lists audio device names on his/her PC too.

Code: [Select]
#SingleInstance force
AutoTrim, Off
;________GET AUDIO DEVICE NAMES INTO ARRAY________________
xcount = 1
Loop, HKEY_CURRENT_USER , Software\Microsoft\Windows\CurrentVersion\Applets\Volume Control,2,0
{
if A_LoopRegName = Options                 ;ignore subkey "Options"
 continue
dev%xcount% = %A_LoopRegName%     ;put audio device name in array
xcount += 1
}
xcount -= 1

;________GET CURRENT AUDIO DEVICE NAME____________________
RegRead, x, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback

;________LOOP OVER ARRAY. IF MATCH, SWITCH TO NEXT________
Loop, %xcount%
{
if dev%A_index% != %x%                ;not match current device?
 continue
xc := A_index + 1
if xc > %xcount%
xc = 1
xnew := dev%xc%                           ;name of new device
RegWrite, REG_SZ, HKEY_CURRENT_USER, Software\Microsoft\Multimedia\Sound Mapper, Playback, %xnew%
TrayTip, ,%xnew%, 2,
break
}
sleep 2000

I have been trawling the interweb for a while now to find exactly this kind of fix, I thought I should at the very least say this works on my XP SP2 system and I'm going to attempt the same thing on Windows 7 Build 7000, just for kicks.

Nod5

  • Supporting Member
  • Joined in 2006
  • **
  • Posts: 812
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #14 on: February 08, 2009, 07:08:38 AM »
I have been trawling the interweb for a while now to find exactly this kind of fix, I thought I should at the very least say this works on my XP SP2 system and I'm going to attempt the same thing on Windows 7 Build 7000, just for kicks.
Hi and welcome to DC!  :) Great that it works. Let us know how it goes with W7.

superboyac

  • Charter Member
  • Joined in 2005
  • ***
  • Posts: 6,031
  • Is your software in my list?
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #15 on: February 08, 2009, 02:46:26 PM »
I have a feeling you missed my link in this thread to the freeware that already exists for this sort of thing:
Go here

or maybe you did see it but it's not what you were looking for.

djlightbulb

  • Participant
  • Joined in 2009
  • *
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #16 on: April 26, 2009, 10:21:22 AM »
Cheers for  the link Superboy, that was exactly what I was looking for when I googled this thread, however it doesn't seem to work in Vista, so I might have to go with the reg edit switch...


mazzzzz

  • Participant
  • Joined in 2009
  • *
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
Re: Audio output device manager
« Reply #17 on: June 23, 2009, 11:18:05 PM »
thanks for the help on this topic, based off the registry information above I created a simple program (this program is based off the .net framework meaning you need the .net run time to run this program)...
I figured I would post it up for any other XP users who needed it.
http://mazzzzz.uuuq....hangeAudioDevice.exe