how to control enable audio enhancements with code

哲敏 陈 86 Reputation points
2021-12-20T09:23:01.86+00:00

Hi all,
is there a way to disable the microphone audio enhancements from C++ code?
When the audio enhancement function is enabled, the microphone data collected by our software will be affected, resulting in problems such as echo can not be eliminated。
So I want to know if I can get and set the status of audio enhancement from C + + code。
Here is a picture showing the position of the switch
158972-1.png

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,650 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,757 questions
Windows Hardware Performance
Windows Hardware Performance
Windows: A family of Microsoft operating systems that run across personal computers, tablets, laptops, phones, internet of things devices, self-contained mixed reality headsets, large collaboration screens, and other devices.Hardware Performance: Delivering / providing hardware or hardware systems or adjusting / adapting hardware or hardware systems.
1,622 questions
{count} vote

Accepted answer
  1. Castorix31 85,711 Reputation points
    2021-12-21T08:36:47.797+00:00

    This simplified test with IPolicyConfig to update the Store works for me (Windows 10 21H1) =>
    (I get 0, then I set to 1 and enhancements become disabled)

    IMMDeviceEnumerator* pDeviceEnumerator;
    HRESULT hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), NULL, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (LPVOID*)&pDeviceEnumerator);
    if (SUCCEEDED(hr))
    {
     IMMDevice* pDefault;
     hr = pDeviceEnumerator->GetDefaultAudioEndpoint(eRender, eMultimedia, &pDefault);
     if (SUCCEEDED(hr))
     {
     LPWSTR pwstrEndpointId = NULL;
     hr = pDefault->GetId(&pwstrEndpointId);
    
     IPolicyConfig* pPolicyConfig;
     hr = CoCreateInstance(CLSID_PolicyConfig, NULL, CLSCTX_INPROC_SERVER, IID_PPV_ARGS(&pPolicyConfig));
     if (SUCCEEDED(hr))
     {
     PROPVARIANT var;
     PropVariantInit(&var);
     hr = pPolicyConfig->GetPropertyValue(pwstrEndpointId, TRUE, PKEY_AudioEndpoint_Disable_SysFx, &var);
     var.uiVal = (USHORT)1;
     hr = pPolicyConfig->SetPropertyValue(pwstrEndpointId, TRUE, PKEY_AudioEndpoint_Disable_SysFx, &var);
     pPolicyConfig->Release();
     }
     }
     pDeviceEnumerator->Release();
    }
    

    At beginning :

    #include <initguid.h>
    #include <Mmdeviceapi.h>
    
    DEFINE_GUID(CLSID_PolicyConfig, 0x870af99c, 0x171d, 0x4f9e, 0xaf, 0x0d, 0xe6, 0x3d, 0xf4, 0x0c, 0x2b, 0xc9);
    MIDL_INTERFACE("f8679f50-850a-41cf-9c72-430f290290c8")
    IPolicyConfig : public IUnknown
    {
    public:
     virtual HRESULT STDMETHODCALLTYPE GetMixFormat(PCWSTR pszDeviceName, WAVEFORMATEX** ppFormat) = 0;
     virtual HRESULT STDMETHODCALLTYPE GetDeviceFormat(PCWSTR pszDeviceName, bool bDefault, WAVEFORMATEX** ppFormat) = 0;
     virtual HRESULT STDMETHODCALLTYPE ResetDeviceFormat(PCWSTR pszDeviceName) = 0;
     virtual HRESULT STDMETHODCALLTYPE SetDeviceFormat(PCWSTR pszDeviceName, WAVEFORMATEX* ppEndpointFormatFormat, WAVEFORMATEX* pMixFormat) = 0;
     virtual HRESULT STDMETHODCALLTYPE GetProcessingPeriod(PCWSTR pszDeviceName, bool bDefault, PINT64 pmftDefaultPeriod, PINT64 pmftMinimumPeriod) = 0;
     virtual HRESULT STDMETHODCALLTYPE SetProcessingPeriod(PCWSTR pszDeviceName, PINT64 pmftPeriod) = 0;
     virtual HRESULT STDMETHODCALLTYPE GetShareMode(PCWSTR pszDeviceName, struct DeviceShareMode* pMode) = 0;
     virtual HRESULT STDMETHODCALLTYPE SetShareMode(PCWSTR pszDeviceName, struct DeviceShareMode* pMode) = 0;
     virtual HRESULT STDMETHODCALLTYPE GetPropertyValue(PCWSTR pszDeviceName, BOOL bFxStore, const PROPERTYKEY& pKey, PROPVARIANT* pv) = 0;
     virtual HRESULT STDMETHODCALLTYPE SetPropertyValue(PCWSTR pszDeviceName, BOOL bFxStore, const PROPERTYKEY& pKey, PROPVARIANT* pv) = 0;
     virtual HRESULT STDMETHODCALLTYPE SetDefaultEndpoint(PCWSTR pszDeviceName, ERole eRole) = 0;
     virtual HRESULT STDMETHODCALLTYPE SetEndpointVisibility(PCWSTR pszDeviceName, bool bVisible) = 0;
    };
    

3 additional answers

Sort by: Most helpful
  1. Castorix31 85,711 Reputation points
    2021-12-20T09:45:10.527+00:00

    It is done with IPropertyStore and PKEY_AudioEndpoint_Disable_SysFx


  2. Jeanine Zhang-MSFT 9,771 Reputation points Microsoft Vendor
    2021-12-21T05:28:46.44+00:00

    Hi,

    Welcome to Microsoft Q&A!

    According to your description, whether you want to set this?

    159178-image.png

    If so, I am afraid of that this is impossible.

    Each endpoint has two property stores; the "endpoint property store" displayed above, and the "effects property store." The endpoint property store is exposed to applications, but the effects property store is limited to:

    1) the audio driver

    2) the audio engine

    3) the Sound control panel.

    So only the user can view / change settings in the effects property store, and that only through the Sound control panel.

    And I suggest you could refer to the threads: https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/b028b430-48c5-434b-a644-da192fbf20a5/how-can-we-control-the-quotenhancementsquot-page-under-device-properties-page?forum=windowspro-audiodevelopment

    https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/5830c1de-fc50-468b-9017-6a88b774a861/how-can-i-disable-microphone-enhancements-from-code?forum=windowspro-audiodevelopment

    Best Regards,

    Jeanine


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  3. Jens-Peter Vraa Jensen 1 Reputation point
    2022-05-20T12:08:08.61+00:00

    Hi,

    Did anyone find a solution to this?

    We are facing audio recording issues when the "Enabled audio enhanchments" is checked. The issue is quite serious as there are several seconds of empty recordings in-between. It only happens using Philips and Olympus dictaphones, but not when using a Jabra Evolve 40 UC headset.

    Since our users are switching workplace computers all the time, we can simply not ask them to check/untick a box before starting their work, so I was hoping we could fix this in code somehow.

    Looking forward to any replies!

    Best regards,

    Jens-Peter


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.