4456a4f63dedf601d45acfa73eb52319f9cf449e
[ardour.git] / libs / plugins / a-comp.lv2 / a-comp.c
1 /* a-comp
2  * Copyright (C) 2016 Damien Zammit <damien@zamaudio.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  */
14
15 #include <math.h>
16 #include <stdlib.h>
17 #include <string.h>
18 #include <stdbool.h>
19
20 #ifdef LV2_EXTENDED
21 #include <cairo/cairo.h>
22 #include "ardour/lv2_extensions.h"
23 #endif
24
25 #include "lv2/lv2plug.in/ns/lv2core/lv2.h"
26
27 #define ACOMP_URI               "urn:ardour:a-comp"
28 #define ACOMP_STEREO_URI        "urn:ardour:a-comp#stereo"
29
30 typedef enum {
31         ACOMP_ATTACK = 0,
32         ACOMP_RELEASE,
33         ACOMP_KNEE,
34         ACOMP_RATIO,
35         ACOMP_THRESHOLD,
36         ACOMP_MAKEUP,
37
38         ACOMP_GAINR,
39         ACOMP_OUTLEVEL,
40         ACOMP_SIDECHAIN,
41
42         ACOMP_INPUT,
43         ACOMP_SC,
44         ACOMP_OUTPUT,
45 } PortIndexMono;
46
47 typedef enum {
48         ACOMP_STEREO_ATTACK = 0,
49         ACOMP_STEREO_RELEASE,
50         ACOMP_STEREO_KNEE,
51         ACOMP_STEREO_RATIO,
52         ACOMP_STEREO_THRESHOLD,
53         ACOMP_STEREO_MAKEUP,
54
55         ACOMP_STEREO_GAINR,
56         ACOMP_STEREO_OUTLEVEL,
57         ACOMP_STEREO_SIDECHAIN,
58
59         ACOMP_STEREO_INPUT0,
60         ACOMP_STEREO_INPUT1,
61         ACOMP_STEREO_SC,
62         ACOMP_STEREO_OUTPUT0,
63         ACOMP_STEREO_OUTPUT1,
64 } PortIndexStereo;
65
66 typedef struct {
67         float* attack;
68         float* release;
69         float* knee;
70         float* ratio;
71         float* thresdb;
72         float* makeup;
73
74         float* gainr;
75         float* outlevel;
76         float* sidechain;
77
78         float* input0;
79         float* input1;
80         float* sc;
81         float* output0;
82         float* output1;
83
84         float srate;
85         float old_yl;
86         float old_y1;
87         float old_yg;
88
89 #ifdef LV2_EXTENDED
90         LV2_Inline_Display_Image_Surface surf;
91         bool                     need_expose;
92         cairo_surface_t*         display;
93         LV2_Inline_Display*      queue_draw;
94         uint32_t                 w, h;
95
96         /* ports pointers are only valid during run so we'll
97          * have to cache them for the display, besides
98          * we do want to check for changes
99          */
100         float v_knee;
101         float v_ratio;
102         float v_thresdb;
103         float v_lvl;
104         float v_lvl_in;
105         float v_lvl_out;
106 #endif
107 } AComp;
108
109 static LV2_Handle
110 instantiate(const LV2_Descriptor* descriptor,
111             double rate,
112             const char* bundle_path,
113             const LV2_Feature* const* features)
114 {
115         AComp* acomp = (AComp*)calloc(1, sizeof(AComp));
116
117         for (int i=0; features[i]; ++i) {
118 #ifdef LV2_EXTENDED
119                 if (!strcmp(features[i]->URI, LV2_INLINEDISPLAY__queue_draw)) {
120                         acomp->queue_draw = (LV2_Inline_Display*) features[i]->data;
121                 }
122 #endif
123         }
124
125         acomp->srate = rate;
126         acomp->old_yl=acomp->old_y1=acomp->old_yg=0.f;
127 #ifdef LV2_EXTENDED
128         acomp->need_expose = true;
129 #endif
130
131         return (LV2_Handle)acomp;
132 }
133
134
135 static void
136 connect_port_mono(LV2_Handle instance,
137              uint32_t port,
138              void* data)
139 {
140         AComp* acomp = (AComp*)instance;
141
142         switch ((PortIndexMono)port) {
143         case ACOMP_ATTACK:
144                 acomp->attack = (float*)data;
145                 break;
146         case ACOMP_RELEASE:
147                 acomp->release = (float*)data;
148                 break;
149         case ACOMP_KNEE:
150                 acomp->knee = (float*)data;
151                 break;
152         case ACOMP_RATIO:
153                 acomp->ratio = (float*)data;
154                 break;
155         case ACOMP_THRESHOLD:
156                 acomp->thresdb = (float*)data;
157                 break;
158         case ACOMP_MAKEUP:
159                 acomp->makeup = (float*)data;
160                 break;
161         case ACOMP_GAINR:
162                 acomp->gainr = (float*)data;
163                 break;
164         case ACOMP_OUTLEVEL:
165                 acomp->outlevel = (float*)data;
166                 break;
167         case ACOMP_SIDECHAIN:
168                 acomp->sidechain = (float*)data;
169                 break;
170         case ACOMP_INPUT:
171                 acomp->input0 = (float*)data;
172                 break;
173         case ACOMP_SC:
174                 acomp->sc = (float*)data;
175                 break;
176         case ACOMP_OUTPUT:
177                 acomp->output0 = (float*)data;
178                 break;
179         }
180 }
181
182 static void
183 connect_port_stereo(LV2_Handle instance,
184              uint32_t port,
185              void* data)
186 {
187         AComp* acomp = (AComp*)instance;
188
189         switch ((PortIndexStereo)port) {
190         case ACOMP_STEREO_ATTACK:
191                 acomp->attack = (float*)data;
192                 break;
193         case ACOMP_STEREO_RELEASE:
194                 acomp->release = (float*)data;
195                 break;
196         case ACOMP_STEREO_KNEE:
197                 acomp->knee = (float*)data;
198                 break;
199         case ACOMP_STEREO_RATIO:
200                 acomp->ratio = (float*)data;
201                 break;
202         case ACOMP_STEREO_THRESHOLD:
203                 acomp->thresdb = (float*)data;
204                 break;
205         case ACOMP_STEREO_MAKEUP:
206                 acomp->makeup = (float*)data;
207                 break;
208         case ACOMP_STEREO_GAINR:
209                 acomp->gainr = (float*)data;
210                 break;
211         case ACOMP_STEREO_OUTLEVEL:
212                 acomp->outlevel = (float*)data;
213                 break;
214         case ACOMP_STEREO_SIDECHAIN:
215                 acomp->sidechain = (float*)data;
216                 break;
217         case ACOMP_STEREO_INPUT0:
218                 acomp->input0 = (float*)data;
219                 break;
220         case ACOMP_STEREO_INPUT1:
221                 acomp->input1 = (float*)data;
222                 break;
223         case ACOMP_STEREO_SC:
224                 acomp->sc = (float*)data;
225                 break;
226         case ACOMP_STEREO_OUTPUT0:
227                 acomp->output0 = (float*)data;
228                 break;
229         case ACOMP_STEREO_OUTPUT1:
230                 acomp->output1 = (float*)data;
231                 break;
232         }
233 }
234
235 // Force already-denormal float value to zero
236 static inline float
237 sanitize_denormal(float value) {
238         if (!isnormal(value)) {
239                 value = 0.f;
240         }
241         return value;
242 }
243
244 static inline float
245 from_dB(float gdb) {
246         return (exp(gdb/20.f*log(10.f)));
247 }
248
249 static inline float
250 to_dB(float g) {
251         return (20.f*log10(g));
252 }
253
254 static void
255 activate(LV2_Handle instance)
256 {
257         AComp* acomp = (AComp*)instance;
258
259         *(acomp->gainr) = 0.0f;
260         *(acomp->outlevel) = -45.0f;
261         acomp->old_yl=acomp->old_y1=acomp->old_yg=0.f;
262 }
263
264 static void
265 run_mono(LV2_Handle instance, uint32_t n_samples)
266 {
267         AComp* acomp = (AComp*)instance;
268
269         const float* const input = acomp->input0;
270         const float* const sc = acomp->sc;
271         float* const output = acomp->output0;
272
273         float srate = acomp->srate;
274         float width = (6.f * *(acomp->knee)) + 0.01;
275         float cdb=0.f;
276         float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
277         float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
278
279         float max = 0.f;
280         float lgaininp = 0.f;
281         float Lgain = 1.f;
282         float Lxg, Lxl, Lyg, Lyl, Ly1;
283         int usesidechain = (*(acomp->sidechain) < 0.5) ? 0 : 1;
284         uint32_t i;
285         float ingain;
286         float in0;
287         float sc0;
288         float ratio = *(acomp->ratio);
289         float thresdb = *(acomp->thresdb);
290
291 #ifdef LV2_EXTENDED
292         if (acomp->v_knee != *acomp->knee) {
293                 acomp->v_knee = *acomp->knee;
294                 acomp->need_expose = true;
295         }
296
297         if (acomp->v_ratio != *acomp->ratio) {
298                 acomp->v_ratio = *acomp->ratio;
299                 acomp->need_expose = true;
300         }
301
302         if (acomp->v_thresdb != *acomp->thresdb) {
303                 acomp->v_thresdb = *acomp->thresdb;
304                 acomp->need_expose = true;
305         }
306 #endif
307
308         float in_peak = 0;
309
310         for (i = 0; i < n_samples; i++) {
311                 in0 = input[i];
312                 sc0 = sc[i];
313                 ingain = usesidechain ? fabs(sc0) : fabs(in0);
314                 in_peak = fmaxf (in_peak, ingain);
315                 Lyg = 0.f;
316                 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
317                 Lxg = sanitize_denormal(Lxg);
318
319                 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
320
321                 if (2.f*(Lxg-thresdb) < -width) {
322                         Lyg = Lxg;
323                 } else {
324                         Lyg = thresdb + (Lxg-thresdb)/ratio;
325                         Lyg = sanitize_denormal(Lyg);
326                 }
327
328                 Lxl = Lxg - Lyg;
329
330                 acomp->old_y1 = sanitize_denormal(acomp->old_y1);
331                 acomp->old_yl = sanitize_denormal(acomp->old_yl);
332                 Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
333                 Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
334                 Ly1 = sanitize_denormal(Ly1);
335                 Lyl = sanitize_denormal(Lyl);
336
337                 cdb = -Lyl;
338                 Lgain = from_dB(cdb);
339
340                 *(acomp->gainr) = Lyl;
341
342                 lgaininp = in0 * Lgain;
343                 output[i] = lgaininp * from_dB(*(acomp->makeup));
344
345                 max = (fabsf(output[i]) > max) ? fabsf(output[i]) : sanitize_denormal(max);
346
347                 // TODO re-use local variables on stack
348                 // store values back to acomp at the end of the inner-loop
349                 acomp->old_yl = Lyl;
350                 acomp->old_y1 = Ly1;
351                 acomp->old_yg = Lyg;
352         }
353
354         *(acomp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max);
355
356 #ifdef LV2_EXTENDED
357         acomp->v_lvl += .1 * (in_peak - acomp->v_lvl);  // crude LPF TODO use n_samples/rate TC
358         const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
359         const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
360         if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {
361                 // >= 1dB difference
362                 acomp->need_expose = true;
363                 acomp->v_lvl_in = v_lvl_in;
364                 acomp->v_lvl_out = v_lvl_out - *acomp->makeup;
365         }
366         if (acomp->need_expose && acomp->queue_draw) {
367                 acomp->need_expose = false;
368                 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
369         }
370 #endif
371 }
372
373 static void
374 run_stereo(LV2_Handle instance, uint32_t n_samples)
375 {
376         AComp* acomp = (AComp*)instance;
377
378         const float* const input0 = acomp->input0;
379         const float* const input1 = acomp->input1;
380         const float* const sc = acomp->sc;
381         float* const output0 = acomp->output0;
382         float* const output1 = acomp->output1;
383
384         float srate = acomp->srate;
385         float width = (6.f * *(acomp->knee)) + 0.01;
386         float cdb=0.f;
387         float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
388         float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
389
390         float max = 0.f;
391         float lgaininp = 0.f;
392         float rgaininp = 0.f;
393         float Lgain = 1.f;
394         float Lxg, Lxl, Lyg, Lyl, Ly1;
395         int usesidechain = (*(acomp->sidechain) < 0.5) ? 0 : 1;
396         uint32_t i;
397         float ingain;
398         float in0;
399         float in1;
400         float sc0;
401         float maxabslr;
402         float ratio = *(acomp->ratio);
403         float thresdb = *(acomp->thresdb);
404
405 #ifdef LV2_EXTENDED
406         if (acomp->v_knee != *acomp->knee) {
407                 acomp->v_knee = *acomp->knee;
408                 acomp->need_expose = true;
409         }
410
411         if (acomp->v_ratio != *acomp->ratio) {
412                 acomp->v_ratio = *acomp->ratio;
413                 acomp->need_expose = true;
414         }
415
416         if (acomp->v_thresdb != *acomp->thresdb) {
417                 acomp->v_thresdb = *acomp->thresdb;
418                 acomp->need_expose = true;
419         }
420 #endif
421
422         float in_peak = 0;
423
424         for (i = 0; i < n_samples; i++) {
425                 in0 = input0[i];
426                 in1 = input1[i];
427                 sc0 = sc[i];
428                 maxabslr = fmaxf(fabs(in0), fabs(in1));
429                 ingain = usesidechain ? fabs(sc0) : maxabslr;
430                 in_peak = fmaxf (in_peak, ingain);
431                 Lyg = 0.f;
432                 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
433                 Lxg = sanitize_denormal(Lxg);
434
435                 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
436
437                 if (2.f*(Lxg-thresdb) < -width) {
438                         Lyg = Lxg;
439                 } else {
440                         Lyg = thresdb + (Lxg-thresdb)/ratio;
441                         Lyg = sanitize_denormal(Lyg);
442                 }
443
444                 Lxl = Lxg - Lyg;
445
446                 acomp->old_y1 = sanitize_denormal(acomp->old_y1);
447                 acomp->old_yl = sanitize_denormal(acomp->old_yl);
448                 Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
449                 Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
450                 Ly1 = sanitize_denormal(Ly1);
451                 Lyl = sanitize_denormal(Lyl);
452
453                 cdb = -Lyl;
454                 Lgain = from_dB(cdb);
455
456                 *(acomp->gainr) = Lyl;
457
458                 lgaininp = in0 * Lgain;
459                 rgaininp = in1 * Lgain;
460                 output0[i] = lgaininp * from_dB(*(acomp->makeup));
461                 output1[i] = rgaininp * from_dB(*(acomp->makeup));
462
463                 max = (fmaxf(fabs(output0[i]), fabs(output1[i])) > max) ? fmaxf(fabs(output0[i]), fabs(output1[i])) : sanitize_denormal(max);
464
465                 // TODO re-use local variables on stack
466                 // store values back to acomp at the end of the inner-loop
467                 acomp->old_yl = Lyl;
468                 acomp->old_y1 = Ly1;
469                 acomp->old_yg = Lyg;
470         }
471
472         *(acomp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max);
473
474 #ifdef LV2_EXTENDED
475         acomp->v_lvl += .1 * (in_peak - acomp->v_lvl);  // crude LPF TODO use n_samples/rate TC
476         const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
477         const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
478         if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {
479                 // >= 1dB difference
480                 acomp->need_expose = true;
481                 acomp->v_lvl_in = v_lvl_in;
482                 acomp->v_lvl_out = v_lvl_out - *acomp->makeup;
483         }
484         if (acomp->need_expose && acomp->queue_draw) {
485                 acomp->need_expose = false;
486                 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
487         }
488 #endif
489 }
490
491 static void
492 deactivate(LV2_Handle instance)
493 {
494         activate(instance);
495 }
496
497 static void
498 cleanup(LV2_Handle instance)
499 {
500 #ifdef LV2_EXTENDED
501         AComp* acomp = (AComp*)instance;
502         if (acomp->display) {
503                 cairo_surface_destroy (acomp->display);
504         }
505 #endif
506
507         free(instance);
508 }
509
510
511 #ifndef MIN
512 #define MIN(A,B) ((A) < (B)) ? (A) : (B)
513 #endif
514
515 #ifdef LV2_EXTENDED
516 static float
517 comp_curve (AComp* self, float xg) {
518         const float knee = self->v_knee;
519         const float ratio = self->v_ratio;
520         const float thresdb = self->v_thresdb;
521
522         const float width = 6.f * knee + 0.01f;
523         float yg = 0.f;
524
525         if (2.f * (xg - thresdb) < -width) {
526                 yg = xg;
527         } else if (2.f * fabs (xg - thresdb) <= width) {
528                 yg = xg + (1.f / ratio - 1.f ) * (xg - thresdb + width / 2.f) * (xg - thresdb + width / 2.f) / (2.f * width);
529         } else if (2.f * (xg - thresdb) > width) {
530                 yg = thresdb + (xg - thresdb) / ratio;
531         }
532         return yg;
533 }
534
535 static LV2_Inline_Display_Image_Surface *
536 render_inline (LV2_Handle instance, uint32_t w, uint32_t max_h)
537 {
538         AComp* self = (AComp*)instance;
539         uint32_t h = MIN (w, max_h);
540
541         if (!self->display || self->w != w || self->h != h) {
542                 if (self->display) cairo_surface_destroy(self->display);
543                 self->display = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
544                 self->w = w;
545                 self->h = h;
546         }
547
548         cairo_t* cr = cairo_create (self->display);
549
550         // clear background
551         cairo_rectangle (cr, 0, 0, w, h);
552         cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
553         cairo_fill (cr);
554
555         cairo_set_line_width(cr, 1.0);
556
557         // draw grid 10dB steps
558         const double dash1[] = {1, 2};
559         const double dash2[] = {1, 3};
560         cairo_save (cr);
561         cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
562         cairo_set_dash(cr, dash2, 2, 2);
563         cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
564
565         for (uint32_t d = 1; d < 6; ++d) {
566                 const float x = -.5 + floorf (w * (d * 10.f / 60.f));
567                 const float y = -.5 + floorf (h * (d * 10.f / 60.f));
568
569                 cairo_move_to (cr, x, 0);
570                 cairo_line_to (cr, x, h);
571                 cairo_stroke (cr);
572
573                 cairo_move_to (cr, 0, y);
574                 cairo_line_to (cr, w, y);
575                 cairo_stroke (cr);
576         }
577         if (self->v_thresdb < 0) {
578                 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
579                 const float y = -.5 + floorf (h * (self->v_thresdb / -60.f));
580                 cairo_set_dash(cr, dash1, 2, 2);
581                 cairo_move_to (cr, 0, y);
582                 cairo_line_to (cr, w, y);
583                 cairo_stroke (cr);
584                 cairo_move_to (cr, 0, h);
585                 cairo_line_to (cr, w, 0);
586                 cairo_stroke (cr);
587         }
588         cairo_restore (cr);
589
590
591         // draw curve
592         cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
593         cairo_move_to (cr, 0, h);
594
595         for (uint32_t x = 0; x < w; ++x) {
596                 // plot -60..0  dB
597                 const float x_db = 60.f * (-1.f + x / (float)w);
598                 const float y_db = comp_curve (self, x_db);
599                 const float y = h * (y_db / -60.f);
600                 cairo_line_to (cr, x, y);
601         }
602         cairo_stroke_preserve (cr);
603
604         cairo_line_to (cr, w, h);
605         cairo_close_path (cr);
606         cairo_clip (cr);
607
608         // draw signal level & reduction/gradient
609         const float top = comp_curve (self, 0);
610         cairo_pattern_t* pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, h);
611         if (top > self->v_thresdb) {
612                 cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.8, 0.1, 0.1, 0.5);
613                 cairo_pattern_add_color_stop_rgba (pat, top / -60.f, 0.8, 0.1, 0.1, 0.5);
614         }
615         if (self->v_knee > 0) {
616                 cairo_pattern_add_color_stop_rgba (pat, (self->v_thresdb / -60.f), 0.7, 0.7, 0.2, 0.5);
617                 cairo_pattern_add_color_stop_rgba (pat, ((self->v_thresdb - self->v_knee) / -60.f), 0.5, 0.5, 0.5, 0.5);
618         } else {
619                 cairo_pattern_add_color_stop_rgba (pat, (self->v_thresdb / -60.f), 0.7, 0.7, 0.2, 0.5);
620                 cairo_pattern_add_color_stop_rgba (pat, ((self->v_thresdb - .01) / -60.f), 0.5, 0.5, 0.5, 0.5);
621         }
622         cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.5, 0.5, 0.5, 0.5);
623
624         // maybe cut off at x-position?
625         const float x = w * (self->v_lvl_in + 60) / 60.f;
626         const float y = h * (self->v_lvl_out + 60) / 60.f;
627         cairo_rectangle (cr, 0, h - x, x, h);
628         if (self->v_ratio > 1.0) {
629                 cairo_set_source (cr, pat);
630         } else {
631                 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
632         }
633         cairo_fill (cr);
634
635         cairo_pattern_destroy (pat); // TODO cache pattern
636
637
638         // create RGBA surface
639         cairo_destroy (cr);
640         cairo_surface_flush (self->display);
641         self->surf.width = cairo_image_surface_get_width (self->display);
642         self->surf.height = cairo_image_surface_get_height (self->display);
643         self->surf.stride = cairo_image_surface_get_stride (self->display);
644         self->surf.data = cairo_image_surface_get_data  (self->display);
645
646         return &self->surf;
647 }
648 #endif
649
650 static const void*
651 extension_data(const char* uri)
652 {
653 #ifdef LV2_EXTENDED
654         static const LV2_Inline_Display_Interface display  = { render_inline };
655         if (!strcmp(uri, LV2_INLINEDISPLAY__interface)) {
656                 return &display;
657         }
658 #endif
659         return NULL;
660 }
661
662 static const LV2_Descriptor descriptor_mono = {
663         ACOMP_URI,
664         instantiate,
665         connect_port_mono,
666         activate,
667         run_mono,
668         deactivate,
669         cleanup,
670         extension_data
671 };
672
673 static const LV2_Descriptor descriptor_stereo = {
674         ACOMP_STEREO_URI,
675         instantiate,
676         connect_port_stereo,
677         activate,
678         run_stereo,
679         deactivate,
680         cleanup,
681         extension_data
682 };
683
684 LV2_SYMBOL_EXPORT
685 const LV2_Descriptor*
686 lv2_descriptor(uint32_t index)
687 {
688         switch (index) {
689         case 0:
690                 return &descriptor_mono;
691         case 1:
692                 return &descriptor_stereo;
693         default:
694                 return NULL;
695         }
696 }