From 691f6703f4d27bce562846040a39c4b2acd431c8 Mon Sep 17 00:00:00 2001 From: Hybrid Dog Date: Thu, 29 Mar 2018 13:43:22 +0200 Subject: [PATCH 1/2] LADSPA module: Support run_adding --- src/modules/module-ladspa-sink.c | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c index d677381d..5f5e4bc9 100644 --- a/src/modules/module-ladspa-sink.c +++ b/src/modules/module-ladspa-sink.c @@ -63,6 +63,7 @@ PA_MODULE_USAGE( "plugin= " "label= " "control= " + "run_adding_gain= " "input_ladspaport_map= " "output_ladspaport_map= " "autoloaded= ")); @@ -85,6 +86,8 @@ struct userdata { LADSPA_Data **input, **output; size_t block_size; LADSPA_Data *control; + bool use_run_adding; + LADSPA_Data run_adding_gain; long unsigned n_control; /* This is a dummy buffer. Every port must be connected, but we don't care @@ -118,6 +121,7 @@ static const char* const valid_modargs[] = { "plugin", "label", "control", + "run_adding_gain", "input_ladspaport_map", "output_ladspaport_map", "autoloaded", @@ -172,7 +176,7 @@ static void get_algorithm_parameters(DBusConnection *conn, DBusMessage *msg, voi pa_dbus_append_basic_array(&struct_iter, DBUS_TYPE_DOUBLE, control, u->n_control); pa_dbus_append_basic_array(&struct_iter, DBUS_TYPE_BOOLEAN, use_default, u->n_control); - +// TODO: what should be done here? pa_assert_se(dbus_message_iter_close_container(&msg_iter, &struct_iter)); pa_assert_se(dbus_connection_send(conn, reply, NULL)); @@ -229,6 +233,7 @@ static void set_algorithm_parameters(DBusConnection *conn, DBusMessage *msg, DBu pa_log_warn("Failed writing control parameters"); goto error; } +// TODO set run_adding_gain using DBUS pa_asyncmsgq_send(u->sink->asyncmsgq, PA_MSGOBJECT(u->sink), LADSPA_SINK_MESSAGE_UPDATE_PARAMETERS, NULL, 0, NULL); @@ -505,7 +510,10 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk for (h = 0; h < (u->channels / u->max_ladspaport_count); h++) { for (c = 0; c < u->input_count; c++) pa_sample_clamp(PA_SAMPLE_FLOAT32NE, u->input[c], sizeof(float), src+ h*u->max_ladspaport_count + c, u->channels*sizeof(float), n); - u->descriptor->run(u->handle[h], n); + if (u->use_run_adding) + u->descriptor->run_adding(u->handle[h], n); + else + u->descriptor->run(u->handle[h], n); for (c = 0; c < u->output_count; c++) pa_sample_clamp(PA_SAMPLE_FLOAT32NE, dst + h*u->max_ladspaport_count + c, u->channels*sizeof(float), u->output[c], sizeof(float), n); } @@ -986,9 +994,10 @@ int pa__init(pa_module*m) { const char *plugin, *label, *input_ladspaport_map, *output_ladspaport_map; LADSPA_Descriptor_Function descriptor_func; unsigned long input_ladspaport[PA_CHANNELS_MAX], output_ladspaport[PA_CHANNELS_MAX]; - const char *e, *cdata; + const char *e, *cdata, *run_adding_str; const LADSPA_Descriptor *d; unsigned long p, h, j, n_control, c; + double run_adding_gain_d; pa_memchunk silence; pa_assert(m); @@ -1054,6 +1063,17 @@ int pa__init(pa_module*m) { u->output = NULL; u->ss = ss; + run_adding_str = pa_modargs_get_value(ma, "run_adding_gain", NULL); + if (pa_atod(run_adding_str, &run_adding_gain_d) < 0) { + // run_adding_gain is not specified, use the run function + u->use_run_adding = false; + } else { + // run_adding is used, testing it's availability happens later + u->use_run_adding = true; + u->run_adding_gain = (LADSPA_Data)run_adding_gain_d; + pa_log_debug("run_adding_gain is set to %g", u->run_adding_gain); + } + /* If the LADSPA_PATH environment variable is not set, we use the * LADSPA_PATH preprocessor macro instead. The macro can contain characters * that need to be escaped (especially on Windows backslashes are common). @@ -1195,6 +1215,13 @@ int pa__init(pa_module*m) { } } + // If run_adding should be enabled, ensure that it's available + if (u->use_run_adding && (!d->set_run_adding_gain || !d->run_adding)) { + pa_log("The plugin %s with label %s does not support run_adding", + plugin, d->Label); + goto fail; + } + u->block_size = pa_frame_align(pa_mempool_block_size_max(m->core->mempool), &ss); /* Create buffers */ @@ -1222,6 +1249,9 @@ int pa__init(pa_module*m) { d->connect_port(u->handle[h], input_ladspaport[c], u->input[c]); for (c = 0; c < u->output_count; c++) d->connect_port(u->handle[h], output_ladspaport[c], u->output[c]); + + if (u->use_run_adding) + d->set_run_adding_gain(u->handle[h], u->run_adding_gain); } u->n_control = n_control; -- 2.14.1