diff --git a/spa/plugins/filter-graph/plugin_sofa.c b/spa/plugins/filter-graph/plugin_sofa.c index 2e3a1ea3b..8e1777989 100644 --- a/spa/plugins/filter-graph/plugin_sofa.c +++ b/spa/plugins/filter-graph/plugin_sofa.c @@ -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) diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index f08db7bf1..d0c4cd04c 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -705,7 +705,8 @@ extern struct spa_handle_factory spa_filter_graph_factory; * - `tailsize` specifies the size of the tail blocks to use in the FFT. * - `filename` The SOFA file to load. SOFA files usually end in the .sofa extension * and contain the HRTF for the various spatial positions. - * - `gain` the overall gain to apply to the IR file. + * - `gain` the overall gain to apply to the IR file, default 1.0. + * - `latency` the latency introduced by the filter, default 0 * * - `Azimuth` controls the azimuth, this is the direction the sound is coming from * in degrees between 0 and 360. 0 is straight ahead. 90 is left, 180