Windows: determine minimum number of audio channels supported.

ms-remove-deprecated-modes
Mooneer Salem 2025-05-25 12:43:59 -07:00
parent 5502a07afc
commit e9bfbdf386
1 changed files with 20 additions and 0 deletions

View File

@ -419,6 +419,26 @@ AudioDeviceSpecification WASAPIAudioEngine::getDeviceSpecification_(IMMDevice* d
spec.defaultSampleRate = streamFormat->nSamplesPerSec;
spec.maxChannels = streamFormat->nChannels;
spec.minChannels = streamFormat->nChannels;
// Determine minimum number of channels supported.
for (int channel = spec.maxChannels - 1; channel >= 1; channel--)
{
WAVEFORMATEX* closestFormat = nullptr;
streamFormat->nChannels = channel;
if (audioClient->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED, streamFormat, &closestFormat) == S_OK)
{
spec.minChannels = channel;
}
if (closestFormat != nullptr)
{
CoTaskMemFree(closestFormat);
}
if (spec.minChannels != channel)
{
break;
}
}
CoTaskMemFree(streamFormat);
audioClient->Release();