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

« back to all changes in this revision

Viewing changes to plugins/ladspa_effect/swh/bandpass_iir_1892.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 9 "bandpass_iir_1892.xml"
 
29
 
 
30
#include "config.h"
 
31
#include "util/iir.h"
 
32
 
 
33
#define BANDPASS_IIR_CENTER            0
 
34
#define BANDPASS_IIR_WIDTH             1
 
35
#define BANDPASS_IIR_STAGES            2
 
36
#define BANDPASS_IIR_INPUT             3
 
37
#define BANDPASS_IIR_OUTPUT            4
 
38
 
 
39
static LADSPA_Descriptor *bandpass_iirDescriptor = NULL;
 
40
 
 
41
typedef struct {
 
42
        LADSPA_Data *center;
 
43
        LADSPA_Data *width;
 
44
        LADSPA_Data *stages;
 
45
        LADSPA_Data *input;
 
46
        LADSPA_Data *output;
 
47
        iir_stage_t* first;
 
48
        iir_stage_t* gt;
 
49
        iirf_t*      iirf;
 
50
        float        lfc;
 
51
        long         sample_rate;
 
52
        iir_stage_t* second;
 
53
        float        ufc;
 
54
        LADSPA_Data run_adding_gain;
 
55
} Bandpass_iir;
 
56
 
 
57
_WINDOWS_DLL_EXPORT_
 
58
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
 
59
 
 
60
#ifdef WIN32
 
61
        if (bIsFirstTime) {
 
62
                _init();
 
63
                bIsFirstTime = 0;
 
64
        }
 
65
#endif
 
66
        switch (index) {
 
67
        case 0:
 
68
                return bandpass_iirDescriptor;
 
69
        default:
 
70
                return NULL;
 
71
        }
 
72
}
 
73
 
 
74
static void activateBandpass_iir(LADSPA_Handle instance) {
 
75
        Bandpass_iir *plugin_data = (Bandpass_iir *)instance;
 
76
        iir_stage_t*first = plugin_data->first;
 
77
        iir_stage_t*gt = plugin_data->gt;
 
78
        iirf_t*iirf = plugin_data->iirf;
 
79
        float lfc = plugin_data->lfc;
 
80
        long sample_rate = plugin_data->sample_rate;
 
81
        iir_stage_t*second = plugin_data->second;
 
82
        float ufc = plugin_data->ufc;
 
83
#line 36 "bandpass_iir_1892.xml"
 
84
        
 
85
        ufc = (*(plugin_data->center) + *(plugin_data->width)*0.5f)/(float)sample_rate;
 
86
        lfc = (*(plugin_data->center) - *(plugin_data->width)*0.5f)/(float)sample_rate;
 
87
        first = init_iir_stage(IIR_STAGE_LOWPASS,10,3,2);
 
88
        second = init_iir_stage(IIR_STAGE_HIGHPASS,10,3,2);                  
 
89
        gt = init_iir_stage(IIR_STAGE_BANDPASS,20,3,2); 
 
90
        iirf = init_iirf_t(gt);
 
91
        chebyshev(iirf, first, 2*CLAMP((int)(*(plugin_data->stages)),1,10), IIR_STAGE_LOWPASS, ufc, 0.5f);
 
92
        chebyshev(iirf, second, 2*CLAMP((int)(*(plugin_data->stages)),1,10), IIR_STAGE_HIGHPASS, lfc, 0.5f);
 
93
        combine_iir_stages(IIR_STAGE_BANDPASS, gt, first, second,0,0);
 
94
        plugin_data->first = first;
 
95
        plugin_data->gt = gt;
 
96
        plugin_data->iirf = iirf;
 
97
        plugin_data->lfc = lfc;
 
98
        plugin_data->sample_rate = sample_rate;
 
99
        plugin_data->second = second;
 
100
        plugin_data->ufc = ufc;
 
101
 
 
102
}
 
103
 
 
104
static void cleanupBandpass_iir(LADSPA_Handle instance) {
 
105
#line 48 "bandpass_iir_1892.xml"
 
106
        Bandpass_iir *plugin_data = (Bandpass_iir *)instance;
 
107
        free_iirf_t(plugin_data->iirf, plugin_data->gt);                  
 
108
        free_iir_stage(plugin_data->first);
 
109
        free_iir_stage(plugin_data->second);
 
110
        free_iir_stage(plugin_data->gt);
 
111
        free(instance);
 
112
}
 
113
 
 
114
static void connectPortBandpass_iir(
 
115
 LADSPA_Handle instance,
 
116
 unsigned long port,
 
117
 LADSPA_Data *data) {
 
118
        Bandpass_iir *plugin;
 
119
 
 
120
        plugin = (Bandpass_iir *)instance;
 
121
        switch (port) {
 
122
        case BANDPASS_IIR_CENTER:
 
123
                plugin->center = data;
 
124
                break;
 
125
        case BANDPASS_IIR_WIDTH:
 
126
                plugin->width = data;
 
127
                break;
 
128
        case BANDPASS_IIR_STAGES:
 
129
                plugin->stages = data;
 
130
                break;
 
131
        case BANDPASS_IIR_INPUT:
 
132
                plugin->input = data;
 
133
                break;
 
134
        case BANDPASS_IIR_OUTPUT:
 
135
                plugin->output = data;
 
136
                break;
 
137
        }
 
138
}
 
139
 
 
140
static LADSPA_Handle instantiateBandpass_iir(
 
141
 const LADSPA_Descriptor *descriptor,
 
142
 unsigned long s_rate) {
 
143
        Bandpass_iir *plugin_data = (Bandpass_iir *)malloc(sizeof(Bandpass_iir));
 
144
        iir_stage_t*first = NULL;
 
145
        iir_stage_t*gt = NULL;
 
146
        iirf_t*iirf = NULL;
 
147
        float lfc;
 
148
        long sample_rate;
 
149
        iir_stage_t*second = NULL;
 
150
        float ufc;
 
151
 
 
152
#line 24 "bandpass_iir_1892.xml"
 
153
        sample_rate = s_rate;
 
154
 
 
155
        plugin_data->first = first;
 
156
        plugin_data->gt = gt;
 
157
        plugin_data->iirf = iirf;
 
158
        plugin_data->lfc = lfc;
 
159
        plugin_data->sample_rate = sample_rate;
 
160
        plugin_data->second = second;
 
161
        plugin_data->ufc = ufc;
 
162
 
 
163
        return (LADSPA_Handle)plugin_data;
 
164
}
 
165
 
 
166
#undef buffer_write
 
167
#undef RUN_ADDING
 
168
#undef RUN_REPLACING
 
169
 
 
170
#define buffer_write(b, v) (b = v)
 
171
#define RUN_ADDING    0
 
172
#define RUN_REPLACING 1
 
173
 
 
174
static void runBandpass_iir(LADSPA_Handle instance, unsigned long sample_count) {
 
175
        Bandpass_iir *plugin_data = (Bandpass_iir *)instance;
 
176
 
 
177
        /* Center Frequency (Hz) (float value) */
 
178
        const LADSPA_Data center = *(plugin_data->center);
 
179
 
 
180
        /* Bandwidth (Hz) (float value) */
 
181
        const LADSPA_Data width = *(plugin_data->width);
 
182
 
 
183
        /* Stages(2 poles per stage) (float value) */
 
184
        const LADSPA_Data stages = *(plugin_data->stages);
 
185
 
 
186
        /* Input (array of floats of length sample_count) */
 
187
        const LADSPA_Data * const input = plugin_data->input;
 
188
 
 
189
        /* Output (array of floats of length sample_count) */
 
190
        LADSPA_Data * const output = plugin_data->output;
 
191
        iir_stage_t* first = plugin_data->first;
 
192
        iir_stage_t* gt = plugin_data->gt;
 
193
        iirf_t* iirf = plugin_data->iirf;
 
194
        float lfc = plugin_data->lfc;
 
195
        long sample_rate = plugin_data->sample_rate;
 
196
        iir_stage_t* second = plugin_data->second;
 
197
        float ufc = plugin_data->ufc;
 
198
 
 
199
#line 27 "bandpass_iir_1892.xml"
 
200
        ufc = (center + width*0.5f)/(float)sample_rate;
 
201
        lfc = (center - width*0.5f)/(float)sample_rate;
 
202
        combine_iir_stages(IIR_STAGE_BANDPASS, gt, first, second,
 
203
                           chebyshev(iirf, first,  2*CLAMP((int)stages,1,10), IIR_STAGE_LOWPASS,  ufc, 0.5f),
 
204
                           chebyshev(iirf, second, 2*CLAMP((int)stages,1,10), IIR_STAGE_HIGHPASS, lfc, 0.5f));
 
205
        iir_process_buffer_ns_5(iirf, gt, input, output, sample_count,RUN_ADDING);
 
206
}
 
207
#undef buffer_write
 
208
#undef RUN_ADDING
 
209
#undef RUN_REPLACING
 
210
 
 
211
#define buffer_write(b, v) (b += (v) * run_adding_gain)
 
212
#define RUN_ADDING    1
 
213
#define RUN_REPLACING 0
 
214
 
 
215
static void setRunAddingGainBandpass_iir(LADSPA_Handle instance, LADSPA_Data gain) {
 
216
        ((Bandpass_iir *)instance)->run_adding_gain = gain;
 
217
}
 
218
 
 
219
static void runAddingBandpass_iir(LADSPA_Handle instance, unsigned long sample_count) {
 
220
        Bandpass_iir *plugin_data = (Bandpass_iir *)instance;
 
221
        LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
 
222
 
 
223
        /* Center Frequency (Hz) (float value) */
 
224
        const LADSPA_Data center = *(plugin_data->center);
 
225
 
 
226
        /* Bandwidth (Hz) (float value) */
 
227
        const LADSPA_Data width = *(plugin_data->width);
 
228
 
 
229
        /* Stages(2 poles per stage) (float value) */
 
230
        const LADSPA_Data stages = *(plugin_data->stages);
 
231
 
 
232
        /* Input (array of floats of length sample_count) */
 
233
        const LADSPA_Data * const input = plugin_data->input;
 
234
 
 
235
        /* Output (array of floats of length sample_count) */
 
236
        LADSPA_Data * const output = plugin_data->output;
 
237
        iir_stage_t* first = plugin_data->first;
 
238
        iir_stage_t* gt = plugin_data->gt;
 
239
        iirf_t* iirf = plugin_data->iirf;
 
240
        float lfc = plugin_data->lfc;
 
241
        long sample_rate = plugin_data->sample_rate;
 
242
        iir_stage_t* second = plugin_data->second;
 
243
        float ufc = plugin_data->ufc;
 
244
 
 
245
#line 27 "bandpass_iir_1892.xml"
 
246
        ufc = (center + width*0.5f)/(float)sample_rate;
 
247
        lfc = (center - width*0.5f)/(float)sample_rate;
 
248
        combine_iir_stages(IIR_STAGE_BANDPASS, gt, first, second,
 
249
                           chebyshev(iirf, first,  2*CLAMP((int)stages,1,10), IIR_STAGE_LOWPASS,  ufc, 0.5f),
 
250
                           chebyshev(iirf, second, 2*CLAMP((int)stages,1,10), IIR_STAGE_HIGHPASS, lfc, 0.5f));
 
251
        iir_process_buffer_ns_5(iirf, gt, input, output, sample_count,RUN_ADDING);
 
252
}
 
253
 
 
254
void _init() {
 
255
        char **port_names;
 
256
        LADSPA_PortDescriptor *port_descriptors;
 
257
        LADSPA_PortRangeHint *port_range_hints;
 
258
 
 
259
#ifdef ENABLE_NLS
 
260
#define D_(s) dgettext(PACKAGE, s)
 
261
        setlocale(LC_ALL, "");
 
262
        bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
 
263
#else
 
264
#define D_(s) (s)
 
265
#endif
 
266
 
 
267
 
 
268
        bandpass_iirDescriptor =
 
269
         (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
 
270
 
 
271
        if (bandpass_iirDescriptor) {
 
272
                bandpass_iirDescriptor->UniqueID = 1892;
 
273
                bandpass_iirDescriptor->Label = "bandpass_iir";
 
274
                bandpass_iirDescriptor->Properties =
 
275
                 LADSPA_PROPERTY_HARD_RT_CAPABLE;
 
276
                bandpass_iirDescriptor->Name =
 
277
                 D_("Glame Bandpass Filter");
 
278
                bandpass_iirDescriptor->Maker =
 
279
                 "Alexander Ehlert <mag@glame.de>";
 
280
                bandpass_iirDescriptor->Copyright =
 
281
                 "GPL";
 
282
                bandpass_iirDescriptor->PortCount = 5;
 
283
 
 
284
                port_descriptors = (LADSPA_PortDescriptor *)calloc(5,
 
285
                 sizeof(LADSPA_PortDescriptor));
 
286
                bandpass_iirDescriptor->PortDescriptors =
 
287
                 (const LADSPA_PortDescriptor *)port_descriptors;
 
288
 
 
289
                port_range_hints = (LADSPA_PortRangeHint *)calloc(5,
 
290
                 sizeof(LADSPA_PortRangeHint));
 
291
                bandpass_iirDescriptor->PortRangeHints =
 
292
                 (const LADSPA_PortRangeHint *)port_range_hints;
 
293
 
 
294
                port_names = (char **)calloc(5, sizeof(char*));
 
295
                bandpass_iirDescriptor->PortNames =
 
296
                 (const char **)port_names;
 
297
 
 
298
                /* Parameters for Center Frequency (Hz) */
 
299
                port_descriptors[BANDPASS_IIR_CENTER] =
 
300
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
301
                port_names[BANDPASS_IIR_CENTER] =
 
302
                 D_("Center Frequency (Hz)");
 
303
                port_range_hints[BANDPASS_IIR_CENTER].HintDescriptor =
 
304
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE | LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_LOGARITHMIC;
 
305
                port_range_hints[BANDPASS_IIR_CENTER].LowerBound = 0.0001;
 
306
                port_range_hints[BANDPASS_IIR_CENTER].UpperBound = 0.45;
 
307
 
 
308
                /* Parameters for Bandwidth (Hz) */
 
309
                port_descriptors[BANDPASS_IIR_WIDTH] =
 
310
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
311
                port_names[BANDPASS_IIR_WIDTH] =
 
312
                 D_("Bandwidth (Hz)");
 
313
                port_range_hints[BANDPASS_IIR_WIDTH].HintDescriptor =
 
314
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE | LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_LOGARITHMIC;
 
315
                port_range_hints[BANDPASS_IIR_WIDTH].LowerBound = 0.0001;
 
316
                port_range_hints[BANDPASS_IIR_WIDTH].UpperBound = 0.45;
 
317
 
 
318
                /* Parameters for Stages(2 poles per stage) */
 
319
                port_descriptors[BANDPASS_IIR_STAGES] =
 
320
                 LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
 
321
                port_names[BANDPASS_IIR_STAGES] =
 
322
                 D_("Stages(2 poles per stage)");
 
323
                port_range_hints[BANDPASS_IIR_STAGES].HintDescriptor =
 
324
                 LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_1 | LADSPA_HINT_INTEGER;
 
325
                port_range_hints[BANDPASS_IIR_STAGES].LowerBound = 1.0;
 
326
                port_range_hints[BANDPASS_IIR_STAGES].UpperBound = 10.0;
 
327
 
 
328
                /* Parameters for Input */
 
329
                port_descriptors[BANDPASS_IIR_INPUT] =
 
330
                 LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
 
331
                port_names[BANDPASS_IIR_INPUT] =
 
332
                 D_("Input");
 
333
                port_range_hints[BANDPASS_IIR_INPUT].HintDescriptor = 0;
 
334
 
 
335
                /* Parameters for Output */
 
336
                port_descriptors[BANDPASS_IIR_OUTPUT] =
 
337
                 LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
 
338
                port_names[BANDPASS_IIR_OUTPUT] =
 
339
                 D_("Output");
 
340
                port_range_hints[BANDPASS_IIR_OUTPUT].HintDescriptor = 0;
 
341
 
 
342
                bandpass_iirDescriptor->activate = activateBandpass_iir;
 
343
                bandpass_iirDescriptor->cleanup = cleanupBandpass_iir;
 
344
                bandpass_iirDescriptor->connect_port = connectPortBandpass_iir;
 
345
                bandpass_iirDescriptor->deactivate = NULL;
 
346
                bandpass_iirDescriptor->instantiate = instantiateBandpass_iir;
 
347
                bandpass_iirDescriptor->run = runBandpass_iir;
 
348
                bandpass_iirDescriptor->run_adding = runAddingBandpass_iir;
 
349
                bandpass_iirDescriptor->set_run_adding_gain = setRunAddingGainBandpass_iir;
 
350
        }
 
351
}
 
352
 
 
353
void _fini() {
 
354
        if (bandpass_iirDescriptor) {
 
355
                free((LADSPA_PortDescriptor *)bandpass_iirDescriptor->PortDescriptors);
 
356
                free((char **)bandpass_iirDescriptor->PortNames);
 
357
                free((LADSPA_PortRangeHint *)bandpass_iirDescriptor->PortRangeHints);
 
358
                free(bandpass_iirDescriptor);
 
359
        }
 
360
 
 
361
}