diff --git a/spa/plugins/filter-graph/plugin_sofa.c b/spa/plugins/filter-graph/plugin_sofa.c index 309b86dd9..22b28fcb2 100644 --- a/spa/plugins/filter-graph/plugin_sofa.c +++ b/spa/plugins/filter-graph/plugin_sofa.c @@ -50,6 +50,8 @@ static void * spatializer_instantiate(const struct spa_fga_plugin *plugin, const const char *val; char key[256]; char filename[PATH_MAX] = ""; + bool normalize = false; + float normalized; int len; errno = EINVAL; @@ -104,6 +106,13 @@ static void * spatializer_instantiate(const struct spa_fga_plugin *plugin, const goto error; } } + else if (spa_streq(key, "normalize")) { + if (spa_json_parse_bool(val, len, &normalize) <= 0) { + spa_log_error(impl->log, "spatializer:normalize requires a bool"); + errno = EINVAL; + 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"); @@ -206,8 +215,13 @@ static void * spatializer_instantiate(const struct spa_fga_plugin *plugin, const if (impl->tailsize <= 0) impl->tailsize = SPA_CLAMP(4096, impl->blocksize, 32768); - spa_log_info(impl->log, "using n_samples:%u %d:%d blocksize gain:%f sofa:%s", impl->n_samples, - impl->blocksize, impl->tailsize, impl->gain, filename); + if (normalize) + normalized = mysofa_loudness(impl->sofa->hrtf); + + spa_log_info(impl->log, "using n_samples:%u %d:%d blocksize %sgain:%f sofa:%s", impl->n_samples, + impl->blocksize, impl->tailsize, + normalize ? "auto" : "", normalize ? normalized : impl->gain, filename); + impl->tmp[0] = calloc(impl->plugin->quantum_limit, sizeof(float)); impl->tmp[1] = calloc(impl->plugin->quantum_limit, sizeof(float)); diff --git a/src/modules/module-filter-chain.c b/src/modules/module-filter-chain.c index 62dd9e666..d3b061114 100644 --- a/src/modules/module-filter-chain.c +++ b/src/modules/module-filter-chain.c @@ -743,6 +743,7 @@ extern struct spa_handle_factory spa_filter_graph_factory; * filename = ... * gain = ... * latency = ... + * normalize = ... * } * control = { * "Azimuth" = ... @@ -764,6 +765,7 @@ extern struct spa_handle_factory spa_filter_graph_factory; * and contain the HRTF for the various spatial positions. * - `gain` the overall gain to apply to the IR file, default 1.0. * - `latency` the latency introduced by the filter, default 0 + * - `normalize` automatically normalize the loudness of the IR, default false * * - `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