From 5aee5d656a25c819496945a9d78b221ddc985908 Mon Sep 17 00:00:00 2001 From: Steven Noonan Date: Wed, 10 Aug 2022 11:45:31 -0700 Subject: [PATCH] channel mapping: treat "simple" mix mode as a 1:1 mapping only mode We already map the in:out 1:1 mappings above the switch statement, but the code for "simple" mapping stomps on the mappings. Also, even before that loop was added, mix mode "simple" did not necessarily map to the same channel types you'd expect. For example, if you have a 6-channel input and 8-channel output, you would get something like this with "simple": Correct: CHANNEL_FRONT_LEFT -> CHANNEL_FRONT_LEFT Correct: CHANNEL_FRONT_RIGHT -> CHANNEL_FRONT_RIGHT Correct: CHANNEL_FRONT_CENTER -> CHANNEL_FRONT_CENTER Correct: CHANNEL_LFE -> CHANNEL_LFE Wrong: CHANNEL_SIDE_LEFT -> CHANNEL_BACK_LEFT Wrong: CHANNEL_SIDE_RIGHT -> CHANNEL_BACK_RIGHT Instead of just assuming the input channel map is a truncation of the output channel map and has channels in the same order, just keep the existing 1:1 mappings and hope that's sufficient. Signed-off-by: Steven Noonan --- miniaudio.h | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/miniaudio.h b/miniaudio.h index bc663196..a9e4fdaf 100644 --- a/miniaudio.h +++ b/miniaudio.h @@ -51293,19 +51293,8 @@ MA_API ma_result ma_channel_converter_init_preallocated(const ma_channel_convert case ma_channel_mix_mode_simple: { - /* In simple mode, excess channels need to be silenced or dropped. */ - ma_uint32 iChannel; - for (iChannel = 0; iChannel < ma_min(pConverter->channelsIn, pConverter->channelsOut); iChannel += 1) { - if (pConverter->format == ma_format_f32) { - if (pConverter->weights.f32[iChannel][iChannel] == 0) { - pConverter->weights.f32[iChannel][iChannel] = 1; - } - } else { - if (pConverter->weights.s16[iChannel][iChannel] == 0) { - pConverter->weights.s16[iChannel][iChannel] = ma_channel_converter_float_to_fixed(1); - } - } - } + /* In simple mode, only set weights for channels that have exactly matching types, leave the rest at + zero. The 1:1 mappings have already been covered before this switch statement. */ } break; case ma_channel_mix_mode_rectangular: