diff --git a/spa/plugins/filter-graph/builtin_plugin.c b/spa/plugins/filter-graph/builtin_plugin.c index 999f0de08..5943700f9 100644 --- a/spa/plugins/filter-graph/builtin_plugin.c +++ b/spa/plugins/filter-graph/builtin_plugin.c @@ -2081,6 +2081,49 @@ static const struct spa_fga_descriptor param_eq_desc = { .cleanup = free, }; +/** max */ +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]; + + if (out == NULL) + return; + + unsigned long n; + for (n = 0; n < SampleCount; n++) + out[n] = SPA_MAX(in1[n], in2[n]); +} + +static struct spa_fga_port max_ports[] = { + { .index = 0, + .name = "Out", + .flags = SPA_FGA_PORT_OUTPUT | SPA_FGA_PORT_AUDIO, + }, + + { .index = 1, + .name = "In 1", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 2, + .name = "In 2", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + } +}; + +static const struct spa_fga_descriptor max_desc = { + .name = "max", + .flags = SPA_FGA_DESCRIPTOR_SUPPORTS_NULL_DATA, + + .n_port = SPA_N_ELEMENTS(max_ports), + .ports = max_ports, + + .instantiate = builtin_instantiate, + .connect_port = builtin_connect_port, + .run = max_run, + .cleanup = builtin_cleanup, +}; + static const struct spa_fga_descriptor * builtin_descriptor(unsigned long Index) { switch(Index) { @@ -2128,6 +2171,8 @@ static const struct spa_fga_descriptor * builtin_descriptor(unsigned long Index) return &sine_desc; case 21: return ¶m_eq_desc; + case 22: + return &max_desc; } return NULL; } diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 39fd14d96..b54b5151f 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -466,6 +466,12 @@ extern struct spa_handle_factory spa_filter_graph_factory; * "Freq", "Ampl", "Offset" and "Phase" can be used to control the sine wave * frequency, amplitude, offset and phase. * + * ### Max + * + * Use the `max` plugin if you need to select the max value of two channels. + * + * It has two input ports "In 1" and "In 2" and one output port "Out". + * * ## SOFA filter * * There is an optional builtin SOFA filter available.