From 4f0b6545032ee6b999ed3c8cf0ca3731c5c988c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kacper=20Michaj=C5=82ow?= Date: Thu, 2 Feb 2023 20:02:57 +0100 Subject: [PATCH] wasapi: clamp number of output channels to 8 This is the most supported in standard layout, if we request more it tends to fallback to stereo instead. Also channels mask is 32-bit and it can get truncated. --- audio/out/ao_wasapi_utils.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/audio/out/ao_wasapi_utils.c b/audio/out/ao_wasapi_utils.c index d2261bfb6c..07c7ddb43f 100644 --- a/audio/out/ao_wasapi_utils.c +++ b/audio/out/ao_wasapi_utils.c @@ -143,7 +143,19 @@ static void set_waveformat(WAVEFORMATEXTENSIBLE *wformat, wformat->SubFormat = *format_to_subtype(format->mp_format); wformat->Samples.wValidBitsPerSample = format->used_msb; - wformat->dwChannelMask = mp_chmap_to_waveext(channels); + + uint64_t chans = mp_chmap_to_waveext(channels); + wformat->dwChannelMask = chans; + + if (wformat->Format.nChannels > 8 || wformat->dwChannelMask != chans) { + // IAudioClient::IsFormatSupported tend to fallback to stereo for closest + // format match when there are more channels. Remix to standard layout. + // Also if input channel mask has channels outside 32-bits override it + // and hope for the best... + wformat->dwChannelMask = KSAUDIO_SPEAKER_7POINT1_SURROUND; + wformat->Format.nChannels = 8; + } + update_waveformat_datarate(wformat); }