filter-graph: add latency option for SOFA

Add latency option to the sofa plugin. I believe the latency of the
SOFA filters is by default 0 instead of the full length of the IR,
so use that.
This commit is contained in:
Wim Taymans 2026-07-09 11:03:09 +02:00
parent ffdc95655e
commit 18a78cc591
2 changed files with 16 additions and 3 deletions

View file

@ -34,6 +34,7 @@ struct spatializer_impl {
int n_samples, blocksize, tailsize;
float gain;
float *tmp[2];
float latency;
struct MYSOFA_EASY *sofa;
unsigned int interpolate:1;
@ -73,6 +74,7 @@ static void * spatializer_instantiate(const struct spa_fga_plugin *plugin, const
impl->dsp = pl->dsp;
impl->log = pl->log;
impl->gain = 1.0f;
impl->latency = 0.0f;
while ((len = spa_json_object_next(&it[0], key, sizeof(key), &val)) > 0) {
if (spa_streq(key, "blocksize")) {
@ -103,6 +105,16 @@ static void * spatializer_instantiate(const struct spa_fga_plugin *plugin, const
goto error;
}
}
else if (spa_streq(key, "latency")) {
if (spa_json_parse_float(val, len, &impl->latency) <= 0) {
spa_log_error(impl->log, "spatializer:latency requires a number");
errno = EINVAL;
goto error;
}
}
else {
spa_log_warn(pl->log, "spatializer: ignoring config key: '%s'", key);
}
}
if (!filename[0]) {
spa_log_error(impl->log, "spatializer:filename was not given");
@ -331,7 +343,7 @@ static void spatializer_run(void * Instance, unsigned long SampleCount)
convolver_run(impl->l_conv[0], impl->port[2], impl->port[0], SampleCount);
convolver_run(impl->r_conv[0], impl->port[2], impl->port[1], SampleCount);
}
impl->port[6][0] = impl->n_samples;
impl->port[6][0] = impl->latency;
}
static void spatializer_connect_port(void * Instance, unsigned long Port,
@ -367,7 +379,7 @@ static void spatializer_control_changed(void * Instance)
static void spatializer_activate(void * Instance)
{
struct spatializer_impl *impl = Instance;
impl->port[6][0] = impl->n_samples;
impl->port[6][0] = impl->latency;
}
static void spatializer_deactivate(void * Instance)