diff --git a/spa/plugins/filter-graph/builtin_plugin.c b/spa/plugins/filter-graph/builtin_plugin.c index fd935b2bc..e30194bc4 100644 --- a/spa/plugins/filter-graph/builtin_plugin.c +++ b/spa/plugins/filter-graph/builtin_plugin.c @@ -2367,6 +2367,44 @@ static const struct spa_fga_descriptor ramp_desc = { .cleanup = builtin_cleanup, }; +/* abs */ +static void abs_run(void * Instance, unsigned long SampleCount) +{ + struct builtin *impl = Instance; + float *in = impl->port[1], *out = impl->port[0]; + + if (in != NULL && out != NULL) { + unsigned long n; + for (n = 0; n < SampleCount; n++) { + out[n] = SPA_ABS(in[n]); + } + } +} + +static struct spa_fga_port abs_ports[] = { + { .index = 0, + .name = "Out", + .flags = SPA_FGA_PORT_OUTPUT | SPA_FGA_PORT_AUDIO, + }, + { .index = 1, + .name = "In", + .flags = SPA_FGA_PORT_INPUT | SPA_FGA_PORT_AUDIO, + }, +}; + +static const struct spa_fga_descriptor abs_desc = { + .name = "abs", + .flags = SPA_FGA_DESCRIPTOR_SUPPORTS_NULL_DATA, + + .n_ports = SPA_N_ELEMENTS(abs_ports), + .ports = abs_ports, + + .instantiate = builtin_instantiate, + .connect_port = builtin_connect_port, + .run = abs_run, + .cleanup = builtin_cleanup, +}; + static const struct spa_fga_descriptor * builtin_descriptor(unsigned long Index) { switch(Index) { @@ -2420,6 +2458,8 @@ static const struct spa_fga_descriptor * builtin_descriptor(unsigned long Index) return &dcblock_desc; case 24: return &ramp_desc; + case 25: + return &abs_desc; } return NULL; } diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index e1ec6e6c3..276bc0edd 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -427,6 +427,12 @@ extern struct spa_handle_factory spa_filter_graph_factory; * It has an input port "In" and an output port "Out". It also has a "Control" * and "Notify" port for the control values. * + * ### Abs + * + * The abs plugin can be used to calculate the absolute value of samples. + * + * It has an input port "In" and an output port "Out". + * * ### Exp * * The exp plugin can be used to calculate the exponential (base^x) of samples