mirror of
https://gitlab.freedesktop.org/pulseaudio/pulseaudio.git
synced 2025-11-06 13:29:56 -05:00
clamp sample data to -1 .. 1, before passing it to the plugin; if a control port data specification is left empty, initialize with the default value of the plugin
git-svn-id: file:///home/lennart/svn/public/pulseaudio/branches/lennart@1877 fefdeb5f-60dc-0310-8127-8f9354f1896f
This commit is contained in:
parent
29d25ec8d9
commit
1fc168b02f
1 changed files with 123 additions and 33 deletions
|
|
@ -172,14 +172,14 @@ static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chun
|
|||
p = src + c;
|
||||
q = u->input;
|
||||
for (j = 0; j < n; j++, p += u->channels, q++)
|
||||
*q = *p;
|
||||
*q = CLAMP(*p, -1.0, 1.0);
|
||||
|
||||
u->descriptor->run(u->handle[c], n);
|
||||
|
||||
q = u->output;
|
||||
p = dst + c;
|
||||
for (j = 0; j < n; j++, q++, p += u->channels)
|
||||
*p = *q;
|
||||
*p = CLAMP(*q, -1.0, 1.0);
|
||||
}
|
||||
|
||||
pa_memblock_release(tchunk.memblock);
|
||||
|
|
@ -188,9 +188,12 @@ static int sink_input_peek_cb(pa_sink_input *i, size_t length, pa_memchunk *chun
|
|||
pa_memblock_unref(tchunk.memblock);
|
||||
}
|
||||
|
||||
pa_assert(u->memchunk.length > 0);
|
||||
pa_assert(u->memchunk.memblock);
|
||||
|
||||
*chunk = u->memchunk;
|
||||
pa_memblock_ref(chunk->memblock);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -274,6 +277,7 @@ int pa__init(pa_module*m) {
|
|||
const LADSPA_Descriptor *d;
|
||||
unsigned long input_port, output_port, p, j, n_control;
|
||||
unsigned c;
|
||||
pa_bool_t *use_default = NULL;
|
||||
|
||||
pa_assert(m);
|
||||
|
||||
|
|
@ -425,11 +429,18 @@ int pa__init(pa_module*m) {
|
|||
unsigned long h;
|
||||
|
||||
u->control = pa_xnew(LADSPA_Data, n_control);
|
||||
use_default = pa_xnew(pa_bool_t, n_control);
|
||||
p = 0;
|
||||
|
||||
while ((k = pa_split(cdata, ",", &state))) {
|
||||
float f;
|
||||
|
||||
if (*k == 0) {
|
||||
use_default[p++] = TRUE;
|
||||
pa_xfree(k);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pa_atof(k, &f) < 0) {
|
||||
pa_log("Failed to parse control value '%s'", k);
|
||||
pa_xfree(k);
|
||||
|
|
@ -443,6 +454,7 @@ int pa__init(pa_module*m) {
|
|||
goto fail;
|
||||
}
|
||||
|
||||
use_default[p] = FALSE;
|
||||
u->control[p++] = f;
|
||||
}
|
||||
|
||||
|
|
@ -453,12 +465,86 @@ int pa__init(pa_module*m) {
|
|||
|
||||
h = 0;
|
||||
for (p = 0; p < d->PortCount; p++) {
|
||||
LADSPA_PortRangeHintDescriptor hint = d->PortRangeHints[p].HintDescriptor;
|
||||
|
||||
if (!LADSPA_IS_PORT_INPUT(d->PortDescriptors[p]) || !LADSPA_IS_PORT_CONTROL(d->PortDescriptors[p]))
|
||||
continue;
|
||||
|
||||
pa_assert(h < n_control);
|
||||
|
||||
if (use_default[c]) {
|
||||
LADSPA_Data lower, upper;
|
||||
|
||||
if (!LADSPA_IS_HINT_HAS_DEFAULT(hint)) {
|
||||
pa_log("Control port value left empty but plugin defines no default.");
|
||||
goto fail;
|
||||
}
|
||||
|
||||
lower = d->PortRangeHints[p].LowerBound;
|
||||
upper = d->PortRangeHints[p].UpperBound;
|
||||
|
||||
if (LADSPA_IS_HINT_SAMPLE_RATE(hint)) {
|
||||
lower *= ss.rate;
|
||||
upper *= ss.rate;
|
||||
}
|
||||
|
||||
switch (hint & LADSPA_HINT_DEFAULT_MASK) {
|
||||
|
||||
case LADSPA_HINT_DEFAULT_MINIMUM:
|
||||
u->control[h] = lower;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_MAXIMUM:
|
||||
u->control[h] = upper;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_LOW:
|
||||
if (LADSPA_IS_HINT_LOGARITHMIC(hint))
|
||||
u->control[h] = exp(log(lower) * 0.75 + log(upper) * 0.25);
|
||||
else
|
||||
u->control[h] = lower * 0.75 + upper * 0.25;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_MIDDLE:
|
||||
if (LADSPA_IS_HINT_LOGARITHMIC(hint))
|
||||
u->control[h] = exp(log(lower) * 0.5 + log(upper) * 0.5);
|
||||
else
|
||||
u->control[h] = lower * 0.5 + upper * 0.5;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_HIGH:
|
||||
if (LADSPA_IS_HINT_LOGARITHMIC(hint))
|
||||
u->control[h] = exp(log(lower) * 0.25 + log(upper) * 0.75);
|
||||
else
|
||||
u->control[h] = lower * 0.25 + upper * 0.75;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_0:
|
||||
u->control[h] = 0;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_1:
|
||||
u->control[h] = 1;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_100:
|
||||
u->control[h] = 100;
|
||||
break;
|
||||
|
||||
case LADSPA_HINT_DEFAULT_440:
|
||||
u->control[h] = 440;
|
||||
break;
|
||||
|
||||
default:
|
||||
pa_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
if (LADSPA_IS_HINT_INTEGER(hint))
|
||||
u->control[h] = roundf(u->control[h]);
|
||||
|
||||
pa_log_debug("Binding %f to port %s", u->control[h], d->PortNames[p]);
|
||||
|
||||
for (c = 0; c < ss.channels; c++)
|
||||
d->connect_port(u->handle[c], p, &u->control[h]);
|
||||
|
||||
|
|
@ -514,12 +600,16 @@ int pa__init(pa_module*m) {
|
|||
|
||||
pa_modargs_free(ma);
|
||||
|
||||
pa_xfree(use_default);
|
||||
|
||||
return 0;
|
||||
|
||||
fail:
|
||||
if (ma)
|
||||
pa_modargs_free(ma);
|
||||
|
||||
pa_xfree(use_default);
|
||||
|
||||
pa__done(m);
|
||||
|
||||
return -1;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue