windowsaudiowindows-11

How to change microphone format programmatically


In Windows 11 you can change the format manually in Sound Settings. This changes the format that ADC (analogue-to-digital converter) outputs.

How does the settings app manage to do this?

From the Device Topology API

The settings in the volume, mute, and multiplexer subunits can be controlled by clients, and the DeviceTopology API provides control interfaces to clients for controlling them. In this example, the ADC subunit has no control settings. Thus, the DeviceTopology API provides no control interface for the ADC.

Is the settings app using an undocumented API?

Change format UI


Solution

  • After familiarizing myself with the Core Audio API (and noting that the only formats supported by both API's are exactly those supported natively by the audio device), I think it's obvious that:

    Calling IAudioClient::Initialize with AUDCLNT_SHAREMODE_EXCLUSIVE will change the ADC output format.

    Changing the shared mode audio format in the settings app will also change the ADC output format. You can retrieve the shared mode audio format from an IMMDevice through it's property store using the key PKEY_AudioEngine_DeviceFormat. So maybe it's possible to change this programmatically, by setting the IPropertyStore (or possibly by changing values in the windows registry).

    I'm still a bit unclear of the behaviour of AudioDeviceInputNode when creating with AudioncodingProperties different from that shared mode format. Does it get exclusive access to the device, does it change the shared mode format, does it fail, or does it resample. And how to tell these apart?