# SoundSet

改变音频设备的多种设置 (主静音, 主音量, 等)

SoundSet, NewSetting [, ComponentType, ControlType, DeviceNumber]

#### 参数

NewSetting | 从 -100 到 100 (包含的)之间的百分率数字 (它可以是一个浮点数或 表达式). 如果数值以加号或者减号开头, 当前的音量等级 将往上或者往下调指示的数值. 否则, 音量将明确地设置为 NewSetting 指示的等级. 对于只有两种可能的设置的 控制类型 而言 -- 即 ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, and BASSBOOST -- 任何正数都将开启设置, 而 0 则将关闭. 然而, 如果数值以加号或者减号开头, 设置将被切换 (设置为和当前状态相反).
ComponentType | 如果省略或为空, 默认值为单词 MASTER. 否则, 它可以是下列单词的其中一个: MASTER (与 SPEAKERS 含义相同), DIGITAL, LINE, MICROPHONE, SYNTH, CD, TELEPHONE, PCSPEAKER, WAVE, AUX, ANALOG, HEADPHONES, 或 N/A. 如果音频设备缺少指定的 ComponentType/组件类型, ErrorLevel 将表明有问题. 在某些混音器中标为 Auxiliary 的组件可能需要作为 ANALOG 而不是 AUX 进行访问. 如果一个设备含有同种 组件类型 的多个实例(例如两种类型的 LINE), 通常首个包含播放设置, 第二个包含录制设置.要访问首个实例外的其他实例, 在该参数后附加一个冒号和数字.例如: Analog:2 表示 analog 组件的第二个实例.
ControlType | 如果省略或为空, 默认值为 VOLUME. 否则, 它可以是下列单词的其中一个: VOLUME (或 VOL), ONOFF, MUTE, MONO, LOUDNESS, STEREOENH, BASSBOOST, PAN, QSOUNDPAN, BASS, TREBLE, EQUALIZER, 或者是有效的控制器类型的数字 (请看 声卡分析脚本).如果指定的 组件类型 缺少指定的 控制类型, ErrorLevel 将表明有问题.
DeviceNumber | 如果省略此参数, 默认值为 1 (第一个音频设备), 通常是系统默认的录制和播放设备.可以通过指定一个大于 1 的数字来操作其他的音频设备.此参数可以是一个 表达式.

#### ErrorLevel

如果命令成功执行 ErrorLevel 被设置为 0.否则它被设置为下列短语的其中一个:

Invalid Control Type or Component Type
Can't Open Specified Mixer
Mixer Doesn't Support This Component Type
Mixer Doesn't Have That Many of That Component Type
Component Doesn't Support This Control Type
Can't Get Current Setting
Can't Change Setting

#### 备注

在 Windows Vista 或更高版本的系统上, SoundSet 和 SoundGet 命令仅对脚本自己有效 (此问题可能会在未来的版本中解决). 至少有两种方法可以绕弯解决这个问题:

1) 在 "AutoHotkey.exe" (或 已编译脚本)文件的属性对话框中, 改变兼容性设置为 "Windows XP".

2) 使用发送音量控制键的脚本来改变整个系统的主音量. 例如:

    Send {Volume_Up}  ; Raise the master volume by 1 interval (typically 5%).
    Send {Volume_Down 3}  ; Lower the master volume by 3 intervals.
    Send {Volume_Mute}  ; Mute/unmute the master volume.

为了发现安装在系统上的音频设备 (混音器) 的功能 -- 例如可用的组件类型和控制类型 -- 请运行 声卡分析脚本.

当 SoundSet 命令改变组件的音量时, 该组件的所有声道 (例如左和右) 都被设置为相同的等级. 换句话说, 任何原来的不平衡的声道设置会丢失. 使用 SoundSetWaveVolume 命令设置 WAVE 组件可以避免此问题, 它在改变音量等级时会尝试维持原有的声道平衡.

使用 SoundGet 命令可以获取一个设置的当前数值.

#### 相关

SoundGet, SoundGetWaveVolume, SoundSetWaveVolume, SoundPlay

#### 示例

    ; BASIC EXAMPLES:
    SoundSet, 50  ; Set the master volume to 50%
    SoundSet +10  ; Increase master volume by 10%
    SoundSet -10  ; Decrease master volume by 10%
    SoundSet, 1, Microphone, mute  ; mute the microphone
    SoundSet, +1, , mute  ; Toggle the master mute (set it to the opposite state)
    SoundSet, +20, Master, bass  ; Increase bass level by 20%.
    if ErrorLevel
        MsgBox, The BASS setting is not supported for MASTER.

?

    ; SOUNDCARD ANALYSIS
    ; Use the following script to discover your soundcard's capabilities (component types and control types).
    ; It displays the results in a simple ListView.

    SetBatchLines -1
    SplashTextOn,,, Gathering Soundcard Info...

    ; Most of the pure numbers below probably don't exist in any mixer, but they're queried for completeness.
    ; The numbers correspond to the following items (in order): CUSTOM, BOOLEANMETER, SIGNEDMETER, PEAKMETER,
    ; UNSIGNEDMETER, BOOLEAN, BUTTON, DECIBELS, SIGNED, UNSIGNED, PERCENT, SLIDER, FADER, SINGLESELECT, MUX,
    ; MULTIPLESELECT, MIXER, MICROTIME, MILLITIME
    ControlTypes = VOLUME,ONOFF,MUTE,MONO,LOUDNESS,STEREOENH,BASSBOOST,PAN,QSOUNDPAN,BASS,TREBLE,EQUALIZER,0x00000000, 0x10010000,0x10020000,0x10020001,0x10030000,0x20010000,0x21010000,0x30040000,0x30020000,0x30030000,0x30050000,0x40020000,0x50030000,0x70010000,0x70010001,0x71010000,0x71010001,0x60030000,0x61030000

    ComponentTypes = MASTER,HEADPHONES,DIGITAL,LINE,MICROPHONE,SYNTH,CD,TELEPHONE,PCSPEAKER,WAVE,AUX,ANALOG,N/A

    ; Create a ListView and prepare for the main loop:
    Gui, Add, Listview, w400 h400 vMyListView, Component Type|Control Type|Setting|Mixer
    LV_ModifyCol(4, "Integer")
    SetFormat, Float, 0.2  ; Limit number of decimal places in percentages to two.

    Loop  ; For each mixer number that exists in the system, query its capabilities.
    {
        CurrMixer := A_Index
        SoundGet, Setting,,, %CurrMixer%
        if ErrorLevel = Can't Open Specified Mixer  ; Any error other than this indicates that the mixer exists.
            break
        ; For each component type that exists in this mixer, query its instances and control types:
        Loop, parse, ComponentTypes, `,
        {
            CurrComponent := A_LoopField
            ; First check if this component type even exists in the mixer:
            SoundGet, Setting, %CurrComponent%,, %CurrMixer%
            if ErrorLevel = Mixer Doesn't Support This Component Type
                continue  ; Start a new iteration to move on to the next component type.
            Loop  ; For each instance of this component type, query its control types.
            {
                CurrInstance := A_Index
                ; First check if this instance of this instance even exists in the mixer:
                SoundGet, Setting, %CurrComponent%:%CurrInstance%,, %CurrMixer%
                ; Checking for both of the following errors allows this script to run on older versions:
                if ErrorLevel in Mixer Doesn't Have That Many of That Component Type,Invalid Control Type or Component Type
                    break  ; No more instances of this component type.
                ; Get the current setting of each control type that exists in this instance of this component:
                Loop, parse, ControlTypes, `,
                {
                    CurrControl := A_LoopField
                    SoundGet, Setting, %CurrComponent%:%CurrInstance%, %CurrControl%, %CurrMixer%
                    ; Checking for both of the following errors allows this script to run on older versions:
                    if ErrorLevel in Component Doesn't Support This Control Type,Invalid Control Type or Component Type
                        continue
                    if ErrorLevel  ; Some other error, which is unexpected so show it in the results.
                        Setting := ErrorLevel
                    ComponentString := CurrComponent
                    if CurrInstance > 1
                        ComponentString = %ComponentString%:%CurrInstance%
                    LV_Add("", ComponentString, CurrControl, Setting, CurrMixer)
                }  ; For each control type.
            }  ; For each component instance.
        }  ; For each component type.
    }  ; For each mixer.

    Loop % LV_GetCount("Col")  ; Auto-size each column to fit its contents.
        LV_ModifyCol(A_Index, "AutoHdr")

    SplashTextOff
    Gui, Show
    return

    GuiClose:
    ExitApp