From 17b50b26e6cc2ff58b655236fcd9ee75905d7833 Mon Sep 17 00:00:00 2001 From: Hybrid Dog Date: Fri, 30 Mar 2018 19:26:22 +0200 Subject: [PATCH] wet doesnt work --- src/modules/module-ladspa-sink.c | 29 +++++++++++++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/src/modules/module-ladspa-sink.c b/src/modules/module-ladspa-sink.c index d677381d..9855a778 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= " + "wet= " "input_ladspaport_map= " "output_ladspaport_map= " "autoloaded= ")); @@ -85,6 +86,7 @@ struct userdata { LADSPA_Data **input, **output; size_t block_size; LADSPA_Data *control; + float wet; long unsigned n_control; /* This is a dummy buffer. Every port must be connected, but we don't care @@ -118,6 +120,7 @@ static const char* const valid_modargs[] = { "plugin", "label", "control", + "wet", "input_ladspaport_map", "output_ladspaport_map", "autoloaded", @@ -464,7 +467,7 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk struct userdata *u; float *src, *dst; size_t fs; - unsigned n, h, c; + unsigned n, h, c, x; pa_memchunk tchunk; pa_sink_input_assert_ref(i); @@ -506,6 +509,18 @@ static int sink_input_pop_cb(pa_sink_input *i, size_t nbytes, pa_memchunk *chunk 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); + +// TODO: run_adding instead of wet + if (u->wet < 1.0f) { + float dry = 1.0f - u->wet; + for (c = 0; c < u->output_count; c++) { + for (x = 0; x < n; ++x) { + u->output[c][x] = u->output[c][x] * u->wet + + u->input[c][x] * dry; + } + } + } + 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 +1001,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, *wet_str; const LADSPA_Descriptor *d; unsigned long p, h, j, n_control, c; + double wet_d; pa_memchunk silence; pa_assert(m); @@ -1054,6 +1070,15 @@ int pa__init(pa_module*m) { u->output = NULL; u->ss = ss; + wet_str = pa_modargs_get_value(ma, "wet", NULL); + if (pa_atod(wet_str, &wet_d) < 0) { + u->wet = 1.0f; + } else { + // wet should be in [0,1[ + u->wet = (float)wet_d; + pa_log_debug("wet is set to %g", u->wet); + } + /* 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). -- 2.14.1