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

« back to all changes in this revision

Viewing changes to plugins/ladspa_effect/swh/valve_1209.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 "valve_1209.xml"
 
29
 
 
30
#include "ladspa-util.h"
 
31
 
 
32
#define VALVE_Q_P                      0
 
33
#define VALVE_DIST_P                   1
 
34
#define VALVE_INPUT                    2
 
35
#define VALVE_OUTPUT                   3
 
36
 
 
37
static LADSPA_Descriptor *valveDescriptor = NULL;
 
38
 
 
39
typedef struct {
 
40
        LADSPA_Data *q_p;
 
41
        LADSPA_Data *dist_p;
 
42
        LADSPA_Data *input;
 
43
        LADSPA_Data *output;
 
44
        LADSPA_Data  itm1;
 
45
        LADSPA_Data  otm1;
 
46
        LADSPA_Data run_adding_gain;
 
47
} Valve;
 
48
 
 
49
_WINDOWS_DLL_EXPORT_
 
50
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
 
51
 
 
52
#ifdef WIN32
 
53
        if (bIsFirstTime) {
 
54
                _init();
 
55
                bIsFirstTime = 0;
 
56
        }
 
57
#endif
 
58
        switch (index) {
 
59
        case 0:
 
60
                return valveDescriptor;
 
61
        default:
 
62
                return NULL;
 
63
        }
 
64
}
 
65
 
 
66
static void activateValve(LADSPA_Handle instance) {
 
67
        Valve *plugin_data = (Valve *)instance;
 
68
        LADSPA_Data itm1 = plugin_data->itm1;
 
69
        LADSPA_Data otm1 = plugin_data->otm1;
 
70
#line 21 "valve_1209.xml"
 
71
        itm1 = 0.0f;
 
72
        otm1 = 0.0f;
 
73
        plugin_data->itm1 = itm1;
 
74
        plugin_data->otm1 = otm1;
 
75
 
 
76
}
 
77
 
 
78
static void cleanupValve(LADSPA_Handle instance) {
 
79
        free(instance);
 
80
}
 
81
 
 
82
static void connectPortValve(
 
83
 LADSPA_Handle instance,
 
84
 unsigned long port,
 
85
 LADSPA_Data *data) {
 
86
        Valve *plugin;
 
87
 
 
88
        plugin = (Valve *)instance;
 
89
        switch (port) {
 
90
        case VALVE_Q_P:
 
91
                plugin->q_p = data;
 
92
                break;
 
93
        case VALVE_DIST_P:
 
94
                plugin->dist_p = data;
 
95
                break;
 
96
        case VALVE_INPUT:
 
97
                plugin->input = data;
 
98
                break;
 
99
        case VALVE_OUTPUT:
 
100
                plugin->output = data;
 
101
                break;
 
102
        }
 
103
}
 
104
 
 
105
static LADSPA_Handle instantiateValve(
 
106
 const LADSPA_Descriptor *descriptor,
 
107
 unsigned long s_rate) {
 
108
        Valve *plugin_data = (Valve *)malloc(sizeof(Valve));
 
109
        plugin_data->run_adding_gain = 1.0f;
 
110
 
 
111
        return (LADSPA_Handle)plugin_data;
 
112
}
 
113
 
 
114
#undef buffer_write
 
115
#undef RUN_ADDING
 
116
#undef RUN_REPLACING
 
117
 
 
118
#define buffer_write(b, v) (b = v)
 
119
#define RUN_ADDING    0
 
120
#define RUN_REPLACING 1
 
121
 
 
122
static void runValve(LADSPA_Handle instance, unsigned long sample_count) {
 
123
        Valve *plugin_data = (Valve *)instance;
 
124
 
 
125
        /* Distortion level (float value) */
 
126
        const LADSPA_Data q_p = *(plugin_data->q_p);
 
127
 
 
128
        /* Distortion character (float value) */
 
129
        const LADSPA_Data dist_p = *(plugin_data->dist_p);
 
130
 
 
131
        /* Input (array of floats of length sample_count) */
 
132
        const LADSPA_Data * const input = plugin_data->input;
 
133
 
 
134
        /* Output (array of floats of length sample_count) */
 
135
        LADSPA_Data * const output = plugin_data->output;
 
136
        LADSPA_Data itm1 = plugin_data->itm1;
 
137
        LADSPA_Data otm1 = plugin_data->otm1;
 
138
 
 
139
#line 26 "valve_1209.xml"
 
140
        unsigned long pos;
 
141
        LADSPA_Data fx;
 
142
        
 
143
        const float q = q_p - 0.999f;
 
144
        const float dist = dist_p * 40.0f + 0.1f;
 
145
        
 
146
        if (q == 0.0f) {
 
147
                for (pos = 0; pos < sample_count; pos++) {
 
148
                        if (input[pos] == q) {
 
149
                                fx = 1.0f / dist;
 
150
                        } else {
 
151
                                fx = input[pos] / (1.0f - f_exp(-dist * input[pos]));
 
152
                        }
 
153
                        otm1 = 0.999f * otm1 + fx - itm1;
 
154
                        round_to_zero(&otm1);
 
155
                        itm1 = fx;
 
156
                        buffer_write(output[pos], otm1);
 
157
                }
 
158
        } else {
 
159
                for (pos = 0; pos < sample_count; pos++) {
 
160
                        if (input[pos] == q) {
 
161
                                fx = 1.0f / dist + q / (1.0f - f_exp(dist * q));
 
162
                        } else {
 
163
                                fx = (input[pos] - q) /
 
164
                                 (1.0f - f_exp(-dist * (input[pos] - q))) +
 
165
                                 q / (1.0f - f_exp(dist * q));
 
166
                        }
 
167
                        otm1 = 0.999f * otm1 + fx - itm1;
 
168
                        round_to_zero(&otm1);
 
169
                        itm1 = fx;
 
170
                        buffer_write(output[pos], otm1);
 
171
                }
 
172
        }
 
173
        
 
174
        plugin_data->itm1 = itm1;
 
175
        plugin_data->otm1 = otm1;
 
176
}
 
177
#undef buffer_write
 
178
#undef RUN_ADDING
 
179
#undef RUN_REPLACING
 
180
 
 
181
#define buffer_write(b, v) (b += (v) * run_adding_gain)
 
182
#define RUN_ADDING    1
 
183
#define RUN_REPLACING 0
 
184
 
 
185
static void setRunAddingGainValve(LADSPA_Handle instance, LADSPA_Data gain) {
 
186
        ((Valve *)instance)->run_adding_gain = gain;
 
187
}
 
188
 
 
189
static void runAddingValve(LADSPA_Handle instance, unsigned long sample_count) {
 
190
        Valve *plugin_data = (Valve *)instance;
 
191
        LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
 
192
 
 
193
        /* Distortion level (float value) */
 
194
        const LADSPA_Data q_p = *(plugin_data->q_p);
 
195
 
 
196
        /* Distortion character (float value) */
 
197
        const LADSPA_Data dist_p = *(plugin_data->dist_p);
 
198
 
 
199
        /* Input (array of floats of length sample_count) */
 
200
        const LADSPA_Data * const input = plugin_data->input;
 
201
 
 
202
        /* Output (array of floats of length sample_count) */
 
203
        LADSPA_Data * const output = plugin_data->output;
 
204
        LADSPA_Data itm1 = plugin_data->itm1;
 
205
        LADSPA_Data otm1 = plugin_data->otm1;
 
206
 
 
207
#line 26 "valve_1209.xml"
 
208
        unsigned long pos;
 
209
        LADSPA_Data fx;
 
210
        
 
211
        const float q = q_p - 0.999f;
 
212
        const float dist = dist_p * 40.0f + 0.1f;
 
213
        
 
214
        if (q == 0.0f) {
 
215
                for (pos = 0; pos < sample_count; pos++) {
 
216
                        if (input[pos] == q) {
 
217
                                fx = 1.0f / dist;
 
218
                        } else {
 
219
                                fx = input[pos] / (1.0f - f_exp(-dist * input[pos]));
 
220
                        }
 
221
                        otm1 = 0.999f * otm1 + fx - itm1;
 
222
                        round_to_zero(&otm1);
 
223
                        itm1 = fx;
 
224
                        buffer_write(output[pos], otm1);
 
225
                }
 
226
        } else {
 
227
                for (pos = 0; pos < sample_count; pos++) {
 
228
                        if (input[pos] == q) {
 
229
                                fx = 1.0f / dist + q / (1.0f - f_exp(dist * q));
 
230
                        } else {
 
231
                                fx = (input[pos] - q) /
 
232
                                 (1.0f - f_exp(-dist * (input[pos] - q))) +
 
233
                                 q / (1.0f - f_exp(dist * q));
 
234
                        }
 
235
                        otm1 = 0.999f * otm1 + fx - itm1;
 
236
                        round_to_zero(&otm1);
 
237
                        itm1 = fx;
 
238
                        buffer_write(output[pos], otm1);
 
239
                }
 
240
        }
 
241
        
 
242
        plugin_data->itm1 = itm1;
 
243
        plugin_data->otm1 = otm1;
 
244
}
 
245
 
 
246
void _init() {
 
247
        char **port_names;
 
248
        LADSPA_PortDescriptor *port_descriptors;
 
249
        LADSPA_PortRangeHint *port_range_hints;
 
250
 
 
251
#ifdef ENABLE_NLS
 
252
#define D_(s) dgettext(PACKAGE, s)
 
253
        setlocale(LC_ALL, "");
 
254
        bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
 
255
#else
 
256
#define D_(s) (s)
 
257
#endif
 
258
 
 
259
 
 
260
        valveDescriptor =
 
261
         (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
 
262
 
 
263
        if (valveDescriptor) {
 
264
                valveDescriptor->UniqueID = 1209;
 
265
                valveDescriptor->Label = "valve";
 
266
                valveDescriptor->Properties =
 
267
                 LADSPA_PROPERTY_HARD_RT_CAPABLE;
 
268
                valveDescriptor->Name =
 
269
                 D_("Valve saturation");
 
270
                valveDescriptor->Maker =
 
271
                 "Steve Harris <steve@plugin.org.uk>";
 
272
                valveDescriptor->Copyright =
 
273
                 "GPL";
 
274
                valveDescriptor->PortCount = 4;
 
275
 
 
276
                port_descriptors = (LADSPA_PortDescriptor *)calloc(4,
 
277
                 sizeof(LADSPA_PortDescriptor));
 
278
                valveDescriptor->PortDescriptors =
 
279
                 (const LADSPA_PortDescriptor *)port_descriptors;
 
280
 
 
281
                port_range_hints = (LADSPA_PortRangeHint *)calloc(4,
 
282
                 sizeof(LADSPA_PortRangeHint));
 
283
                valveDescriptor->PortRangeHints =
 
284
                 (const LADSPA_PortRangeHint *)port_range_hints;
 
285
 
 
286
                port_names = (char **)calloc(4, sizeof(char*));
 
287
                valveDescriptor->PortNames =
 
288
                 (const char **)port_names;
 
289
 
 
290
                /* Parameters for Distortion level */
 
291
                port_descriptors[VALVE_Q_P] =
 
292
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
293
                port_names[VALVE_Q_P] =
 
294
                 D_("Distortion level");
 
295
                port_range_hints[VALVE_Q_P].HintDescriptor =
 
296
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
 
297
                port_range_hints[VALVE_Q_P].LowerBound = 0;
 
298
                port_range_hints[VALVE_Q_P].UpperBound = 1;
 
299
 
 
300
                /* Parameters for Distortion character */
 
301
                port_descriptors[VALVE_DIST_P] =
 
302
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
303
                port_names[VALVE_DIST_P] =
 
304
                 D_("Distortion character");
 
305
                port_range_hints[VALVE_DIST_P].HintDescriptor =
 
306
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
 
307
                port_range_hints[VALVE_DIST_P].LowerBound = 0;
 
308
                port_range_hints[VALVE_DIST_P].UpperBound = 1;
 
309
 
 
310
                /* Parameters for Input */
 
311
                port_descriptors[VALVE_INPUT] =
 
312
                 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
 
313
                port_names[VALVE_INPUT] =
 
314
                 D_("Input");
 
315
                port_range_hints[VALVE_INPUT].HintDescriptor = 0;
 
316
 
 
317
                /* Parameters for Output */
 
318
                port_descriptors[VALVE_OUTPUT] =
 
319
                 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
 
320
                port_names[VALVE_OUTPUT] =
 
321
                 D_("Output");
 
322
                port_range_hints[VALVE_OUTPUT].HintDescriptor = 0;
 
323
 
 
324
                valveDescriptor->activate = activateValve;
 
325
                valveDescriptor->cleanup = cleanupValve;
 
326
                valveDescriptor->connect_port = connectPortValve;
 
327
                valveDescriptor->deactivate = NULL;
 
328
                valveDescriptor->instantiate = instantiateValve;
 
329
                valveDescriptor->run = runValve;
 
330
                valveDescriptor->run_adding = runAddingValve;
 
331
                valveDescriptor->set_run_adding_gain = setRunAddingGainValve;
 
332
        }
 
333
}
 
334
 
 
335
void _fini() {
 
336
        if (valveDescriptor) {
 
337
                free((LADSPA_PortDescriptor *)valveDescriptor->PortDescriptors);
 
338
                free((char **)valveDescriptor->PortNames);
 
339
                free((LADSPA_PortRangeHint *)valveDescriptor->PortRangeHints);
 
340
                free(valveDescriptor);
 
341
        }
 
342
 
 
343
}