[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
    6,787
    10,357
    210
    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...
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. jellybelly

    jellybelly MDL Member

    Oct 30, 2009
    149
    28
    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.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  4. Dos_Probie

    Dos_Probie MDL Senior Member

    Jul 18, 2012
    250
    84
    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
    2
    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
    865
    447
    30
    alternative: use nircmd
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  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!