[REQ] Script to enable/disable Windows built-in Loudness Equalization

Discussion in 'Scripting' started by ViwwiV, Mar 30, 2014.

  1. ViwwiV

    ViwwiV MDL Novice

    Apr 16, 2011
    4
    0
    0
    Hello,

    I was wondering if anyone could help me out with a script.

    Does anyone know how to write a .BAT or .VBS script to quickly enable/disable Windows built-in Loudness Equalization? – which is normally switched ON and OFF as we can see in this guide: hxxp://howtogeek.com/115656/3-ways-to-normalize-sound-volume-on-your-pc/

    If anyone could help me, I would be very grateful. Thanks in advance!
     
  2. murphy78

    murphy78 MDL DISM Enthusiast

    Nov 18, 2012
    7,389
    11,614
    240
    There's probably a way to do it with vbscript that just isn't documented, but from what I can tell there's a registry key:
    HKEY_LOCAL_MACHINE/SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/MMDEVICES/AUDIO/RENDER

    One of those...
    You could make a cmd script to add the loudness thing, net stop the audio service and of course net start the audio service. I'm pretty sure the reg keys are being checked when the audio service starts or you restart windows

    Sorry I don't have the exact names, but you could probably figure it out from there...
     
  3. jellybelly

    jellybelly MDL Member

    Oct 30, 2009
    159
    29
    10
    murphy is correct, that's where the setting is.. then from there it's a unique GUID key for every computer and every audio device..

    You can take a snapshot of your registry and then change the setting in volume control, then compare the active registry to the snapshot to see which key was changed, so you know for sure... or you can take a guess......

    in each GUID named key there are 2 sub keys named FxProperties and Properties, in the Properties key you will be looking for a key whose value is Speakers..... you might only have one so it would be easy to find. My PC has 2 for some reason and changing the setting only affects one of the keys..

    once you find the right key for Speakers, then you go back into the FxProperties subkey and that's where the setting is stored... it's another unique GUID label key, the value is 0 for off and 1 for on.. you can have that key open when you change the setting and then refresh the screen and see which key has changed..... then you know which to toggle

    Now the tricky part... apparently these keys are protected from change by the user... I was using Registry Workshop and my changes were denied. Changing the permissions didn't seem to work from RW either. I had to use Windows registry editor to change the permission of the key to full access for admins... then I was able to toggle the value without issue. There was no need to start/stop the audio service.. the registry change was all that was needed.

    So yes it could be done by batch script provided you have all the required keys (and would need to get the new GUID key names and values each time you reinstalled Windows), and change the permissions on the key to be able to toggle the value.

    All in all, it might not be worth the hassle.. up to you.
     
  4. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    86
    10
    toggle volume on or off

    Instead of going thru all the protected reg with correct guid, why don't you just use devcon.exe from a batch or commandline to toggle sound on and off.
    If you don't have the devcon utility you can download from Microsoft the 32/64bit versions @ http://support.microsoft.com/default.aspx?scid=kb;EN-US;Q311272
    then place your version in system32 or just run it from the desktop like so:
    Using my machine as an example you can do the following:
    1. Use the above reg file to identify the sound hardware id or from commandline Run either devcon find *> HardwareID.List.txt or devcon hwids *> HardwareID.List.txt
    2. From text file Do Ctrl+F for a search of hdaudio (mine is:HDAUDIO\FUNC_01&VEN_10EC&DEV_0269&SUBSYS_1179FC36&REV_1001\4&68B495B&0&0001: Realtek High Definition Audio
    3. Now with that info just use the DEV_0269
    Now fun part
    To toggle off volume: devcon disable *DEV_0269>nul
    To toggle back on: devcon restart *DEV_0269
    DP:D
     
  5. ViwwiV

    ViwwiV MDL Novice

    Apr 16, 2011
    4
    0
    0
    Thank you for your answers!

    I checked what changed in the registry after enabling this feature and it seems a little complicated, as you can see in the snapshots below (changing values has been highlighted).

    In HKEY_LOCAL_MACHINE/SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/MMDEVICES/AUDIO/RENDER/{xxx}/Properties:
    n4Gihv4.png

    In HKEY_LOCAL_MACHINE/SOFTWARE/MICROSOFT/WINDOWS/CURRENTVERSION/MMDEVICES/AUDIO/RENDER/{xxx}/FxProperties:
    bgW4HrH.png
     
  6. ViwwiV

    ViwwiV MDL Novice

    Apr 16, 2011
    4
    0
    0
    Thanks Dos Probie, I already know DevCon but, from what I know, it is just an utility to enable/disable a device (which is not what I want; I want to enable/disable a feature of a device: the Loudness Equalization).
     
  7. ja34blke

    ja34blke MDL Novice

    Sep 29, 2014
    1
    11
    0
    #7 ja34blke, Sep 29, 2014
    Last edited by a moderator: Apr 20, 2017
    Got something that works on my Realtek High Definition Audio Device

    OK, so this isn't a script, but it's usable in a script, and it interacts with COM, so there may be a way to convert it to a script. Since this page is high on the search results at the moment, and I couldn't find anything that could do this anywhere else, I wanted to share this somewhere others could find it. If that's a no-no, let me know.

    I've written a little utility that will toggle loudness equalization for the default multimedia device (assuming it's Realtek). This may work with other Realtek devices, but I have only tried it with my own Realtek ALC892 (10EC:0892) on 64-bit Windows 8.1, driver 6.0.1.7246, with RtkCfg64.dll available in C:\WINDOWS\system32.

    Usage: ToggleLoudnessEqualization.exe [1/on/0/off/toggle] [exit]
    This command displays the resulting status of loudness equalization on completion. Arguments are optional, and if not included, it will simply display the current status of LEQ.
    Including an "exit" parameter will cause the program to return success when LEQ is on, failure when it is off, which allows you to do something like:
    ToggleLoudnessEqualization.exe toggle exit && nircmd speak text enabled || nircmd speak text disabled
    The above command is useful in a batch file. If you have Nir Sofer's wonderful nircmd installed, that command will announce whether you've just turned Loudness Equalization on or off. Just an example usage, and the way I use it myself.
    ToggleLoudnessEqualization.exe and RTPolicyConfigClientLib.dll are the only files necessary for the application to execute.

    Source and binaries attached:
    View attachment ToggleLoudnessEqualization.zip

    Details:
    Some Realtek drivers come with DLLs that allow you to change Fx Properties and have it take effect immediately (without disabling/re-enabling the whole device). For my particular device, the relevant COM-accessible DLL is RtkCfg64.dll, RtkCfg.RtkCfgApi.1.

    If programming in .NET is your thing, you can interact with the RtkCfg COM library by creating an interop DLL for it using TlbImp -- in my case, from the Windows "v7.0A" SDK's bin folder, but other versions of TlbImp probably work. If you're targeting a version of .NET earlier than 4.0, you will need to modify tlbimp.exe.config and insert the following into the <configuration> section:
    Code:
        <startup>
            <supportedRuntime version="v2.0.50727"/>
        </startup>
    (I couldn't insert it in the typical GUI way, myself, due to it being a 64-bit library.)

    After that, the resulting DLL can be included as a reference in a C# project.
    By the way, the closest I've come to converting this to VBScript is...:
    Code:
    Set objRtk =  CreateObject("RtkCfg.RtkCfgApi.1")
    You're welcome to try to flesh that out. First step is figuring out how to get an audio device ID in VBScript...
     
  8. MKANET

    MKANET MDL Novice

    Sep 15, 2012
    3
    0
    0
    #8 MKANET, Sep 27, 2017
    Last edited: Sep 28, 2017
    Thank you!! I was investigating how to do this via PowerShell / .NET. It looks like I'll still need to make an interop dll assembly (or borrow the one supplied here) for PowerShell to do it.

    EDIT: I just tried the command. It works great!
     
  9. KNARZ

    KNARZ MDL Addicted

    Oct 9, 2012
    895
    482
    30
    alternative: use nircmd
     
  10. MKANET

    MKANET MDL Novice

    Sep 15, 2012
    3
    0
    0
    Nircmd can only control audio volume "up", "down", "mute", "mic" or switch to system audio devices; at least, last I checked. It doesn't enable/disable Realtek's dynamic audio compression in realtime.

    I'd also like to thank @ja34blke again. This really is an irreplaceable tool. Nothing else really like it. I just configured my HTPC (Kodi Media Center) to automatically use dynamic audio compress for TV; and, disable it for Movies and Music! Pretty slick!

     
  11. guide_8

    guide_8 MDL Novice

    Sep 21, 2008
    1
    0
    0
    #11 guide_8, Jul 22, 2018
    Last edited: Jul 22, 2018
    Thank you,
    I want also to to toggle the 'voice cancellation'.
    What would the source code look like?

    I tried to change the uint 'propLoudnessEqualization', from 0 to 98,000 without luck.
     
  12. ExtremelyFancyUsername

    Oct 17, 2018
    212
    70
    10
    Dude, I can't thank you enough for this. ASUS with its dogs**t SupremeFX has no loudness equalization but your little program worked. No more complaining from other people in the house that my sound is too loud!

    THANK YOU SO MUCH!
     
  13. Ahmed Anssaien

    Ahmed Anssaien MDL Novice

    Sep 26, 2019
    1
    0
    0
    #13 Ahmed Anssaien, Sep 26, 2019
    Last edited: Sep 26, 2019
    You're a god! <3 Thank you so much! I wanted to create a shortcut that toggles Sound Equalization with game shortcuts, so I wouldn't have to let my ears be fish food for Windows sound effects — they're pretty loud when it's enabled. Lol
    Now, when I launch Witcher 3: Wild Hunt, it enables SE, then it waits (/wait), and as soon as I exit the game, SE gets disabled, all thanks to your simple yet ingenious tool! Thanks again! :D I also created another shortcut with a shortcut key (CTRL + ALT + S) + a VBS line of code to run it in 'hidden' mode. I use "invisible.vbs" to run a batch script that cleans temporary files automatically, and another one that disables Windows Updates whenever it's enabled (the task runs every 1 minute).

    Example:
    Invisible.vbs contains this line of code (file location: System32):
    Code:
    CreateObject("Wscript.Shell").Run """" & WScript.Arguments(0) & """", 0, False
    Shortcut's target value:
    Code:
    %SystemRoot%\system32\wscript.exe "%systemroot%\system32\invisible.vbs" "%ProgramFiles(x86)%\CD Projekt RED\The Witcher 3 Wild Hunt\bin\x64\toggleSE.cmd" //nologo
    toggleSE.cmd:
    Code:
    @echo off
    ToggleLoudnessEqualization.exe toggle exit && nircmd speak text "Sound Equalization enabled" || nircmd speak text "Sound Equalization disabled"
    start /b /wait "" "C:\Program Files (x86)\CD Projekt RED\The Witcher 3 Wild Hunt\bin\x64\witcher3.exe"
    ToggleLoudnessEqualization.exe toggle exit && nircmd speak text "Sound Equalization enabled" || nircmd speak text "Sound Equalization disabled"
    
    Cheers!
     
  14. Ketamine581

    Ketamine581 MDL Novice

    Mar 3, 2021
    1
    0
    0

    Made an account just to try this - It worked, You are a GOD. I've been looking for something to solve this problem for so long.
    For reference, this worked on my Razer Kraken 7.1 - Even though the drivers are different than my speakers (Realtek).
     
  15. n1r

    n1r MDL Novice

    Jul 15, 2021
    1
    0
    0
    Thanks a lot. Works like a charm.
     
  16. byblo

    byblo MDL Novice

    Jun 17, 2021
    1
    0
    0
    @ja34bke: Thank you for the tool, very useful.

    It is not possible to do similar tool for main windows instead of realtek only?

    BTW, if anyone needs it, I made a systray icon frontend for the ToggleLoudnessEqualization tool, to quickly toggle the loudness equalization, but also to automatize it.
    For instance, to disable automatically on any fullscreen window like a video player or a videogame, or to enable automatically on specified windows like a web browser.

    Usage: Left click to toggle, right click to remember the setting for the currently focused window.

    Download and detailed infos: Nevermind... I cannot post the download link since this forum requires 5 posts before allowing links.. Until then, just search for my patreon page: "byblo" and you will find the tool: ToggleLoudnessEqualizationFE

    [​IMG]

    Have fun :)
     
  17. Mr.X

    Mr.X MDL Guru

    Jul 14, 2013
    8,575
    15,646
    270
    I googled you and found nothing
    Could you pm the link please
     
  18. skorpion68

    skorpion68 MDL Novice

    Mar 21, 2015
    36
    76
    0
  19. theshadowrunner

    theshadowrunner MDL Novice

    Aug 20, 2010
    11
    2
    0
    #19 theshadowrunner, Oct 4, 2022
    Last edited: Oct 4, 2022
    Great app!
    May I add a request?
    I toggle Loudness Equalization On/Off using the toggle parameter:
    Code:
    Set WshShell = CreateObject("WScript.Shell")
    WshShell.Run ("""C:\Program Files\ToggleLoudnessEqualization\ToggleLoudnessEqualization.exe""toggle"), 0
    Set WshShell = Nothing
    
    I would like to use your frontend as visual cue, maybe with some Balloon Tooltip indicating "Loudness Equalization : On or Off" , that would be displayed automatically for a second when the toggle is used.
    But currently your frontend doesn't react to my "external" toggle, so I'm not sure that's possible ?
    edit: by not react I mean the icon on your frontend doesn't change when "ToggleLoudnessEqualization.exe toggle" command line is run..[​IMG]
     
  20. theshadowrunner

    theshadowrunner MDL Novice

    Aug 20, 2010
    11
    2
    0
    So I went ahaid and did it, here it is as a simple toggle with nice bubble tooltip and icon.
    Enjoy.

    Image1.png
     

    Attached Files: