Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Vista Audio Control Functions


  • Please log in to reply
182 replies to this topic
Washburn
  • Members
  • 17 posts
  • Last active: Jan 20 2009 11:04 PM
  • Joined: 16 Dec 2008
I tested your code and I need to stick with my version since I actually have three microphones, which are used for Intercom communication. Two are Logitech, and one is the Realtek HD Audio microphone. Running your code came up with one of the Logitech microphones. I specifically want the Realtek HD Audio microphone. My methodology allows me to search through the capture devices/subunits to find the specific microphone. Also, the order of the devices could change as we add new devices, so my methodology allows me to access the specific microphone regardless of order. Thanks for your suggestion, and I appreciate your time.
My Username comes from the name of a mountain peak in Yellowstone N.P.

Question: Does a bear do its duty in the woods.
Answer: It most certainly does, as well as anywhere else it chooses.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

Running your code came up with one of the Logitech microphones. I specifically want the Realtek HD Audio microphone.

In that case, try the following:
COM_Init()
device := VA_GetDevice("Microphone[color=red] (Realtek High Definition Audio)[/color]")
if device
    MsgBox % VA_GetDeviceName(device)
else
    MsgBox no device
:roll:

Washburn
  • Members
  • 17 posts
  • Last active: Jan 20 2009 11:04 PM
  • Joined: 16 Dec 2008
That's a good refinement. I don't have to run a loop to find the device. It's alot more efficient. Thanks for your suggestion.
My Username comes from the name of a mountain peak in Yellowstone N.P.

Question: Does a bear do its duty in the woods.
Answer: It most certainly does, as well as anywhere else it chooses.

protospork
  • Members
  • 2 posts
  • Last active: Apr 02 2009 12:04 AM
  • Joined: 02 Apr 2009
I have a script using code that I adapted from someone's post on this board (I did it a month or so ago so I'm not sure exactly where I got it) that uses VA to assign f9/f10 to reduce/raise line-in volume and insert to toggle muting it.

I find it a little difficult to explain the situation, but the script itself technically works fine. My issue is that it seems to 'invent' an entirely new line-in device for itself. The line-in in windows' mixer stays functional and is the same audio as whatever AHK affects (off by a few ms, so I get an 'echo' effect), so I have to mute it and exclusively use the script's controls. My sound card only has one input port with audio feeding into it so I'm fairly positive it's not a "you're using the wrong device!" issue.

To sum up, whatever AHK is affecting doesn't show up in the volume mixer, and I'd like it to. Please help! :(

Here is my code, it is a mess :\
HotKey, f10, vol_MasterUp
HotKey, f9, vol_MasterDown

COM_Init() 

Insert::
;SoundSet, +1, microphone, mute
VA_SetMute(!VA_GetMute("Microphone"),"Microphone") 
return

vol_MasterUp:
vol_tmp := VA_GetVolume("Microphone")
vol_Master := (vol_tmp + 5)
VA_SetVolume(vol_Master, "Microphone")
return

vol_MasterDown:
vol_tmp := VA_GetVolume("Microphone")
vol_Master := (vol_tmp - 5)
VA_SetVolume(vol_Master, "Microphone")
return
It's pretty obvious I have no idea what I'm doing. I was a newb at normal AHK stuff, so these VA functions totally threw me for a loop. The above code is a weird hybrid of something I found on this board (probably this thread, I dunno) and a similar script I was using in XP, thrown together using pure guess-and-check.

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
VA controls "subunits" of your audio device - in this case the subunit representing feedback of "Microphone" input through the default output device. It should appear on the Levels tab of your device's properties. (If that's what you meant by "windows' mixer", I'll be confused.)

Edit, cleanup:
COM_Init()
Insert::VA_SetMute(!VA_GetMute("Microphone"), "Microphone")
F10::VA_SetVolume(VA_GetVolume("Microphone") + 5, "Microphone")
F9::VA_SetVolume(VA_GetVolume("Microphone") - 5, "Microphone")


protospork
  • Members
  • 2 posts
  • Last active: Apr 02 2009 12:04 AM
  • Joined: 02 Apr 2009
Whoa, that's a hell of a cleanup :shock:

I found the slider on the 'levels' tab, where you said it would be.
By "mixer", I had meant the window you get when you right click the speaker in the systray and choose "Open Volume Mixer", but as long as I know where to change the volume on the input via mouse, I'm satisfied. It really had just confused me that whatever my script was controlling didn't seem to appear anywhere in windows' interface.

Thanks for the help, especially that rewrite. Your code makes it look a lot more like simple AHK :D

Dustin
  • Guests
  • Last active:
  • Joined: --
I hope people don't get too mad for me bringing this thread back to life. I've looked but I haven't been able to find any help.

All I want to do is mute my microphone by pressing a button. But I can't get this to work.

Here's the subunits I see.

VOLUME SUBUNITS

Speakers
Line In Volume
Aux Volume
CD Volume
Mic Volume


MUTE SUBUNITS

Master Mute
Line Mute
Aux Mute
CD Mute
Mic Mute

Here's my AHK script

COM_Init()
F11::VA_SetMute(!VA_GetMute("Mic"), "Mic")
COM_Term()

However, this seems to only disable the playback side of the mic, not the recording side. I thought maybe I could just add a 2 because of duplicate devices. SO I tried this...

F11::VA_SetMute(!VA_GetMute("Mic"), 2, "Mic")

It didn't work. So I tried this.

F11::VA_SetMute(!VA_GetMute("Mic"), 1, "Mic")

I thought that should just work as if the 1 wasn't even there and mute the playback side of my mic. But it didn't do anything.

In fact, I can't seem to mute any of the input devices, I can only mute the playback sides of all of them.

Any help would be awesome!

Dustin
  • Guests
  • Last active:
  • Joined: --
Sorry, I'm pretty new to this stuff so I don't really understand much.

With that said, I think I've solved it.

I used this line
F11::VA_SetMasterMute(!VA_GetMasterMute("capture"), "capture")

This appears to just toggle mute the default input device, exactly what I need! If there's some way I can get it to mute just the mic instead of the default input device, that would be better. But really, this is just splitting hairs and I'm just overjoyed to actually have it working!

Much thanks!

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

If there's some way I can get it to mute just the mic instead of the default input device, that would be better.

Do you mean when the microphone is not the default input device? You can use the device name (or part of it) in place of "capture". If there is ambiguity you may append ":n" to retrieve the nth matching device. This will list all available capture devices:
COM_Init()
While (dev := VA_GetDevice("capture:" A_Index))
{
    devlist .= A_Index ": " VA_GetDeviceName(dev) "`n"
    COM_Release(dev)
}
COM_Term()
MsgBox %devlist%


codex
  • Guests
  • Last active:
  • Joined: --
Hi Lexikos!

First thanks for your great library!

Could you please help me with one issue.

I enabled Stereo Mix device in Vista sound settings and I want to use it as source for recording. I want to use Autohotkey and your excelent library to mute/unmute Mic playback with a single button.
I able to controll it with Vista Audio settings in Playback devices->Playback->Speakers->Levels->Rear Pink In. But I can't figure how to do it with VA_SetMute :(.
I tried different params but it just doesn't affect mic playback volume. I can control record volume of Mic using VA_* calls but I need to change its (Rear Pink In) playback.

Here is my topology:
+ (CONNECTOR) Realtek HD Audio output : {4509F757-2D46-4637-8E62-CE7DB944F57B}
   + Master Mute : IAudioMute
      + Speakers : IAudioVolumeLevel
         + Sum
            + (CONNECTOR) 
            + Mute : IAudioMute
               + CD Audio : IAudioVolumeLevel
                  + (CONNECTOR) CD Audio
            + Mute : IAudioMute
               + Rear Green In : IAudioVolumeLevel
                  + (CONNECTOR) Rear Green In
            + Mute : IAudioMute
               + Rear Black In : IAudioVolumeLevel
                  + (CONNECTOR) Rear Black In
            + Mute : IAudioMute
               + Rear Orange In : IAudioVolumeLevel
                  + (CONNECTOR) Rear Orange In
            + Mute : IAudioMute
               + Rear Grey In : IAudioVolumeLevel
                  + (CONNECTOR) Rear Grey In
            + Mute : IAudioMute
               + Rear Pink In : IAudioVolumeLevel
                  + (CONNECTOR) Rear Pink In
            + Mute : IAudioMute
               + Front Pink In : IAudioVolumeLevel
                  + (CONNECTOR) Front Pink In
            + Mute : IAudioMute
               + Rear Blue In : IAudioVolumeLevel
                  + (CONNECTOR) Rear Blue In
            + Mute : IAudioMute
               + Front Green In : IAudioVolumeLevel
                  + (CONNECTOR) Front Green In
            + Side : IAudioVolumeLevel
               + (CONNECTOR) Side
            + Center : IAudioVolumeLevel
               + (CONNECTOR) Center
            + Subwoofer : IAudioVolumeLevel
               + (CONNECTOR) Subwoofer
            + Rear : IAudioVolumeLevel
               + (CONNECTOR) Rear
            + Front : IAudioVolumeLevel
               + (CONNECTOR) Front


VOLUME SUBUNITS

Speakers
CD Audio
Rear Green In
Rear Black In
Rear Orange In
Rear Grey In
Rear Pink In
Front Pink In
Rear Blue In
Front Green In
Side
Center
Subwoofer
Rear
Front


MUTE SUBUNITS

Master Mute
Mute
Mute
Mute
Mute
Mute
Mute
Mute
Mute
Mute


Thank you![/code]

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

VA_SetMute ... I tried different params but it just doesn't affect mic playback volume.

Are you really trying to control volume (VA_SetVolume), or mute (VA_SetMute)?

It looks like your audio driver doesn't give unique names to the "Mute" subunits, so you would need to identify it by its number, as determined by the order it appears in the topology. On the other hand, since there is a volume subunit called "Rear Pink In", you may pass that to VA_SetVolume.
COM_Init()
VA_SetVolume(100, "Rear Pink In")
VA_SetMute(false, 6)
If that doesn't work, experiment with different numbers while watching the volume levels/mute in the "Speakers" control panel.

codex
  • Members
  • 8 posts
  • Last active: Sep 19 2009 08:48 AM
  • Joined: 27 Aug 2009
Thank you for answer!

I spent about 4 hours yesterday for that. I tried both VA_SetVolume and VA_SetMute. I tried VA_SetMute(1..10) and other Microphone:1, playback:n, capture:n, Pink Rear In, Microphone at Pink Rear In .... It doesn't affect any level unfortunately.
Maybe this (CONNECTOR) in my topology tree is problem:
+ Sum
+ (CONNECTOR)
+ Mute : IAudioMute

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006

I tried VA_SetMute(1..10)

If so, you need to read the manual. The first parameter of SetMute must be true (to mute) or false (to unmute). True and false are synonymous with 1 and 0, respectively. The second parameter is the subunit name or number.

and other Microphone:1, playback:n, capture:n,

These are all device names, not subunit names. Device names are specified in the third parameter of SetMute or fourth parameter of SetVolume. However, I suspect you need the default playback device, in which case you can omit the device parameter. Otherwise you could specify "Speakers" assuming the correct volume/mute controls can be found in "Speakers Properties".

Pink Rear In

As the tree and list of subunits you posted shows, this is a volume subunit and will not work with SetMute. It should work with SetVolume, as long as you use the correct (second) parameter (and surround it with "quote marks").

Maybe this (CONNECTOR) in my topology tree is problem:
+ Sum
+ (CONNECTOR)
+ Mute : IAudioMute

Since the somewhat outdated topolgy script is able to list the subunits, I doubt very much that is a problem.


Try this:
COM_Init()

MsgBox,
(
Please open your Speakers Properties to the Levels tab.
This script will toggle mute on and off repeatedly; while
it is doing so, watch the Levels to see which one changes.
Hold Ctrl to display the subunit number and advance to the
next subunit.  Hold Shift to quit.

Click OK to continue.
)

Loop {
    n_device := "playback:" A_Index
    if VA_GetMasterMute(n_device) = ""
        break
    Loop {
        n_subunit := A_Index
        if VA_GetMute(n_subunit, n_device) = ""
            break
        Loop {
            if GetKeyState("Ctrl")
                break
            if GetKeyState("Shift")
                ExitApp
            VA_SetMute(not VA_GetMute(n_subunit, n_device), n_subunit, n_device)
            Sleep 500
        }
        MsgBox Device: %n_device%, Subunit: %n_subunit%
    }
}
MsgBox Ran out of controls.
ExitApp
On my system at least, the controls on the Levels tab are listed in the same order that VA.ahk assigns them numbers, so the first is 1, the second is 2... and so on.

Edit: Updated script. Edit2: Slight fix. It's supposed to toggle, not just mute...

codex
  • Members
  • 8 posts
  • Last active: Sep 19 2009 08:48 AM
  • Joined: 27 Aug 2009
Thanks!

Of course I used correct syntax: VA_SetMute( true, 1..10) :)
Your test script breaks at
if VA_GetMute(n_subunit, n_device) = ""
I tried VA_GetMute before and it returns empty string for any index...

BTW is there any way to enumerate all guidEventContext (which is used in IAudioMute::SetMute) to specifiy it directly then ?

Lexikos
  • Administrators
  • 9844 posts
  • AutoHotkey Foundation
  • Last active:
  • Joined: 17 Oct 2006
When I suggested VA_SetMute(false, 6), I had not counted "Master Mute". I should have said VA_SetMute(false, 7).

Your test script breaks at
if VA_GetMute(n_subunit, n_device) = ""

Do you mean it immediately breaks out of the loop and shows "Ran out of controls"? If so, the device name is probably incorrect. Try changing "Speakers" to "playback". Since you said "Playback devices->Playback->Speakers" I presumed "Speakers" was the correct device name.

Altenately, you may try the script in my previous post again. I have updated it to cycle through all playback devices.

I tried VA_GetMute before and it returns empty string for any index...

Were you specifying a device name? If so, it may be incorrect. To verify that a device name is correct, call VA_GetDevice:
COM_Init()
dev := VA_GetDevice("the-device-name-here")
if dev
    COM_Release(dev)
In any case, the script may be failing for some other reason. Ensure COM_Init() has been called, you have a functioning audio device and drivers, you have a recent version of AutoHotkey, etc. I don't know what else to suggest.

BTW is there any way to enumerate all guidEventContext (which is used in IAudioMute::SetMute) to specifiy it directly then ?

guidEventContext is completely irrelevant.

pguidEventContext

[in] Context value for the IControlChangeNotify::OnNotify method. This parameter points to an event-context GUID. If the SetMute call changes the state of the mute control, all clients that have registered IControlChangeNotify interfaces with that control receive notifications. In its implementation of the OnNotify method, a client can inspect the event-context GUID to discover whether it or another client is the source of the control-change event. If the caller supplies a NULL pointer for this parameter, the client's notification method receives a NULL context pointer.

It is much more likely that the script is failing somewhere in VA_GetDeviceSubunit.

Of course I used correct syntax: VA_SetMute( true, 1..10)
...
I tried VA_GetMute before and it returns empty string for any index...

If you need further help, please post the actual code which you've tried. Guesses will only get me so far.