diff options
author | Damien Zammit <damien@zamaudio.com> | 2016-07-05 02:13:22 +1000 |
---|---|---|
committer | Damien Zammit <damien@zamaudio.com> | 2016-07-05 02:15:47 +1000 |
commit | 46bfe2b51a64ddee2f404b7164defd5ec1009847 (patch) | |
tree | 84e2cbe3ce60404d08d4a0a62b11011ae9387a53 /libs/plugins/a-comp.lv2 | |
parent | b27d9bb02a38bf2c6024823feff003d681e2ca69 (diff) |
a-comp: Add stereo version
Diffstat (limited to 'libs/plugins/a-comp.lv2')
-rw-r--r-- | libs/plugins/a-comp.lv2/a-comp#stereo.ttl.in | 157 | ||||
-rw-r--r-- | libs/plugins/a-comp.lv2/a-comp.c | 264 | ||||
-rw-r--r-- | libs/plugins/a-comp.lv2/a-comp.ttl.in | 61 | ||||
-rw-r--r-- | libs/plugins/a-comp.lv2/manifest.ttl.in | 25 | ||||
-rw-r--r-- | libs/plugins/a-comp.lv2/wscript | 2 |
5 files changed, 448 insertions, 61 deletions
diff --git a/libs/plugins/a-comp.lv2/a-comp#stereo.ttl.in b/libs/plugins/a-comp.lv2/a-comp#stereo.ttl.in new file mode 100644 index 0000000000..438a87e1e1 --- /dev/null +++ b/libs/plugins/a-comp.lv2/a-comp#stereo.ttl.in @@ -0,0 +1,157 @@ +@prefix doap: <http://usefulinc.com/ns/doap#> . +@prefix foaf: <http://xmlns.com/foaf/0.1/> . +@prefix lv2: <http://lv2plug.in/ns/lv2core#> . +@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> . +@prefix rsz: <http://lv2plug.in/ns/ext/resize-port#> . +@prefix ui: <http://lv2plug.in/ns/extensions/ui#> . +@prefix unit: <http://lv2plug.in/ns/extensions/units#> . + +<http://ardour.org/credits.html> + a foaf:Person ; + foaf:name "Ardour Team" ; + foaf:homepage <http://ardour.org/> . + +<urn:ardour:a-comp#stereo> + a lv2:Plugin, doap:Project, lv2:CompressorPlugin ; + + lv2:optionalFeature <http://lv2plug.in/ns/lv2core#hardRTCapable>; + + lv2:port [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 0 ; + lv2:name "Attack" ; + lv2:symbol "att" ; + lv2:default 10.000000 ; + lv2:minimum 0.100000 ; + lv2:maximum 100.000000 ; + unit:unit unit:ms ; + ] , + [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 1 ; + lv2:name "Release" ; + lv2:symbol "rel" ; + lv2:default 80.000000 ; + lv2:minimum 1.000000 ; + lv2:maximum 500.000000 ; + unit:unit unit:ms ; + ] , + [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 2 ; + lv2:name "Knee" ; + lv2:symbol "kn" ; + lv2:default 0.000000 ; + lv2:minimum 0.000000 ; + lv2:maximum 8.000000 ; + unit:unit unit:db ; + ] , + [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 3 ; + lv2:name "Ratio" ; + lv2:symbol "rat" ; + lv2:default 4.000000 ; + lv2:minimum 1.000000 ; + lv2:maximum 20.000000 ; + unit:unit [ + rdfs:label " " ; + unit:symbol " " ; + unit:render "%f " ; + ] ; + ] , + [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 4 ; + lv2:name "Threshold" ; + lv2:symbol "thr" ; + lv2:default 0.000000 ; + lv2:minimum -60.000000 ; + lv2:maximum 0.000000 ; + unit:unit unit:db ; + ] , + [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 5 ; + lv2:name "Makeup" ; + lv2:symbol "mak" ; + lv2:default 0.000000 ; + lv2:minimum 0.000000 ; + lv2:maximum 30.000000 ; + unit:unit unit:db ; + ] , + [ + a lv2:OutputPort, lv2:ControlPort ; + lv2:index 6 ; + lv2:name "Gain Reduction" ; + lv2:symbol "gr" ; + lv2:default 0.000000 ; + lv2:minimum 0.000000 ; + lv2:maximum 45.000000 ; + unit:unit unit:db ; + ] , + [ + a lv2:OutputPort, lv2:ControlPort ; + lv2:index 7 ; + lv2:name "Output Level" ; + lv2:symbol "outlevel" ; + lv2:default -45.000000 ; + lv2:minimum -45.000000 ; + lv2:maximum 0.000000 ; + unit:unit unit:db ; + ] , + [ + a lv2:InputPort, lv2:ControlPort ; + lv2:index 8 ; + lv2:name "Sidechain" ; + lv2:symbol "sidech" ; + lv2:default 0.000000 ; + lv2:minimum 0.000000 ; + lv2:maximum 1.000000 ; + lv2:portProperty lv2:toggled ; + ] ; + + lv2:port [ + a lv2:InputPort, lv2:AudioPort ; + lv2:index 9 ; + lv2:symbol "in_1" ; + lv2:name "Audio Input 1" ; + ] , + [ + a lv2:InputPort, lv2:AudioPort ; + lv2:index 10 ; + lv2:symbol "in_2" ; + lv2:name "Audio Input 2" ; + ] , + [ + a lv2:InputPort, lv2:AudioPort ; + lv2:index 11 ; + lv2:symbol "sidechain_in" ; + lv2:name "Sidechain Input" ; + lv2:portProperty lv2:isSideChain; + ], + [ + a lv2:OutputPort, lv2:AudioPort ; + lv2:index 12 ; + lv2:symbol "out_1" ; + lv2:name "Audio Output 1" ; + ], + [ + a lv2:OutputPort, lv2:AudioPort ; + lv2:index 13 ; + lv2:symbol "out_2" ; + lv2:name "Audio Output 2" ; + ] ; + + rdfs:comment """ +A powerful stereo compressor. +""" ; + + doap:name "a-comp stereo" ; + doap:license "GPL v2+" ; + doap:maintainer <http://ardour.org/credits.html> + +# ui:ui <urn:ardour:a-comp#ui>; + + lv2:microVersion 1 ; + lv2:minorVersion 1 . diff --git a/libs/plugins/a-comp.lv2/a-comp.c b/libs/plugins/a-comp.lv2/a-comp.c index 6870b20c4e..9449c2741e 100644 --- a/libs/plugins/a-comp.lv2/a-comp.c +++ b/libs/plugins/a-comp.lv2/a-comp.c @@ -24,14 +24,11 @@ #include "lv2/lv2plug.in/ns/lv2core/lv2.h" -#define ACOMP_URI "urn:ardour:a-comp" +#define ACOMP_URI "urn:ardour:a-comp" +#define ACOMP_STEREO_URI "urn:ardour:a-comp#stereo" typedef enum { - ACOMP_INPUT0 = 0, - ACOMP_INPUT1, - ACOMP_OUTPUT, - - ACOMP_ATTACK, + ACOMP_ATTACK = 0, ACOMP_RELEASE, ACOMP_KNEE, ACOMP_RATIO, @@ -41,14 +38,32 @@ typedef enum { ACOMP_GAINR, ACOMP_OUTLEVEL, ACOMP_SIDECHAIN, -} PortIndex; + ACOMP_INPUT, + ACOMP_SC, + ACOMP_OUTPUT, +} PortIndexMono; -typedef struct { - float* input0; - float* input1; - float* output; +typedef enum { + ACOMP_STEREO_ATTACK = 0, + ACOMP_STEREO_RELEASE, + ACOMP_STEREO_KNEE, + ACOMP_STEREO_RATIO, + ACOMP_STEREO_THRESHOLD, + ACOMP_STEREO_MAKEUP, + + ACOMP_STEREO_GAINR, + ACOMP_STEREO_OUTLEVEL, + ACOMP_STEREO_SIDECHAIN, + + ACOMP_STEREO_INPUT0, + ACOMP_STEREO_INPUT1, + ACOMP_STEREO_SC, + ACOMP_STEREO_OUTPUT0, + ACOMP_STEREO_OUTPUT1, +} PortIndexStereo; +typedef struct { float* attack; float* release; float* knee; @@ -60,6 +75,12 @@ typedef struct { float* outlevel; float* sidechain; + float* input0; + float* input1; + float* sc; + float* output0; + float* output1; + float srate; float old_yl; float old_y1; @@ -108,14 +129,15 @@ instantiate(const LV2_Descriptor* descriptor, return (LV2_Handle)acomp; } + static void -connect_port(LV2_Handle instance, +connect_port_mono(LV2_Handle instance, uint32_t port, void* data) { AComp* acomp = (AComp*)instance; - switch ((PortIndex)port) { + switch ((PortIndexMono)port) { case ACOMP_ATTACK: acomp->attack = (float*)data; break; @@ -143,14 +165,67 @@ connect_port(LV2_Handle instance, case ACOMP_SIDECHAIN: acomp->sidechain = (float*)data; break; - case ACOMP_INPUT0: + case ACOMP_INPUT: acomp->input0 = (float*)data; break; - case ACOMP_INPUT1: - acomp->input1 = (float*)data; + case ACOMP_SC: + acomp->sc = (float*)data; break; case ACOMP_OUTPUT: - acomp->output = (float*)data; + acomp->output0 = (float*)data; + break; + } +} + +static void +connect_port_stereo(LV2_Handle instance, + uint32_t port, + void* data) +{ + AComp* acomp = (AComp*)instance; + + switch ((PortIndexStereo)port) { + case ACOMP_STEREO_ATTACK: + acomp->attack = (float*)data; + break; + case ACOMP_STEREO_RELEASE: + acomp->release = (float*)data; + break; + case ACOMP_STEREO_KNEE: + acomp->knee = (float*)data; + break; + case ACOMP_STEREO_RATIO: + acomp->ratio = (float*)data; + break; + case ACOMP_STEREO_THRESHOLD: + acomp->thresdb = (float*)data; + break; + case ACOMP_STEREO_MAKEUP: + acomp->makeup = (float*)data; + break; + case ACOMP_STEREO_GAINR: + acomp->gainr = (float*)data; + break; + case ACOMP_STEREO_OUTLEVEL: + acomp->outlevel = (float*)data; + break; + case ACOMP_STEREO_SIDECHAIN: + acomp->sidechain = (float*)data; + break; + case ACOMP_STEREO_INPUT0: + acomp->input0 = (float*)data; + break; + case ACOMP_STEREO_INPUT1: + acomp->input1 = (float*)data; + break; + case ACOMP_STEREO_SC: + acomp->sc = (float*)data; + break; + case ACOMP_STEREO_OUTPUT0: + acomp->output0 = (float*)data; + break; + case ACOMP_STEREO_OUTPUT1: + acomp->output1 = (float*)data; break; } } @@ -185,13 +260,13 @@ activate(LV2_Handle instance) } static void -run(LV2_Handle instance, uint32_t n_samples) +run_mono(LV2_Handle instance, uint32_t n_samples) { AComp* acomp = (AComp*)instance; - const float* const input0 = acomp->input0; - const float* const input1 = acomp->input1; - float* const output = acomp->output; + const float* const input = acomp->input0; + const float* const sc = acomp->sc; + float* const output = acomp->output0; float srate = acomp->srate; float width = (6.f * *(acomp->knee)) + 0.01; @@ -207,7 +282,7 @@ run(LV2_Handle instance, uint32_t n_samples) uint32_t i; float ingain; float in0; - float in1; + float sc0; float ratio = *(acomp->ratio); float thresdb = *(acomp->thresdb); @@ -231,9 +306,9 @@ run(LV2_Handle instance, uint32_t n_samples) float in_peak = 0; for (i = 0; i < n_samples; i++) { - in0 = input0[i]; - in1 = input1[i]; - ingain = usesidechain ? in1 : in0; + in0 = input[i]; + sc0 = sc[i]; + ingain = usesidechain ? sc0 : in0; Lyg = 0.f; Lxg = (ingain==0.f) ? -160.f : to_dB(fabs(ingain)); Lxg = sanitize_denormal(Lxg); @@ -296,6 +371,124 @@ run(LV2_Handle instance, uint32_t n_samples) } static void +run_stereo(LV2_Handle instance, uint32_t n_samples) +{ + AComp* acomp = (AComp*)instance; + + const float* const input0 = acomp->input0; + const float* const input1 = acomp->input1; + const float* const sc = acomp->sc; + float* const output0 = acomp->output0; + float* const output1 = acomp->output1; + + float srate = acomp->srate; + float width = (6.f * *(acomp->knee)) + 0.01; + float cdb=0.f; + float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate)); + float release_coeff = exp(-1000.f/(*(acomp->release) * srate)); + + float max = 0.f; + float lgaininp = 0.f; + float rgaininp = 0.f; + float Lgain = 1.f; + float Lxg, Lxl, Lyg, Lyl, Ly1; + int usesidechain = (*(acomp->sidechain) < 0.5) ? 0 : 1; + uint32_t i; + float ingain; + float in0; + float in1; + float sc0; + float ratio = *(acomp->ratio); + float thresdb = *(acomp->thresdb); + +#ifdef LV2_EXTENDED + if (acomp->v_knee != *acomp->knee) { + acomp->v_knee = *acomp->knee; + acomp->need_expose = true; + } + + if (acomp->v_ratio != *acomp->ratio) { + acomp->v_ratio = *acomp->ratio; + acomp->need_expose = true; + } + + if (acomp->v_thresdb != *acomp->thresdb) { + acomp->v_thresdb = *acomp->thresdb; + acomp->need_expose = true; + } +#endif + + float in_peak = 0; + + for (i = 0; i < n_samples; i++) { + in0 = input0[i]; + in1 = input1[i]; + sc0 = sc[i]; + ingain = usesidechain ? fabs(sc0) : fmaxf(fabs(in0), fabs(in1)); + Lyg = 0.f; + Lxg = (ingain==0.f) ? -160.f : to_dB(ingain); + Lxg = sanitize_denormal(Lxg); + + Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width); + + if (2.f*(Lxg-thresdb) < -width) { + Lyg = Lxg; + } else { + Lyg = thresdb + (Lxg-thresdb)/ratio; + Lyg = sanitize_denormal(Lyg); + } + + Lxl = Lxg - Lyg; + + acomp->old_y1 = sanitize_denormal(acomp->old_y1); + acomp->old_yl = sanitize_denormal(acomp->old_yl); + Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl); + Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1; + Ly1 = sanitize_denormal(Ly1); + Lyl = sanitize_denormal(Lyl); + + cdb = -Lyl; + Lgain = from_dB(cdb); + + *(acomp->gainr) = Lyl; + + if (ingain > in_peak) { + in_peak = ingain; + } + lgaininp = in0 * Lgain; + rgaininp = in1 * Lgain; + output0[i] = lgaininp * from_dB(*(acomp->makeup)); + output1[i] = rgaininp * from_dB(*(acomp->makeup)); + + max = (fmaxf(fabsf(output0[i]), fabsf(output1[i])) > max) ? fmaxf(fabsf(output0[i]), fabsf(output1[i])) : sanitize_denormal(max); + + // TODO re-use local variables on stack + // store values back to acomp at the end of the inner-loop + acomp->old_yl = Lyl; + acomp->old_y1 = Ly1; + acomp->old_yg = Lyg; + } + + *(acomp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max); + +#ifdef LV2_EXTENDED + acomp->v_lvl += .1 * (in_peak - acomp->v_lvl); // crude LPF TODO use n_samples/rate TC + const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl); + const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max); + if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) { + // >= 1dB difference + acomp->need_expose = true; + acomp->v_lvl_in = v_lvl_in; + acomp->v_lvl_out = v_lvl_out - *acomp->makeup; + } + if (acomp->need_expose && acomp->queue_draw) { + acomp->need_expose = false; + acomp->queue_draw->queue_draw (acomp->queue_draw->handle); + } +#endif +} + +static void deactivate(LV2_Handle instance) { activate(instance); @@ -464,12 +657,23 @@ extension_data(const char* uri) return NULL; } -static const LV2_Descriptor descriptor = { +static const LV2_Descriptor descriptor_mono = { ACOMP_URI, instantiate, - connect_port, + connect_port_mono, + activate, + run_mono, + deactivate, + cleanup, + extension_data +}; + +static const LV2_Descriptor descriptor_stereo = { + ACOMP_STEREO_URI, + instantiate, + connect_port_stereo, activate, - run, + run_stereo, deactivate, cleanup, extension_data @@ -481,7 +685,9 @@ lv2_descriptor(uint32_t index) { switch (index) { case 0: - return &descriptor; + return &descriptor_mono; + case 1: + return &descriptor_stereo; default: return NULL; } diff --git a/libs/plugins/a-comp.lv2/a-comp.ttl.in b/libs/plugins/a-comp.lv2/a-comp.ttl.in index 703cb25572..fed9d87307 100644 --- a/libs/plugins/a-comp.lv2/a-comp.ttl.in +++ b/libs/plugins/a-comp.lv2/a-comp.ttl.in @@ -17,29 +17,8 @@ lv2:optionalFeature <http://lv2plug.in/ns/lv2core#hardRTCapable>; lv2:port [ - a lv2:InputPort, lv2:AudioPort ; - lv2:index 0 ; - lv2:symbol "lv2_audio_in_1" ; - lv2:name "Audio Input 1" ; - ] , - [ - a lv2:InputPort, lv2:AudioPort ; - lv2:index 1 ; - lv2:symbol "lv2_sidechain_in" ; - lv2:name "Sidechain Input" ; - lv2:portProperty lv2:isSideChain; - ] ; - - lv2:port [ - a lv2:OutputPort, lv2:AudioPort ; - lv2:index 2 ; - lv2:symbol "lv2_audio_out_1" ; - lv2:name "Audio Output 1" ; - ] ; - - lv2:port [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 3 ; + lv2:index 0 ; lv2:name "Attack" ; lv2:symbol "att" ; lv2:default 10.000000 ; @@ -49,7 +28,7 @@ ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 4 ; + lv2:index 1 ; lv2:name "Release" ; lv2:symbol "rel" ; lv2:default 80.000000 ; @@ -59,7 +38,7 @@ ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 5 ; + lv2:index 2 ; lv2:name "Knee" ; lv2:symbol "kn" ; lv2:default 0.000000 ; @@ -69,7 +48,7 @@ ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 6 ; + lv2:index 3 ; lv2:name "Ratio" ; lv2:symbol "rat" ; lv2:default 4.000000 ; @@ -83,7 +62,7 @@ ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 7 ; + lv2:index 4 ; lv2:name "Threshold" ; lv2:symbol "thr" ; lv2:default 0.000000 ; @@ -93,7 +72,7 @@ ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 8 ; + lv2:index 5 ; lv2:name "Makeup" ; lv2:symbol "mak" ; lv2:default 0.000000 ; @@ -103,7 +82,7 @@ ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 9 ; + lv2:index 6 ; lv2:name "Gain Reduction" ; lv2:symbol "gr" ; lv2:default 0.000000 ; @@ -113,7 +92,7 @@ ] , [ a lv2:OutputPort, lv2:ControlPort ; - lv2:index 10 ; + lv2:index 7 ; lv2:name "Output Level" ; lv2:symbol "outlevel" ; lv2:default -45.000000 ; @@ -123,7 +102,7 @@ ] , [ a lv2:InputPort, lv2:ControlPort ; - lv2:index 11 ; + lv2:index 8 ; lv2:name "Sidechain" ; lv2:symbol "sidech" ; lv2:default 0.000000 ; @@ -132,6 +111,26 @@ lv2:portProperty lv2:toggled ; ] ; + lv2:port [ + a lv2:InputPort, lv2:AudioPort ; + lv2:index 9 ; + lv2:symbol "lv2_audio_in_1" ; + lv2:name "Audio Input 1" ; + ] , + [ + a lv2:InputPort, lv2:AudioPort ; + lv2:index 10 ; + lv2:symbol "lv2_sidechain_in" ; + lv2:name "Sidechain Input" ; + lv2:portProperty lv2:isSideChain; + ], + [ + a lv2:OutputPort, lv2:AudioPort ; + lv2:index 11 ; + lv2:symbol "lv2_audio_out_1" ; + lv2:name "Audio Output 1" ; + ] ; + rdfs:comment """ A powerful mono compressor. """ ; @@ -142,5 +141,5 @@ A powerful mono compressor. # ui:ui <urn:ardour:a-comp#ui>; - lv2:microVersion 0 ; + lv2:microVersion 1 ; lv2:minorVersion 1 . diff --git a/libs/plugins/a-comp.lv2/manifest.ttl.in b/libs/plugins/a-comp.lv2/manifest.ttl.in index 73cacd4dbf..de71199617 100644 --- a/libs/plugins/a-comp.lv2/manifest.ttl.in +++ b/libs/plugins/a-comp.lv2/manifest.ttl.in @@ -8,6 +8,11 @@ lv2:binary <a-comp@LIB_EXT@> ; rdfs:seeAlso <a-comp.ttl> . +<urn:ardour:a-comp#stereo> + a lv2:Plugin ; + lv2:binary <a-comp@LIB_EXT@> ; + rdfs:seeAlso <a-comp#stereo.ttl> . + #<urn:ardour:a-comp#ui> # a ui:GtkUI ; # ui:binary <a-comp-ui@LIB_EXT@> ; @@ -30,3 +35,23 @@ lv2:appliesTo <urn:ardour:a-comp> ; rdfs:label "VocalLeveller" ; rdfs:seeAlso <presets.ttl> . + + + +<urn:ardour:a-comp#preset001> + a pset:Preset ; + lv2:appliesTo <urn:ardour:a-comp#stereo> ; + rdfs:label "Zero" ; + rdfs:seeAlso <presets.ttl> . + +<urn:ardour:a-comp#preset002> + a pset:Preset ; + lv2:appliesTo <urn:ardour:a-comp#stereo> ; + rdfs:label "PoppySnare" ; + rdfs:seeAlso <presets.ttl> . + +<urn:ardour:a-comp#preset003> + a pset:Preset ; + lv2:appliesTo <urn:ardour:a-comp#stereo> ; + rdfs:label "VocalLeveller" ; + rdfs:seeAlso <presets.ttl> . diff --git a/libs/plugins/a-comp.lv2/wscript b/libs/plugins/a-comp.lv2/wscript index 9d33d16507..4c8cdc1434 100644 --- a/libs/plugins/a-comp.lv2/wscript +++ b/libs/plugins/a-comp.lv2/wscript @@ -26,7 +26,7 @@ def build(bld): if bld.is_defined ('HAVE_LV2'): # Build RDF files - for i in ['manifest.ttl', 'a-comp.ttl', 'presets.ttl']: + for i in ['manifest.ttl', 'a-comp.ttl', 'a-comp#stereo.ttl', 'presets.ttl']: bld(features = 'subst', source = i + '.in', target = '../../LV2/%s/%s' % (bundle, i), |