From 8bcf0460d150ba56f75416501aa4866797df5a88 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Wed, 7 May 2025 17:18:15 +0200 Subject: [PATCH] filter-graph: add latency option to the convolver Sometimes you want to use the convolver as a delay without adding latency so add a latency option to tweak the automatic latency reporting. Use this in the upmix rear delay filters. --- spa/plugins/filter-graph/builtin_plugin.c | 15 ++++++++++++--- .../filter-chain/sink-upmix-5.1-filter.conf | 2 ++ src/modules/module-filter-chain.c | 3 +++ 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/spa/plugins/filter-graph/builtin_plugin.c b/spa/plugins/filter-graph/builtin_plugin.c index b38681f9d..260f36c53 100644 --- a/spa/plugins/filter-graph/builtin_plugin.c +++ b/spa/plugins/filter-graph/builtin_plugin.c @@ -688,7 +688,7 @@ struct convolver_impl { struct spa_fga_dsp *dsp; unsigned long rate; float *port[3]; - unsigned long latency; + float latency; struct convolver *conv; }; @@ -927,7 +927,7 @@ static void * convolver_instantiate(const struct spa_fga_plugin *plugin, const s char *filenames[MAX_RATES] = { 0 }; int blocksize = 0, tailsize = 0; int resample_quality = RESAMPLE_DEFAULT_QUALITY; - float gain = 1.0f, delay = 0.0f; + float gain = 1.0f, delay = 0.0f, latency = -1.0f; unsigned long rate; errno = EINVAL; @@ -1009,6 +1009,12 @@ static void * convolver_instantiate(const struct spa_fga_plugin *plugin, const s return NULL; } } + else if (spa_streq(key, "latency")) { + if (spa_json_parse_float(val, len, &latency) <= 0) { + spa_log_error(pl->log, "convolver:latency requires a number"); + return NULL; + } + } else { spa_log_warn(pl->log, "convolver: ignoring config key: '%s'", key); } @@ -1069,7 +1075,10 @@ static void * convolver_instantiate(const struct spa_fga_plugin *plugin, const s if (impl->conv == NULL) goto error; - impl->latency = n_samples; + if (latency < 0.0f) + impl->latency = n_samples; + else + impl->latency = latency * impl->rate; free(samples); diff --git a/src/daemon/filter-chain/sink-upmix-5.1-filter.conf b/src/daemon/filter-chain/sink-upmix-5.1-filter.conf index 197733045..5ac4e7650 100644 --- a/src/daemon/filter-chain/sink-upmix-5.1-filter.conf +++ b/src/daemon/filter-chain/sink-upmix-5.1-filter.conf @@ -87,6 +87,7 @@ context.modules = [ delay = 0.012 filename = "/hilbert" length = 33 + latency = 0.0 } } { @@ -101,6 +102,7 @@ context.modules = [ delay = 0.012 filename = "/hilbert" length = 33 + latency = 0.0 } } ] diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 8302c1c8e..8b4e54ac0 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -330,6 +330,7 @@ extern struct spa_handle_factory spa_filter_graph_factory; * length = ... * channel = ... * resample_quality = ... + * latency = ... * } * ... * } @@ -361,6 +362,8 @@ extern struct spa_handle_factory spa_filter_graph_factory; * - `channel` The channel to use from the file as the IR. * - `resample_quality` The resample quality in case the IR does not match the graph * samplerate. + * - `latency` The extra latency in seconds to report. When left unspecified (or < 0.0) + * the convolver latency will be the length of the IR. * * ### Delay *