~ubuntu-branches/ubuntu/trusty/lmms/trusty

« back to all changes in this revision

Viewing changes to plugins/ladspa_effect/swh/plate_1423.c

  • Committer: Charlie Smotherman
  • Date: 2012-12-05 22:08:38 UTC
  • mfrom: (33.1.7 lmms_0.4.13)
  • Revision ID: cjsmo@cableone.net-20121205220838-09pjfzew9m5023hr
* New  Upstream release.
  - Minor tweaking to ZynAddSubFX, CALF, SWH plugins  and Stefan Fendt's RC
    filters.
  - Added UI fixes: Magnentic effect of knobs and Piano-roll fixes
  - Updated German localization and copyright year
* debian/lmms-common.install:
  - added /usr/share/applications so the lmms.desktop file will correctly
    install (LP: #863366)
  - This should also fix the Software Center not displaying lmms in sound
    and video (LP: #824231)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include <stdlib.h>
 
2
#include <string.h>
 
3
#ifndef WIN32
 
4
#include "config.h"
 
5
#endif
 
6
 
 
7
#ifdef ENABLE_NLS
 
8
#include <libintl.h>
 
9
#endif
 
10
 
 
11
#define         _ISOC9X_SOURCE  1
 
12
#define         _ISOC99_SOURCE  1
 
13
#define         __USE_ISOC99    1
 
14
#define         __USE_ISOC9X    1
 
15
 
 
16
#include <math.h>
 
17
 
 
18
#include "ladspa.h"
 
19
 
 
20
#ifdef WIN32
 
21
#define _WINDOWS_DLL_EXPORT_ __declspec(dllexport)
 
22
int bIsFirstTime = 1; 
 
23
void _init(); // forward declaration
 
24
#else
 
25
#define _WINDOWS_DLL_EXPORT_ 
 
26
#endif
 
27
 
 
28
#line 10 "plate_1423.xml"
 
29
 
 
30
#include "util/waveguide_nl.h"
 
31
 
 
32
#define LP_INNER 0.96f
 
33
#define LP_OUTER 0.983f
 
34
 
 
35
#define RUN_WG(n, junct_a, junct_b) waveguide_nl_process_lin(w[n], junct_a - out[n*2+1], junct_b - out[n*2], out+n*2, out+n*2+1)
 
36
 
 
37
#define PLATE_TIME                     0
 
38
#define PLATE_DAMPING                  1
 
39
#define PLATE_WET                      2
 
40
#define PLATE_INPUT                    3
 
41
#define PLATE_OUTPUTL                  4
 
42
#define PLATE_OUTPUTR                  5
 
43
 
 
44
static LADSPA_Descriptor *plateDescriptor = NULL;
 
45
 
 
46
typedef struct {
 
47
        LADSPA_Data *time;
 
48
        LADSPA_Data *damping;
 
49
        LADSPA_Data *wet;
 
50
        LADSPA_Data *input;
 
51
        LADSPA_Data *outputl;
 
52
        LADSPA_Data *outputr;
 
53
        float *      out;
 
54
        waveguide_nl **w;
 
55
        LADSPA_Data run_adding_gain;
 
56
} Plate;
 
57
 
 
58
_WINDOWS_DLL_EXPORT_
 
59
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
 
60
 
 
61
#ifdef WIN32
 
62
        if (bIsFirstTime) {
 
63
                _init();
 
64
                bIsFirstTime = 0;
 
65
        }
 
66
#endif
 
67
        switch (index) {
 
68
        case 0:
 
69
                return plateDescriptor;
 
70
        default:
 
71
                return NULL;
 
72
        }
 
73
}
 
74
 
 
75
static void activatePlate(LADSPA_Handle instance) {
 
76
        Plate *plugin_data = (Plate *)instance;
 
77
        float *out = plugin_data->out;
 
78
        waveguide_nl **w = plugin_data->w;
 
79
#line 40 "plate_1423.xml"
 
80
        unsigned int i;
 
81
 
 
82
        for (i = 0; i < 8; i++) {
 
83
          waveguide_nl_reset(w[i]);
 
84
        }
 
85
        plugin_data->out = out;
 
86
        plugin_data->w = w;
 
87
 
 
88
}
 
89
 
 
90
static void cleanupPlate(LADSPA_Handle instance) {
 
91
#line 85 "plate_1423.xml"
 
92
        Plate *plugin_data = (Plate *)instance;
 
93
        unsigned int i;
 
94
 
 
95
        for (i = 0; i < 8; i++) {
 
96
          waveguide_nl_free(plugin_data->w[i]);
 
97
        }
 
98
        free(plugin_data->w);
 
99
        free(plugin_data->out);
 
100
        free(instance);
 
101
}
 
102
 
 
103
static void connectPortPlate(
 
104
 LADSPA_Handle instance,
 
105
 unsigned long port,
 
106
 LADSPA_Data *data) {
 
107
        Plate *plugin;
 
108
 
 
109
        plugin = (Plate *)instance;
 
110
        switch (port) {
 
111
        case PLATE_TIME:
 
112
                plugin->time = data;
 
113
                break;
 
114
        case PLATE_DAMPING:
 
115
                plugin->damping = data;
 
116
                break;
 
117
        case PLATE_WET:
 
118
                plugin->wet = data;
 
119
                break;
 
120
        case PLATE_INPUT:
 
121
                plugin->input = data;
 
122
                break;
 
123
        case PLATE_OUTPUTL:
 
124
                plugin->outputl = data;
 
125
                break;
 
126
        case PLATE_OUTPUTR:
 
127
                plugin->outputr = data;
 
128
                break;
 
129
        }
 
130
}
 
131
 
 
132
static LADSPA_Handle instantiatePlate(
 
133
 const LADSPA_Descriptor *descriptor,
 
134
 unsigned long s_rate) {
 
135
        Plate *plugin_data = (Plate *)malloc(sizeof(Plate));
 
136
        float *out = NULL;
 
137
        waveguide_nl **w = NULL;
 
138
 
 
139
#line 26 "plate_1423.xml"
 
140
        w = malloc(8 * sizeof(waveguide_nl *));
 
141
        w[0] = waveguide_nl_new(2389, LP_INNER, 0.04f, 0.0f);
 
142
        w[1] = waveguide_nl_new(4742, LP_INNER, 0.17f, 0.0f);
 
143
        w[2] = waveguide_nl_new(4623, LP_INNER, 0.52f, 0.0f);
 
144
        w[3] = waveguide_nl_new(2142, LP_INNER, 0.48f, 0.0f);
 
145
        w[4] = waveguide_nl_new(5597, LP_OUTER, 0.32f, 0.0f);
 
146
        w[5] = waveguide_nl_new(3692, LP_OUTER, 0.89f, 0.0f);
 
147
        w[6] = waveguide_nl_new(5611, LP_OUTER, 0.28f, 0.0f);
 
148
        w[7] = waveguide_nl_new(3703, LP_OUTER, 0.29f, 0.0f);
 
149
 
 
150
        out = calloc(32, sizeof(float));
 
151
 
 
152
        plugin_data->out = out;
 
153
        plugin_data->w = w;
 
154
 
 
155
        return (LADSPA_Handle)plugin_data;
 
156
}
 
157
 
 
158
#undef buffer_write
 
159
#undef RUN_ADDING
 
160
#undef RUN_REPLACING
 
161
 
 
162
#define buffer_write(b, v) (b = v)
 
163
#define RUN_ADDING    0
 
164
#define RUN_REPLACING 1
 
165
 
 
166
static void runPlate(LADSPA_Handle instance, unsigned long sample_count) {
 
167
        Plate *plugin_data = (Plate *)instance;
 
168
 
 
169
        /* Reverb time (float value) */
 
170
        const LADSPA_Data time = *(plugin_data->time);
 
171
 
 
172
        /* Damping (float value) */
 
173
        const LADSPA_Data damping = *(plugin_data->damping);
 
174
 
 
175
        /* Dry/wet mix (float value) */
 
176
        const LADSPA_Data wet = *(plugin_data->wet);
 
177
 
 
178
        /* Input (array of floats of length sample_count) */
 
179
        const LADSPA_Data * const input = plugin_data->input;
 
180
 
 
181
        /* Left output (array of floats of length sample_count) */
 
182
        LADSPA_Data * const outputl = plugin_data->outputl;
 
183
 
 
184
        /* Right output (array of floats of length sample_count) */
 
185
        LADSPA_Data * const outputr = plugin_data->outputr;
 
186
        float * out = plugin_data->out;
 
187
        waveguide_nl ** w = plugin_data->w;
 
188
 
 
189
#line 48 "plate_1423.xml"
 
190
        unsigned long pos;
 
191
        const float scale = powf(time * 0.117647f, 1.34f);
 
192
        const float lpscale = 1.0f - damping * 0.93;
 
193
 
 
194
        for (pos=0; pos<8; pos++) {
 
195
          waveguide_nl_set_delay(w[pos], w[pos]->size * scale);
 
196
        }
 
197
        for (pos=0; pos<4; pos++) {
 
198
          waveguide_nl_set_fc(w[pos], LP_INNER * lpscale);
 
199
        }
 
200
        for (; pos<8; pos++) {
 
201
          waveguide_nl_set_fc(w[pos], LP_OUTER * lpscale);
 
202
        }
 
203
 
 
204
        for (pos = 0; pos < sample_count; pos++) {
 
205
          const float alpha = (out[0] + out[2] + out[4] + out[6]) * 0.5f
 
206
                              + input[pos];
 
207
          const float beta = (out[1] + out[9] + out[14]) * 0.666666666f;
 
208
          const float gamma = (out[3] + out[8] + out[11]) * 0.666666666f;
 
209
          const float delta = (out[5] + out[10] + out[13]) * 0.666666666f;
 
210
          const float epsilon = (out[7] + out[12] + out[15]) * 0.666666666f;
 
211
 
 
212
          RUN_WG(0, beta, alpha);
 
213
          RUN_WG(1, gamma, alpha);
 
214
          RUN_WG(2, delta, alpha);
 
215
          RUN_WG(3, epsilon, alpha);
 
216
          RUN_WG(4, beta, gamma);
 
217
          RUN_WG(5, gamma, delta);
 
218
          RUN_WG(6, delta, epsilon);
 
219
          RUN_WG(7, epsilon, beta);
 
220
 
 
221
          buffer_write(outputl[pos], beta * wet + input[pos] * (1.0f - wet));
 
222
          buffer_write(outputr[pos], gamma * wet + input[pos] * (1.0f - wet));
 
223
        }
 
224
}
 
225
#undef buffer_write
 
226
#undef RUN_ADDING
 
227
#undef RUN_REPLACING
 
228
 
 
229
#define buffer_write(b, v) (b += (v) * run_adding_gain)
 
230
#define RUN_ADDING    1
 
231
#define RUN_REPLACING 0
 
232
 
 
233
static void setRunAddingGainPlate(LADSPA_Handle instance, LADSPA_Data gain) {
 
234
        ((Plate *)instance)->run_adding_gain = gain;
 
235
}
 
236
 
 
237
static void runAddingPlate(LADSPA_Handle instance, unsigned long sample_count) {
 
238
        Plate *plugin_data = (Plate *)instance;
 
239
        LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
 
240
 
 
241
        /* Reverb time (float value) */
 
242
        const LADSPA_Data time = *(plugin_data->time);
 
243
 
 
244
        /* Damping (float value) */
 
245
        const LADSPA_Data damping = *(plugin_data->damping);
 
246
 
 
247
        /* Dry/wet mix (float value) */
 
248
        const LADSPA_Data wet = *(plugin_data->wet);
 
249
 
 
250
        /* Input (array of floats of length sample_count) */
 
251
        const LADSPA_Data * const input = plugin_data->input;
 
252
 
 
253
        /* Left output (array of floats of length sample_count) */
 
254
        LADSPA_Data * const outputl = plugin_data->outputl;
 
255
 
 
256
        /* Right output (array of floats of length sample_count) */
 
257
        LADSPA_Data * const outputr = plugin_data->outputr;
 
258
        float * out = plugin_data->out;
 
259
        waveguide_nl ** w = plugin_data->w;
 
260
 
 
261
#line 48 "plate_1423.xml"
 
262
        unsigned long pos;
 
263
        const float scale = powf(time * 0.117647f, 1.34f);
 
264
        const float lpscale = 1.0f - damping * 0.93;
 
265
 
 
266
        for (pos=0; pos<8; pos++) {
 
267
          waveguide_nl_set_delay(w[pos], w[pos]->size * scale);
 
268
        }
 
269
        for (pos=0; pos<4; pos++) {
 
270
          waveguide_nl_set_fc(w[pos], LP_INNER * lpscale);
 
271
        }
 
272
        for (; pos<8; pos++) {
 
273
          waveguide_nl_set_fc(w[pos], LP_OUTER * lpscale);
 
274
        }
 
275
 
 
276
        for (pos = 0; pos < sample_count; pos++) {
 
277
          const float alpha = (out[0] + out[2] + out[4] + out[6]) * 0.5f
 
278
                              + input[pos];
 
279
          const float beta = (out[1] + out[9] + out[14]) * 0.666666666f;
 
280
          const float gamma = (out[3] + out[8] + out[11]) * 0.666666666f;
 
281
          const float delta = (out[5] + out[10] + out[13]) * 0.666666666f;
 
282
          const float epsilon = (out[7] + out[12] + out[15]) * 0.666666666f;
 
283
 
 
284
          RUN_WG(0, beta, alpha);
 
285
          RUN_WG(1, gamma, alpha);
 
286
          RUN_WG(2, delta, alpha);
 
287
          RUN_WG(3, epsilon, alpha);
 
288
          RUN_WG(4, beta, gamma);
 
289
          RUN_WG(5, gamma, delta);
 
290
          RUN_WG(6, delta, epsilon);
 
291
          RUN_WG(7, epsilon, beta);
 
292
 
 
293
          buffer_write(outputl[pos], beta * wet + input[pos] * (1.0f - wet));
 
294
          buffer_write(outputr[pos], gamma * wet + input[pos] * (1.0f - wet));
 
295
        }
 
296
}
 
297
 
 
298
void _init() {
 
299
        char **port_names;
 
300
        LADSPA_PortDescriptor *port_descriptors;
 
301
        LADSPA_PortRangeHint *port_range_hints;
 
302
 
 
303
#ifdef ENABLE_NLS
 
304
#define D_(s) dgettext(PACKAGE, s)
 
305
        setlocale(LC_ALL, "");
 
306
        bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
 
307
#else
 
308
#define D_(s) (s)
 
309
#endif
 
310
 
 
311
 
 
312
        plateDescriptor =
 
313
         (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
 
314
 
 
315
        if (plateDescriptor) {
 
316
                plateDescriptor->UniqueID = 1423;
 
317
                plateDescriptor->Label = "plate";
 
318
                plateDescriptor->Properties =
 
319
                 LADSPA_PROPERTY_HARD_RT_CAPABLE;
 
320
                plateDescriptor->Name =
 
321
                 D_("Plate reverb");
 
322
                plateDescriptor->Maker =
 
323
                 "Steve Harris <steve@plugin.org.uk>";
 
324
                plateDescriptor->Copyright =
 
325
                 "GPL";
 
326
                plateDescriptor->PortCount = 6;
 
327
 
 
328
                port_descriptors = (LADSPA_PortDescriptor *)calloc(6,
 
329
                 sizeof(LADSPA_PortDescriptor));
 
330
                plateDescriptor->PortDescriptors =
 
331
                 (const LADSPA_PortDescriptor *)port_descriptors;
 
332
 
 
333
                port_range_hints = (LADSPA_PortRangeHint *)calloc(6,
 
334
                 sizeof(LADSPA_PortRangeHint));
 
335
                plateDescriptor->PortRangeHints =
 
336
                 (const LADSPA_PortRangeHint *)port_range_hints;
 
337
 
 
338
                port_names = (char **)calloc(6, sizeof(char*));
 
339
                plateDescriptor->PortNames =
 
340
                 (const char **)port_names;
 
341
 
 
342
                /* Parameters for Reverb time */
 
343
                port_descriptors[PLATE_TIME] =
 
344
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
345
                port_names[PLATE_TIME] =
 
346
                 D_("Reverb time");
 
347
                port_range_hints[PLATE_TIME].HintDescriptor =
 
348
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE;
 
349
                port_range_hints[PLATE_TIME].LowerBound = 0.01;
 
350
                port_range_hints[PLATE_TIME].UpperBound = 8.5;
 
351
 
 
352
                /* Parameters for Damping */
 
353
                port_descriptors[PLATE_DAMPING] =
 
354
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
355
                port_names[PLATE_DAMPING] =
 
356
                 D_("Damping");
 
357
                port_range_hints[PLATE_DAMPING].HintDescriptor =
 
358
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_LOW;
 
359
                port_range_hints[PLATE_DAMPING].LowerBound = 0;
 
360
                port_range_hints[PLATE_DAMPING].UpperBound = 1;
 
361
 
 
362
                /* Parameters for Dry/wet mix */
 
363
                port_descriptors[PLATE_WET] =
 
364
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
365
                port_names[PLATE_WET] =
 
366
                 D_("Dry/wet mix");
 
367
                port_range_hints[PLATE_WET].HintDescriptor =
 
368
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_LOW;
 
369
                port_range_hints[PLATE_WET].LowerBound = 0;
 
370
                port_range_hints[PLATE_WET].UpperBound = 1;
 
371
 
 
372
                /* Parameters for Input */
 
373
                port_descriptors[PLATE_INPUT] =
 
374
                 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
 
375
                port_names[PLATE_INPUT] =
 
376
                 D_("Input");
 
377
                port_range_hints[PLATE_INPUT].HintDescriptor = 0;
 
378
 
 
379
                /* Parameters for Left output */
 
380
                port_descriptors[PLATE_OUTPUTL] =
 
381
                 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
 
382
                port_names[PLATE_OUTPUTL] =
 
383
                 D_("Left output");
 
384
                port_range_hints[PLATE_OUTPUTL].HintDescriptor = 0;
 
385
 
 
386
                /* Parameters for Right output */
 
387
                port_descriptors[PLATE_OUTPUTR] =
 
388
                 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
 
389
                port_names[PLATE_OUTPUTR] =
 
390
                 D_("Right output");
 
391
                port_range_hints[PLATE_OUTPUTR].HintDescriptor = 0;
 
392
 
 
393
                plateDescriptor->activate = activatePlate;
 
394
                plateDescriptor->cleanup = cleanupPlate;
 
395
                plateDescriptor->connect_port = connectPortPlate;
 
396
                plateDescriptor->deactivate = NULL;
 
397
                plateDescriptor->instantiate = instantiatePlate;
 
398
                plateDescriptor->run = runPlate;
 
399
                plateDescriptor->run_adding = runAddingPlate;
 
400
                plateDescriptor->set_run_adding_gain = setRunAddingGainPlate;
 
401
        }
 
402
}
 
403
 
 
404
void _fini() {
 
405
        if (plateDescriptor) {
 
406
                free((LADSPA_PortDescriptor *)plateDescriptor->PortDescriptors);
 
407
                free((char **)plateDescriptor->PortNames);
 
408
                free((LADSPA_PortRangeHint *)plateDescriptor->PortRangeHints);
 
409
                free(plateDescriptor);
 
410
        }
 
411
 
 
412
}