From e355df3785e00c0e82f605ba195ea2e08ded60a0 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Fri, 4 Apr 2025 17:06:43 +0200 Subject: [PATCH] channelmix: fix channel_mask bits iteration Iterate the number of bits in the channel mask based on the number of bits in the mask, not the max amount of channel positions. --- spa/plugins/audioconvert/channelmix-ops.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/spa/plugins/audioconvert/channelmix-ops.c b/spa/plugins/audioconvert/channelmix-ops.c index d774112bc..792cf7e09 100644 --- a/spa/plugins/audioconvert/channelmix-ops.c +++ b/spa/plugins/audioconvert/channelmix-ops.c @@ -129,6 +129,7 @@ static const struct channelmix_info *find_channelmix_info(uint32_t src_chan, uin #define STEREO (_MASK(FL)|_MASK(FR)) #define REAR (_MASK(RL)|_MASK(RR)) #define SIDE (_MASK(SL)|_MASK(SR)) +#define CHANNEL_BITS (64u) static uint32_t mask_to_ch(struct channelmix *mix, uint64_t mask) { @@ -168,7 +169,7 @@ static bool match_mix(struct channelmix *mix, { bool matched = false; uint32_t i; - for (i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++) { + for (i = 0; i < CHANNEL_BITS; i++) { if ((src_mask & dst_mask & (1ULL << i))) { spa_log_info(mix->log, "matched channel %u (%f)", i, 1.0f); matrix[i][i] = 1.0f; @@ -627,7 +628,7 @@ done: if (src_paired == 0) src_paired = ~0LU; - for (jc = 0, ic = 0, i = 0; i < SPA_AUDIO_MAX_CHANNELS; i++) { + for (jc = 0, ic = 0, i = 0; i < CHANNEL_BITS; i++) { float sum = 0.0f; char str1[1024], str2[1024]; struct spa_strbuf sb1, sb2; @@ -637,7 +638,7 @@ done: if ((dst_paired & (1UL << i)) == 0) continue; - for (jc = 0, j = 0; j < SPA_AUDIO_MAX_CHANNELS; j++) { + for (jc = 0, j = 0; j < CHANNEL_BITS; j++) { if ((src_paired & (1UL << j)) == 0) continue; if (ic >= dst_chan || jc >= src_chan)