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.
This commit is contained in:
Niklas Carlsson 2025-09-29 12:09:57 +02:00 committed by Wim Taymans
parent 3cf182255f
commit 3f9ae1ee10
2 changed files with 52 additions and 16 deletions

View file

@ -2155,24 +2155,33 @@ static const struct spa_fga_descriptor param_eq_desc = {
static void max_run(void * Instance, unsigned long SampleCount) static void max_run(void * Instance, unsigned long SampleCount)
{ {
struct builtin *impl = Instance; struct builtin *impl = Instance;
float *out = impl->port[0], *in1 = impl->port[1], *in2 = impl->port[2]; float *out = impl->port[0];
unsigned long n; float *src[8];
unsigned long n, p, n_srcs = 0;
if (out == NULL) if (out == NULL)
return; return;
if (in1 != NULL && in2 != NULL) { for (p = 1; p < 9; p++) {
for (n = 0; n < SampleCount; n++) if (impl->port[p] != NULL)
out[n] = SPA_MAX(in1[n], in2[n]); src[n_srcs++] = impl->port[p];
} else if (in1 != NULL) { }
for (n = 0; n < SampleCount; n++)
out[n] = in1[n]; if (n_srcs == 0) {
} else if (in2 != NULL) { spa_memzero(out, SampleCount * sizeof(float));
for (n = 0; n < SampleCount; n++) } else if (n_srcs == 1) {
out[n] = in2[n]; spa_memcpy(out, src[0], SampleCount * sizeof(float));
} else { } else {
for (n = 0; n < SampleCount; n++) for (p = 0; p < n_srcs; p++) {
out[n] = 0.0f; 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, { .index = 2,
.name = "In 2", .name = "In 2",
.flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, .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 = { static const struct spa_fga_descriptor max_desc = {

View file

@ -537,9 +537,12 @@ extern struct spa_handle_factory spa_filter_graph_factory;
* *
* ### Max * ### 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 * ### dcblock
* *