77895410f251f4f704642ff3f47531bff45c03b3
[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         bool                     need_expose;
91         LV2_Inline_Display_Image_Surface surf;
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         acomp->need_expose = true;
128
129         return (LV2_Handle)acomp;
130 }
131
132
133 static void
134 connect_port_mono(LV2_Handle instance,
135              uint32_t port,
136              void* data)
137 {
138         AComp* acomp = (AComp*)instance;
139
140         switch ((PortIndexMono)port) {
141         case ACOMP_ATTACK:
142                 acomp->attack = (float*)data;
143                 break;
144         case ACOMP_RELEASE:
145                 acomp->release = (float*)data;
146                 break;
147         case ACOMP_KNEE:
148                 acomp->knee = (float*)data;
149                 break;
150         case ACOMP_RATIO:
151                 acomp->ratio = (float*)data;
152                 break;
153         case ACOMP_THRESHOLD:
154                 acomp->thresdb = (float*)data;
155                 break;
156         case ACOMP_MAKEUP:
157                 acomp->makeup = (float*)data;
158                 break;
159         case ACOMP_GAINR:
160                 acomp->gainr = (float*)data;
161                 break;
162         case ACOMP_OUTLEVEL:
163                 acomp->outlevel = (float*)data;
164                 break;
165         case ACOMP_SIDECHAIN:
166                 acomp->sidechain = (float*)data;
167                 break;
168         case ACOMP_INPUT:
169                 acomp->input0 = (float*)data;
170                 break;
171         case ACOMP_SC:
172                 acomp->sc = (float*)data;
173                 break;
174         case ACOMP_OUTPUT:
175                 acomp->output0 = (float*)data;
176                 break;
177         }
178 }
179
180 static void
181 connect_port_stereo(LV2_Handle instance,
182              uint32_t port,
183              void* data)
184 {
185         AComp* acomp = (AComp*)instance;
186
187         switch ((PortIndexStereo)port) {
188         case ACOMP_STEREO_ATTACK:
189                 acomp->attack = (float*)data;
190                 break;
191         case ACOMP_STEREO_RELEASE:
192                 acomp->release = (float*)data;
193                 break;
194         case ACOMP_STEREO_KNEE:
195                 acomp->knee = (float*)data;
196                 break;
197         case ACOMP_STEREO_RATIO:
198                 acomp->ratio = (float*)data;
199                 break;
200         case ACOMP_STEREO_THRESHOLD:
201                 acomp->thresdb = (float*)data;
202                 break;
203         case ACOMP_STEREO_MAKEUP:
204                 acomp->makeup = (float*)data;
205                 break;
206         case ACOMP_STEREO_GAINR:
207                 acomp->gainr = (float*)data;
208                 break;
209         case ACOMP_STEREO_OUTLEVEL:
210                 acomp->outlevel = (float*)data;
211                 break;
212         case ACOMP_STEREO_SIDECHAIN:
213                 acomp->sidechain = (float*)data;
214                 break;
215         case ACOMP_STEREO_INPUT0:
216                 acomp->input0 = (float*)data;
217                 break;
218         case ACOMP_STEREO_INPUT1:
219                 acomp->input1 = (float*)data;
220                 break;
221         case ACOMP_STEREO_SC:
222                 acomp->sc = (float*)data;
223                 break;
224         case ACOMP_STEREO_OUTPUT0:
225                 acomp->output0 = (float*)data;
226                 break;
227         case ACOMP_STEREO_OUTPUT1:
228                 acomp->output1 = (float*)data;
229                 break;
230         }
231 }
232
233 // Force already-denormal float value to zero
234 static inline float
235 sanitize_denormal(float value) {
236         if (!isnormal(value)) {
237                 value = 0.f;
238         }
239         return value;
240 }
241
242 static inline float
243 from_dB(float gdb) {
244         return (exp(gdb/20.f*log(10.f)));
245 }
246
247 static inline float
248 to_dB(float g) {
249         return (20.f*log10(g));
250 }
251
252 static void
253 activate(LV2_Handle instance)
254 {
255         AComp* acomp = (AComp*)instance;
256
257         *(acomp->gainr) = 0.0f;
258         *(acomp->outlevel) = -45.0f;
259         acomp->old_yl=acomp->old_y1=acomp->old_yg=0.f;
260 }
261
262 static void
263 run_mono(LV2_Handle instance, uint32_t n_samples)
264 {
265         AComp* acomp = (AComp*)instance;
266
267         const float* const input = acomp->input0;
268         const float* const sc = acomp->sc;
269         float* const output = acomp->output0;
270
271         float srate = acomp->srate;
272         float width = (6.f * *(acomp->knee)) + 0.01;
273         float cdb=0.f;
274         float attack_coeff = exp(-1000.f/(*(acomp->attack) * srate));
275         float release_coeff = exp(-1000.f/(*(acomp->release) * srate));
276
277         float max = 0.f;
278         float lgaininp = 0.f;
279         float Lgain = 1.f;
280         float Lxg, Lxl, Lyg, Lyl, Ly1;
281         int usesidechain = (*(acomp->sidechain) < 0.5) ? 0 : 1;
282         uint32_t i;
283         float ingain;
284         float in0;
285         float sc0;
286         float ratio = *(acomp->ratio);
287         float thresdb = *(acomp->thresdb);
288
289 #ifdef LV2_EXTENDED
290         if (acomp->v_knee != *acomp->knee) {
291                 acomp->v_knee = *acomp->knee;
292                 acomp->need_expose = true;
293         }
294
295         if (acomp->v_ratio != *acomp->ratio) {
296                 acomp->v_ratio = *acomp->ratio;
297                 acomp->need_expose = true;
298         }
299
300         if (acomp->v_thresdb != *acomp->thresdb) {
301                 acomp->v_thresdb = *acomp->thresdb;
302                 acomp->need_expose = true;
303         }
304 #endif
305
306         float in_peak = 0;
307
308         for (i = 0; i < n_samples; i++) {
309                 in0 = input[i];
310                 sc0 = sc[i];
311                 ingain = usesidechain ? fabs(sc0) : fabs(in0);
312                 Lyg = 0.f;
313                 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
314                 Lxg = sanitize_denormal(Lxg);
315
316                 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
317
318                 if (2.f*(Lxg-thresdb) < -width) {
319                         Lyg = Lxg;
320                 } else {
321                         Lyg = thresdb + (Lxg-thresdb)/ratio;
322                         Lyg = sanitize_denormal(Lyg);
323                 }
324
325                 Lxl = Lxg - Lyg;
326
327                 acomp->old_y1 = sanitize_denormal(acomp->old_y1);
328                 acomp->old_yl = sanitize_denormal(acomp->old_yl);
329                 Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
330                 Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
331                 Ly1 = sanitize_denormal(Ly1);
332                 Lyl = sanitize_denormal(Lyl);
333
334                 cdb = -Lyl;
335                 Lgain = from_dB(cdb);
336
337                 *(acomp->gainr) = Lyl;
338
339                 if (ingain > in_peak) {
340                         in_peak = ingain;
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                 Lyg = 0.f;
431                 Lxg = (ingain==0.f) ? -160.f : to_dB(ingain);
432                 Lxg = sanitize_denormal(Lxg);
433
434                 Lyg = Lxg + (1.f/ratio-1.f)*(Lxg-thresdb+width/2.f)*(Lxg-thresdb+width/2.f)/(2.f*width);
435
436                 if (2.f*(Lxg-thresdb) < -width) {
437                         Lyg = Lxg;
438                 } else {
439                         Lyg = thresdb + (Lxg-thresdb)/ratio;
440                         Lyg = sanitize_denormal(Lyg);
441                 }
442
443                 Lxl = Lxg - Lyg;
444
445                 acomp->old_y1 = sanitize_denormal(acomp->old_y1);
446                 acomp->old_yl = sanitize_denormal(acomp->old_yl);
447                 Ly1 = fmaxf(Lxl, release_coeff * acomp->old_y1+(1.f-release_coeff)*Lxl);
448                 Lyl = attack_coeff * acomp->old_yl+(1.f-attack_coeff)*Ly1;
449                 Ly1 = sanitize_denormal(Ly1);
450                 Lyl = sanitize_denormal(Lyl);
451
452                 cdb = -Lyl;
453                 Lgain = from_dB(cdb);
454
455                 *(acomp->gainr) = Lyl;
456
457                 if (ingain > in_peak) {
458                         in_peak = ingain;
459                 }
460                 lgaininp = in0 * Lgain;
461                 rgaininp = in1 * Lgain;
462                 output0[i] = lgaininp * from_dB(*(acomp->makeup));
463                 output1[i] = rgaininp * from_dB(*(acomp->makeup));
464
465                 max = (fmaxf(fabs(output0[i]), fabs(output1[i])) > max) ? fmaxf(fabs(output0[i]), fabs(output1[i])) : sanitize_denormal(max);
466
467                 // TODO re-use local variables on stack
468                 // store values back to acomp at the end of the inner-loop
469                 acomp->old_yl = Lyl;
470                 acomp->old_y1 = Ly1;
471                 acomp->old_yg = Lyg;
472         }
473
474         *(acomp->outlevel) = (max < 0.0056f) ? -45.f : to_dB(max);
475
476 #ifdef LV2_EXTENDED
477         acomp->v_lvl += .1 * (in_peak - acomp->v_lvl);  // crude LPF TODO use n_samples/rate TC
478         const float v_lvl_in = (acomp->v_lvl < 0.001f) ? -60.f : to_dB(acomp->v_lvl);
479         const float v_lvl_out = (max < 0.001f) ? -60.f : to_dB(max);
480         if (fabsf (acomp->v_lvl_out - v_lvl_out) >= 1 || fabsf (acomp->v_lvl_in - v_lvl_in) >= 1) {
481                 // >= 1dB difference
482                 acomp->need_expose = true;
483                 acomp->v_lvl_in = v_lvl_in;
484                 acomp->v_lvl_out = v_lvl_out - *acomp->makeup;
485         }
486         if (acomp->need_expose && acomp->queue_draw) {
487                 acomp->need_expose = false;
488                 acomp->queue_draw->queue_draw (acomp->queue_draw->handle);
489         }
490 #endif
491 }
492
493 static void
494 deactivate(LV2_Handle instance)
495 {
496         activate(instance);
497 }
498
499 static void
500 cleanup(LV2_Handle instance)
501 {
502 #ifdef LV2_EXTENDED
503         AComp* acomp = (AComp*)instance;
504         if (acomp->display) {
505                 cairo_surface_destroy (acomp->display);
506         }
507 #endif
508
509         free(instance);
510 }
511
512
513 #ifndef MIN
514 #define MIN(A,B) ((A) < (B)) ? (A) : (B)
515 #endif
516
517 #ifdef LV2_EXTENDED
518 static float
519 comp_curve (AComp* self, float xg) {
520         const float knee = self->v_knee;
521         const float ratio = self->v_ratio;
522         const float thresdb = self->v_thresdb;
523
524         const float width = 6.f * knee + 0.01f;
525         float yg = 0.f;
526
527         if (2.f * (xg - thresdb) < -width) {
528                 yg = xg;
529         } else if (2.f * fabs (xg - thresdb) <= width) {
530                 yg = xg + (1.f / ratio - 1.f ) * (xg - thresdb + width / 2.f) * (xg - thresdb + width / 2.f) / (2.f * width);
531         } else if (2.f * (xg - thresdb) > width) {
532                 yg = thresdb + (xg - thresdb) / ratio;
533         }
534         return yg;
535 }
536
537 static LV2_Inline_Display_Image_Surface *
538 render_inline (LV2_Handle instance, uint32_t w, uint32_t max_h)
539 {
540         AComp* self = (AComp*)instance;
541         uint32_t h = MIN (w, max_h);
542
543         if (!self->display || self->w != w || self->h != h) {
544                 if (self->display) cairo_surface_destroy(self->display);
545                 self->display = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, w, h);
546                 self->w = w;
547                 self->h = h;
548         }
549
550         cairo_t* cr = cairo_create (self->display);
551
552         // clear background
553         cairo_rectangle (cr, 0, 0, w, h);
554         cairo_set_source_rgba (cr, .2, .2, .2, 1.0);
555         cairo_fill (cr);
556
557         cairo_set_line_width(cr, 1.0);
558
559         // draw grid 10dB steps
560         const double dash1[] = {1, 2};
561         const double dash2[] = {1, 3};
562         cairo_save (cr);
563         cairo_set_line_cap(cr, CAIRO_LINE_CAP_ROUND);
564         cairo_set_dash(cr, dash2, 2, 2);
565         cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
566
567         for (uint32_t d = 1; d < 6; ++d) {
568                 const float x = -.5 + floorf (w * (d * 10.f / 60.f));
569                 const float y = -.5 + floorf (h * (d * 10.f / 60.f));
570
571                 cairo_move_to (cr, x, 0);
572                 cairo_line_to (cr, x, h);
573                 cairo_stroke (cr);
574
575                 cairo_move_to (cr, 0, y);
576                 cairo_line_to (cr, w, y);
577                 cairo_stroke (cr);
578         }
579         if (self->v_thresdb < 0) {
580                 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 1.0);
581                 const float y = -.5 + floorf (h * (self->v_thresdb / -60.f));
582                 cairo_set_dash(cr, dash1, 2, 2);
583                 cairo_move_to (cr, 0, y);
584                 cairo_line_to (cr, w, y);
585                 cairo_stroke (cr);
586                 cairo_move_to (cr, 0, h);
587                 cairo_line_to (cr, w, 0);
588                 cairo_stroke (cr);
589         }
590         cairo_restore (cr);
591
592
593         // draw curve
594         cairo_set_source_rgba (cr, .8, .8, .8, 1.0);
595         cairo_move_to (cr, 0, h);
596
597         for (uint32_t x = 0; x < w; ++x) {
598                 // plot -60..0  dB
599                 const float x_db = 60.f * (-1.f + x / (float)w);
600                 const float y_db = comp_curve (self, x_db);
601                 const float y = h * (y_db / -60.f);
602                 cairo_line_to (cr, x, y);
603         }
604         cairo_stroke_preserve (cr);
605
606         cairo_line_to (cr, w, h);
607         cairo_close_path (cr);
608         cairo_clip (cr);
609
610         // draw signal level & reduction/gradient
611         const float top = comp_curve (self, 0);
612         cairo_pattern_t* pat = cairo_pattern_create_linear (0.0, 0.0, 0.0, h);
613         if (top > self->v_thresdb) {
614                 cairo_pattern_add_color_stop_rgba (pat, 0.0, 0.8, 0.1, 0.1, 0.5);
615                 cairo_pattern_add_color_stop_rgba (pat, top / -60.f, 0.8, 0.1, 0.1, 0.5);
616         }
617         if (self->v_knee > 0) {
618                 cairo_pattern_add_color_stop_rgba (pat, (self->v_thresdb / -60.f), 0.7, 0.7, 0.2, 0.5);
619                 cairo_pattern_add_color_stop_rgba (pat, ((self->v_thresdb - self->v_knee) / -60.f), 0.5, 0.5, 0.5, 0.5);
620         } else {
621                 cairo_pattern_add_color_stop_rgba (pat, (self->v_thresdb / -60.f), 0.7, 0.7, 0.2, 0.5);
622                 cairo_pattern_add_color_stop_rgba (pat, ((self->v_thresdb - .01) / -60.f), 0.5, 0.5, 0.5, 0.5);
623         }
624         cairo_pattern_add_color_stop_rgba (pat, 1.0, 0.5, 0.5, 0.5, 0.5);
625
626         // maybe cut off at x-position?
627         const float x = w * (self->v_lvl_in + 60) / 60.f;
628         const float y = h * (self->v_lvl_out + 60) / 60.f;
629         cairo_rectangle (cr, 0, h - y, x, y);
630         if (self->v_ratio > 1.0) {
631                 cairo_set_source (cr, pat);
632         } else {
633                 cairo_set_source_rgba (cr, 0.5, 0.5, 0.5, 0.5);
634         }
635         cairo_fill (cr);
636
637         cairo_pattern_destroy (pat); // TODO cache pattern
638
639
640         // create RGBA surface
641         cairo_destroy (cr);
642         cairo_surface_flush (self->display);
643         self->surf.width = cairo_image_surface_get_width (self->display);
644         self->surf.height = cairo_image_surface_get_height (self->display);
645         self->surf.stride = cairo_image_surface_get_stride (self->display);
646         self->surf.data = cairo_image_surface_get_data  (self->display);
647
648         return &self->surf;
649 }
650 #endif
651
652 static const void*
653 extension_data(const char* uri)
654 {
655         static const LV2_Inline_Display_Interface display  = { render_inline };
656         if (!strcmp(uri, LV2_INLINEDISPLAY__interface)) {
657                 return &display;
658         }
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 }