From 3f9ae1ee1045983bd225131fb34de03b5000b692 Mon Sep 17 00:00:00 2001 From: Niklas Carlsson Date: Mon, 29 Sep 2025 12:09:57 +0200 Subject: [PATCH] filter-graph: allow 8 channels in max plugin Mimic the same channel behavior as for other plugins that allows for 8 channels, such as Mixer and Mult. --- spa/plugins/filter-graph/plugin_builtin.c | 61 +++++++++++++++++------ src/modules/module-filter-chain.c | 7 ++- 2 files changed, 52 insertions(+), 16 deletions(-) diff --git a/spa/plugins/filter-graph/plugin_builtin.c b/spa/plugins/filter-graph/plugin_builtin.c index 955c6442d..647c9a51b 100644 --- a/spa/plugins/filter-graph/plugin_builtin.c +++ b/spa/plugins/filter-graph/plugin_builtin.c @@ -2155,24 +2155,33 @@ static const struct spa_fga_descriptor param_eq_desc = { static void max_run(void * Instance, unsigned long SampleCount) { struct builtin *impl = Instance; - float *out = impl->port[0], *in1 = impl->port[1], *in2 = impl->port[2]; - unsigned long n; + float *out = impl->port[0]; + float *src[8]; + unsigned long n, p, n_srcs = 0; if (out == NULL) return; - if (in1 != NULL && in2 != NULL) { - for (n = 0; n < SampleCount; n++) - out[n] = SPA_MAX(in1[n], in2[n]); - } else if (in1 != NULL) { - for (n = 0; n < SampleCount; n++) - out[n] = in1[n]; - } else if (in2 != NULL) { - for (n = 0; n < SampleCount; n++) - out[n] = in2[n]; + for (p = 1; p < 9; p++) { + if (impl->port[p] != NULL) + src[n_srcs++] = impl->port[p]; + } + + if (n_srcs == 0) { + spa_memzero(out, SampleCount * sizeof(float)); + } else if (n_srcs == 1) { + spa_memcpy(out, src[0], SampleCount * sizeof(float)); } else { - for (n = 0; n < SampleCount; n++) - out[n] = 0.0f; + for (p = 0; p < n_srcs; p++) { + if (p == 0) { + for (n = 0; n < SampleCount; n++) + out[n] = SPA_MAX(src[p][n], src[p + 1][n]); + p++; + } else { + for (n = 0; n < SampleCount; n++) + out[n] = SPA_MAX(out[n], src[p][n]); + } + } } } @@ -2189,7 +2198,31 @@ static struct spa_fga_port max_ports[] = { { .index = 2, .name = "In 2", .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, - } + }, + { .index = 3, + .name = "In 3", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 4, + .name = "In 4", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 5, + .name = "In 5", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 6, + .name = "In 6", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 7, + .name = "In 7", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 8, + .name = "In 8", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, }; static const struct spa_fga_descriptor max_desc = { diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 6c2f16200..84b70d651 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -537,9 +537,12 @@ extern struct spa_handle_factory spa_filter_graph_factory; * * ### Max * - * Use the `max` plugin if you need to select the max value of two channels. + * Use the `max` plugin if you need to select the max value of a number of input ports. * - * It has two input ports "In 1" and "In 2" and one output port "Out". + * It has 8 input ports named "In 1" to "In 8" and one output port "Out". + * + * All input ports samples are checked to find the maximum value per sample. Unused + * input ports will be ignored and not cause overhead. * * ### dcblock *