Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Requires AutoHotkey v2.0
- ; This is a simple AutoHotkey v2.0 tray application to change
- ; spatial audio formats, default formats, exclusivity and speaker
- ; configurations. It also has links to various connected applications.
- ;
- ; Modified the original ahk script spatial-audio-switcher-1.0.1
- ; with permission to control mute settings while paring down
- ; the original code to ONLY control DOLBY ATMOS/DOLBY ACCESS FOR HEADPHONES
- ; because that's all I use. (Removed Sonic & DTS). Default settings
- ; are basically Spatial Audio On, 7.1 surround, 24 bit, unmuted.
- ;
- ; Why mute/unmute? Because Windows 11 randomly mutes my sound on
- ; a system level that I have to drill down into deep settings to undo.
- ;
- ; IMPORTANT: To successfully launch this script you have to make or rename
- ; an icon file (.ico) you want to use for DOLBY ACCESS FOR HEADPHONES
- ; an add it to the spatial-audio-switcher-1.0.1 Icons folder.
- ; It must be named dah.ico or look for that in this script and
- ; change it to the .ico file of your choice.
- ;
- ; This very simple tray application wouldn't be possible without
- ; awesome applications of Nir Sofer, Chris Mallet and others.
- ; So all thanks should go to them.
- ;
- ;
- ; SoundVolumeCommandLine console application from NirSoft is
- ; needed to control audio device. Download it and put it inside
- ; Resources directory.
- ; https://www.nirsoft.net/utils/sound_volume_command_line.html
- ;
- ; SoundVolumeView is the GUI version of SoundVolumeCommandLine.
- ; The scripts also provides a link to open it. Download it and put
- ; it inside Resources directory. But it is not necessary to use the script.
- ; https://www.nirsoft.net/utils/sound_volume_view.html
- ;
- ; If the script runs again, skip the dialog box and replace the old instance.
- #SingleInstance Force
- ; Prevents the script from exiting automatically when its last
- ; thread completes, allowing it to stay running in an idle state.
- Persistent
- ; Set default audio device to non-spatial sound, default
- ; speaker configuration to stereo, default format to 16 Bit 44100 Hz
- ; and don't allow applications to take exclusive control of the device.
- ; Change the defaults as needed, you can learn about speaker configurations from here:
- ; https://learn.microsoft.com/en-us/windows-hardware/drivers/audio/mapping-stream-formats-to-speaker-configurations
- Run "Resources\svcl.exe /SetSpatial `"DefaultRenderDevice`" `"Dolby Atmos for Home Theater`"", , "Hide"
- Run "Resources\svcl.exe /SetSpeakersConfig `"DefaultRenderDevice`" 0x63f 0x63f 0x63f", , "Hide"
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 24 192000", , "Hide"
- Run "Resources\svcl.exe /SetAllowExclusive `"DefaultRenderDevice`" 0", , "Hide"
- ; We are going to use two main tray menus. One simple and
- ; quick one, and one with more options. Let us create them.
- ; This is the detailed tray menu. This will open with a right click
- ; to the tray icon. We are also going to set its default icon and
- ; delete AutoHotkey's default tray items.
- Tray := A_TrayMenu
- TraySetIcon "Icons\icon.ico"
- Tray.Delete
- ; This one is the simple menu to change the spatial audio
- ; formats, it will open with a left click to the tray icon.
- SpatialMenu := Menu()
- ; Tooltip text, which is displayed when the mouse hovers over the tray icon.
- A_IconTip := "Spatial Audio Switcher"
- ; Now, we will create the submenus we are going to be using.
- ; This one is for the detailed tray menu. It will show a list
- ; of the spatial audio formats that can be selected.
- Select := Menu()
- ; This will create a submenu to open sound settings.
- ; This is for the detailed tray menu.
- Settings := Menu()
- ; This will create a submenu to control exclusivity.
- ; This is for the detailed tray menu.
- Exclusivity := Menu()
- ; This will create a submenu for the detailed tray menu to change default format of the device.
- ; I have only added 16 bit 44100 Hz, 16 bit 48000 Hz, 16 bit 96000 Hz, 16 bit 192000 Hz,
- ; 24 bit 44100 Hz, 24 bit 48000 Hz, 24 bit 96000 Hz, 24 bit 192000 Hz.
- DefaultFormat := Menu()
- ; Now we will create a sub-menu to control speaker configurations
- ; between Stereo, 5.1 and 7.1. This will stay in both tray menus.
- Configuration := Menu()
- ; Finally we will create a submenu to open spatial audio apps,
- ; Dolby Access and DTS Sound Unbound. This will only stay within
- ; the simple tray menu.
- SpatialApps := Menu()
- ; Now, let's define the functions we are going to use.
- ; First, an empty function.
- Empty(*)
- {
- }
- ; Function to call the simple tray menu. This is going to be the default function.
- Spatial(*)
- {
- SpatialMenu.Show
- }
- ; Function to disable spatial audio.
- Disable(*)
- {
- Run "Resources\svcl.exe /SetSpatial `"DefaultRenderDevice`" `"`"", , "Hide"
- TraySetIcon "Icons\icon.ico"
- Tray.Rename "1&", "Disabled"
- Tray.SetIcon "Disabled", ""
- Tray.Add "Disabled", Empty
- Tray.Disable "&Disable Spatial Audio"
- SpatialMenu.Disable "&Disable Spatial Audio"
- }
- ; Function to enable Dolby Atmos for Home Theater.
- DolbyAtmosEnable(*)
- {
- Run "Resources\svcl.exe /SetSpatial `"DefaultRenderDevice`" `"Dolby Atmos for Home Theater`"", , "Hide"
- TraySetIcon "Icons\dolby.ico"
- Tray.Enable "&Disable Spatial Audio"
- SpatialMenu.Enable "&Disable Spatial Audio"
- Tray.Enable "1&"
- Tray.Rename "1&", "&Dolby Atmos for Home Theater"
- Tray.SetIcon "&Dolby Atmos for Home Theater", "Icons\dolby.ico"
- Tray.Add "&Dolby Atmos for Home Theater", DolbyAtmos
- }
- ; Function to enable Dolby Atmos for Headphones.
- DolbyAccessEnable(*)
- {
- Run "Resources\svcl.exe /SetSpatial `"DefaultRenderDevice`" `"Dolby Atmos`"", , "Hide"
- TraySetIcon "Icons\dah.ico"
- Tray.Enable "&Disable Spatial Audio"
- SpatialMenu.Enable "&Disable Spatial Audio"
- Tray.Enable "1&"
- Tray.Rename "1&", "&Dolby Access for Headphones"
- Tray.SetIcon "&Dolby Access for Headphones", "Icons\dah.ico"
- Tray.Add "&Dolby Access for Headphones", DolbyAccess
- }
- ; Function to start Unmuted
- StartUnmuted(*)
- {
- Run "Resources\svcl.exe /Unmute `"DefaultRenderDevice`""
- MuteMenu.Check "Unmuted"
- MuteMenu.Uncheck "Muted"
- MuteMenu2.Check "Unmuted"
- MuteMenu2.Uncheck "Muted"
- }
- ; Function to run Dolby Access.
- DolbyAtmos(*)
- {
- Run "explorer.exe shell:appsFolder\DolbyLaboratories.DolbyAccess_rz1tebttyb220!App"
- }
- ; Function to run Dolby Access.
- DolbyAccess(*)
- {
- Run "explorer.exe shell:appsFolder\DolbyLaboratories.DolbyAccess_rz1tebttyb220!App"
- }
- ; Function to run SoundVolumeView, our advanced sound device manager.
- Advanced(*)
- {
- Run "Resources\SoundVolumeView.exe"
- }
- ; Function to open Windows' sound settings.
- Modern(*)
- {
- Run "ms-settings:sound"
- }
- ; Function to open Windows' traditional sound settings.
- Traditional(*)
- {
- Run "control mmsys.cpl sounds"
- }
- ; Function to open Windows' application volume mixer.
- Volume(*)
- {
- Run "ms-settings:apps-volume"
- }
- ; Function to allow applications to take exclusive control of the default device .
- Exclusive(*)
- {
- Run "Resources\svcl.exe /SetAllowExclusive `"DefaultRenderDevice`" 1", , "Hide"
- Exclusivity.Check "&Exclusive"
- Exclusivity.Uncheck "&Not Exclusive"
- }
- ; Function to not allow applications to take exclusive control of default device .
- NonExclusive(*)
- {
- Run "Resources\svcl.exe /SetAllowExclusive `"DefaultRenderDevice`" 0", , "Hide"
- Exclusivity.Uncheck "&Exclusive"
- Exclusivity.Check "&Not Exclusive"
- }
- ; Function to set the default speaker configuration to stereo.
- Stereo(*)
- {
- Run "Resources\svcl.exe /SetSpeakersConfig `"DefaultRenderDevice`" 0x3 0x3 0x3", , "Hide"
- Configuration.Check "&Stereo"
- Configuration.Uncheck "&Five-point One"
- Configuration.Uncheck "S&even-point One"
- }
- ; Function to set the default speaker configuration to 5.1.
- FivePointOne(*)
- {
- Run "Resources\svcl.exe /SetSpeakersConfig `"DefaultRenderDevice`" 0x3f 0x3f 0x3f", , "Hide"
- Configuration.Uncheck "&Stereo"
- Configuration.Check "&Five-point One"
- Configuration.Uncheck "S&even-point One"
- }
- ; Function to set the default speaker configuration to 7.1.
- SevenPointOne(*)
- {
- Run "Resources\svcl.exe /SetSpeakersConfig `"DefaultRenderDevice`" 0x63f 0x63f 0x63f", , "Hide"
- Configuration.Uncheck "&Stereo"
- Configuration.Uncheck "&Five-point One"
- Configuration.Check "S&even-point One"
- }
- ; Function to set the default format to 16 bit, 44100 Hz.
- df1644(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 16 44100", , "Hide"
- DefaultFormat.Check "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 16 bit, 48000 Hz.
- df1648(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 16 48000", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Check "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 16 bit, 96000 Hz.
- df1696(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 16 96000", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Check "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 16 bit, 192000 Hz.
- df16192(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 16 192000", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Check "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 24 bit, 44100 Hz.
- df2444(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 24 44100", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Check "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 24 bit, 48000 Hz.
- df2448(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 24 48000", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Check "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 24 bit, 96000 Hz.
- df2496(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 24 96000", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Check "24 Bit, 96000 Hz"
- DefaultFormat.Uncheck "24 Bit, 192000 Hz"
- }
- ; Function to set the default format to 24 bit, 192000 Hz.
- df24192(*)
- {
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 24 192000", , "Hide"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Check "24 Bit, 192000 Hz"
- }
- ; Function to reload the Spatial Audio Switcher.
- ; It loads the default settings.
- Restart(*)
- {
- Reload
- }
- ; Function to exit the Spatial Audio Switcher.
- ; It loads the default settings first.
- Exit(*)
- {
- Run "Resources\svcl.exe /SetSpatial `"DefaultRenderDevice`" `"Dolby Atmos for Home Theater`"", , "Hide"
- Run "Resources\svcl.exe /SetSpeakersConfig `"DefaultRenderDevice`" 0x63f 0x63f 0x63f", , "Hide"
- Run "Resources\svcl.exe /SetDefaultFormat `"DefaultRenderDevice`" 24 192000", , "Hide"
- Run "Resources\svcl.exe /SetAllowExclusive `"DefaultRenderDevice`" 0", , "Hide"
- Run "Resources\svcl.exe /Unmute `"DefaultRenderDevice`""
- Sleep 0
- ExitApp
- }
- ; Function to mute audio and update checkmark.
- MuteAudio(*)
- {
- Run "Resources\svcl.exe /Mute `"DefaultRenderDevice`""
- MuteMenu.Check "Muted"
- MuteMenu.Uncheck "Unmuted"
- MuteMenu2.Check "Muted"
- MuteMenu2.Uncheck "Unmuted"
- }
- ; Function to unmute audio and update checkmark.
- UnmuteAudio(*)
- {
- Run "Resources\svcl.exe /Unmute `"DefaultRenderDevice`""
- MuteMenu.Uncheck "Muted"
- MuteMenu.Check "Unmuted"
- MuteMenu2.Uncheck "Muted"
- MuteMenu2.Check "Unmuted"
- }
- ; Now we will populate the menus.
- ; First the detailed tray menu. This will open with a right click on the tray icon.
- ; First is going to show the current state of spatial audio and change accordingly.
- ; You can open the related app by clicking it.
- Tray.Add "Disabled", Empty
- ; Second will be an option to disable spatial audio. Shall be greyed-out
- ; when it is already disabled.
- Tray.Add "&Disable Spatial Audio", Disable
- Tray.SetIcon "&Disable Spatial Audio", "Icons\disable.ico"
- Tray.Disable "&Disable Spatial Audio"
- ; A seperator.
- Tray.Add
- ; Select submenu.
- Tray.Add "&Spatial Audio", Select
- Select.Add "&Dolby Atmos for Home Theater", DolbyAtmosEnable
- Select.SetIcon "&Dolby Atmos for Home Theater", "Icons\dolby.ico"
- Select.Add "&Dolby Access for Headphones", DolbyAccessEnable
- Select.SetIcon "&Dolby Access for Headphones", "Icons\dah.ico"
- ; Settings submenu.
- Tray.Add "&Audio Settings", Settings
- Settings.Add "&Advanced", Advanced
- Settings.Add "&Modern", Modern
- Settings.Add "&Traditional", Traditional
- ; Mute status menu
- MuteMenu := Menu()
- MuteMenu.Add "Muted", MuteAudio
- MuteMenu.Add "Unmuted", UnmuteAudio
- Tray.Add "Muted Status", MuteMenu
- ; Configuration submenu.
- Tray.Add "Speaker &Configuration", Configuration
- Configuration.Add "&Stereo", Stereo
- Configuration.Add "&Five-point One", FivePointOne
- Configuration.Add "S&even-point One", SevenPointOne
- ; Default Format submenu.
- Tray.Add "Default &Format", DefaultFormat
- DefaultFormat.Add "16 Bit, 44100 Hz", df1644
- DefaultFormat.Add "16 Bit, 48000 Hz", df1648
- DefaultFormat.Add "16 Bit, 96000 Hz", df1696
- DefaultFormat.Add "16 Bit, 192000 Hz", df16192
- DefaultFormat.Add "24 Bit, 44100 Hz", df2444
- DefaultFormat.Add "24 Bit, 48000 Hz", df2448
- DefaultFormat.Add "24 Bit, 96000 Hz", df2496
- DefaultFormat.Add "24 Bit, 192000 Hz", df24192
- ; Exclusivity submenu
- Tray.Add "&Exclusivity", Exclusivity
- Exclusivity.Add "&Exclusive", Exclusive
- Exclusivity.Add "&Not Exclusive", NonExclusive
- ; Application Volume Mixer.
- Tray.Add "&Volume Mixer", Volume
- ; A seperator.
- Tray.Add
- ; An item to reload Spatial Audio Switcher
- ; and reset all settings to their default.
- Tray.Add "&Reload", Restart
- ; An item to quit Spatial Audio Switcher
- ; and reset all settings to their default.
- Tray.Add "E&xit", Exit
- ; Now the simple tray menu. This will open with a left click on the tray icon.
- ; First will be an option to disable spatial audio. Shall be greyed-out
- ; when it is already disabled.
- SpatialMenu.Add "&Disable Spatial Audio", Disable
- SpatialMenu.SetIcon "&Disable Spatial Audio", "Icons\disable.ico"
- SpatialMenu.Disable "&Disable Spatial Audio"
- ; A seperator.
- SpatialMenu.Add
- ; Now the selection between the spatial audio formats.
- SpatialMenu.Add "&Dolby Atmos for Home Theater", DolbyAtmosEnable
- SpatialMenu.SetIcon "&Dolby Atmos for Home Theater", "Icons\dolby.ico"
- SpatialMenu.Add "&Dolby Atmos for Headphones", DolbyAccessEnable
- SpatialMenu.SetIcon "&Dolby Atmos for Headphones", "Icons\dah.ico"
- ; A Seperator
- SpatialMenu.Add
- ; Speaker configuration. This is important enough to stay
- ; within the simple tray menu.
- SpatialMenu.Add "Speaker &Configuration", Configuration
- ; Shortcuts to mute status
- MuteMenu2 := Menu()
- MuteMenu2.Add "Muted", MuteAudio
- MuteMenu2.Add "Unmuted", UnmuteAudio
- SpatialMenu.Add "Muted Status", MuteMenu2
- ; Shortcuts to spatial audio applications.
- SpatialMenu.Add "&Applications", SpatialApps
- SpatialApps.Add "&Dolby Access", DolbyAtmosEnable
- SpatialApps.SetIcon "&Dolby Access", "Icons\dolby.ico"
- ; Now we will make tray menu show our default settings.
- Exclusivity.Uncheck "&Exclusive"
- Exclusivity.Check "&Not Exclusive"
- Configuration.Uncheck "&Stereo"
- Configuration.Uncheck "&Five-point One"
- Configuration.Check "S&even-point One"
- DefaultFormat.Uncheck "16 Bit, 44100 Hz"
- DefaultFormat.Uncheck "16 Bit, 48000 Hz"
- DefaultFormat.Uncheck "16 Bit, 96000 Hz"
- DefaultFormat.Uncheck "16 Bit, 192000 Hz"
- DefaultFormat.Uncheck "24 Bit, 44100 Hz"
- DefaultFormat.Uncheck "24 Bit, 48000 Hz"
- DefaultFormat.Uncheck "24 Bit, 96000 Hz"
- DefaultFormat.Check "24 Bit, 192000 Hz"
- ; Now we will make the simple tray menu the default.
- ; This is needed to open it with one left click to the tray icon.
- Tray.Add
- Tray.Add "Spatial Audio Switcher", Spatial
- Tray.Default := "Spatial Audio Switcher"
- Tray.Disable "Spatial Audio Switcher"
- Tray.ClickCount := 1
- ; Update active state to Dolby Atmos for Home Theater
- DolbyAtmosEnable()
- ; Update active state to Unmuted - addresses Windows randomly muting my devices
- StartUnmuted()
- ; Windows + Alt + S shortcut can be used to open
- ; the simple tray menu below the mouse pointer.
- #!s::SpatialMenu.Show
- ;
- ; END
- ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement