mirror of
https://gitlab.freedesktop.org/pipewire/pipewire.git
synced 2025-11-04 13:30:12 -05:00
filter-chain: add sqrt plugin
To take the square root of the signal.
This commit is contained in:
parent
d7718dbcb7
commit
51e7ed3421
2 changed files with 49 additions and 0 deletions
|
|
@ -2405,6 +2405,47 @@ static const struct spa_fga_descriptor abs_desc = {
|
|||
.cleanup = builtin_cleanup,
|
||||
};
|
||||
|
||||
/* sqrt */
|
||||
static void sqrt_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++) {
|
||||
if (in[n] <= 0.0f)
|
||||
out[n] = 0.0f;
|
||||
else
|
||||
out[n] = sqrtf(in[n]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static struct spa_fga_port sqrt_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 sqrt_desc = {
|
||||
.name = "sqrt",
|
||||
.flags = SPA_FGA_DESCRIPTOR_SUPPORTS_NULL_DATA,
|
||||
|
||||
.n_ports = SPA_N_ELEMENTS(sqrt_ports),
|
||||
.ports = sqrt_ports,
|
||||
|
||||
.instantiate = builtin_instantiate,
|
||||
.connect_port = builtin_connect_port,
|
||||
.run = sqrt_run,
|
||||
.cleanup = builtin_cleanup,
|
||||
};
|
||||
|
||||
static const struct spa_fga_descriptor * builtin_descriptor(unsigned long Index)
|
||||
{
|
||||
switch(Index) {
|
||||
|
|
@ -2460,6 +2501,8 @@ static const struct spa_fga_descriptor * builtin_descriptor(unsigned long Index)
|
|||
return &ramp_desc;
|
||||
case 25:
|
||||
return &abs_desc;
|
||||
case 26:
|
||||
return &sqrt_desc;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -433,6 +433,12 @@ extern struct spa_handle_factory spa_filter_graph_factory;
|
|||
*
|
||||
* It has an input port "In" and an output port "Out".
|
||||
*
|
||||
* ### Sqrt
|
||||
*
|
||||
* The sqrt plugin can be used to calculate the square root 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
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue