How to get number of channels from audio playback devices?

1k Views Asked by At

The game Titanfall 2 shows the audio configuration for the playback device. https://i.stack.imgur.com/WcGpK.png

Is there anything I can do to get this information via code in C#?

Update & correction (September 29, 2019 at around 3:12pm UTC): The above linked image shows the audio option for the free-to-play game Apex Legends. The link for Titanfall 2 audio settings is http://i.imgur.com/6OSSysd.gif. For both games Windows Audio Configuration shows information, it is not an option users can change in game.

Some may find information at https://satsun.org/audio/ useful.

1

There are 1 best solutions below

1
Chuck Walbourn On

You enumerate devices on Windows Vista or later via the MMDevice

IMMDeviceEnumerator *enumerator = nullptr;
IMMDevice *device = nullptr;

hr = CoCreateInstance(__uuidof(MMDeviceEnumerator), nullptr, CLSCTX_ALL, __uuidof(IMMDeviceEnumerator), (void**)&enumerator);
if (FAILED(hr))
       ...

// Get the default renderer
hr = enumerator->GetDefaultAudioEndpoint(eRender, eConsole, &device);
if (FAILED(hr))
       ...

    hr = pEndpoint->OpenPropertyStore(
                      STGM_READ, &pProps);
if (FAILED(hr))
       ...

    PROPVARIANT varName;
    // Initialize container for property value.
    PropVariantInit(&varName);

    // Get the endpoint's physical speaker property.
    hr = pProps->GetValue(
                   PKEY_AudioEndpoint_PhysicalSpeakers, &varName);
if (FAILED(hr))
       …

    // See https://learn.microsoft.com/en-us/windows/win32/coreaudio/pkey-audioendpoint-physicalspeakers

    PropVariantClear(&varName);

See Microsoft Docs