11
#define _ISOC9X_SOURCE 1
12
#define _ISOC99_SOURCE 1
13
#define __USE_ISOC99 1
14
#define __USE_ISOC9X 1
21
#define _WINDOWS_DLL_EXPORT_ __declspec(dllexport)
23
void _init(); // forward declaration
25
#define _WINDOWS_DLL_EXPORT_
28
#line 10 "smooth_decimate_1414.xml"
30
#include "ladspa-util.h"
32
#define SMOOTHDECIMATE_RATE 0
33
#define SMOOTHDECIMATE_SMOOTH 1
34
#define SMOOTHDECIMATE_INPUT 2
35
#define SMOOTHDECIMATE_OUTPUT 3
37
static LADSPA_Descriptor *smoothDecimateDescriptor = NULL;
48
LADSPA_Data run_adding_gain;
52
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
62
return smoothDecimateDescriptor;
68
static void activateSmoothDecimate(LADSPA_Handle instance) {
69
SmoothDecimate *plugin_data = (SmoothDecimate *)instance;
70
float accum = plugin_data->accum;
71
float *buffer = plugin_data->buffer;
72
int buffer_pos = plugin_data->buffer_pos;
73
float fs = plugin_data->fs;
74
#line 26 "smooth_decimate_1414.xml"
77
plugin_data->accum = accum;
78
plugin_data->buffer = buffer;
79
plugin_data->buffer_pos = buffer_pos;
84
static void cleanupSmoothDecimate(LADSPA_Handle instance) {
85
#line 55 "smooth_decimate_1414.xml"
86
SmoothDecimate *plugin_data = (SmoothDecimate *)instance;
87
free(plugin_data->buffer);
91
static void connectPortSmoothDecimate(
92
LADSPA_Handle instance,
95
SmoothDecimate *plugin;
97
plugin = (SmoothDecimate *)instance;
99
case SMOOTHDECIMATE_RATE:
102
case SMOOTHDECIMATE_SMOOTH:
103
plugin->smooth = data;
105
case SMOOTHDECIMATE_INPUT:
106
plugin->input = data;
108
case SMOOTHDECIMATE_OUTPUT:
109
plugin->output = data;
114
static LADSPA_Handle instantiateSmoothDecimate(
115
const LADSPA_Descriptor *descriptor,
116
unsigned long s_rate) {
117
SmoothDecimate *plugin_data = (SmoothDecimate *)malloc(sizeof(SmoothDecimate));
119
float *buffer = NULL;
123
#line 19 "smooth_decimate_1414.xml"
124
buffer = calloc(8, sizeof(float));
129
plugin_data->accum = accum;
130
plugin_data->buffer = buffer;
131
plugin_data->buffer_pos = buffer_pos;
132
plugin_data->fs = fs;
134
return (LADSPA_Handle)plugin_data;
141
#define buffer_write(b, v) (b = v)
143
#define RUN_REPLACING 1
145
static void runSmoothDecimate(LADSPA_Handle instance, unsigned long sample_count) {
146
SmoothDecimate *plugin_data = (SmoothDecimate *)instance;
148
/* Resample rate (float value) */
149
const LADSPA_Data rate = *(plugin_data->rate);
151
/* Smoothing (float value) */
152
const LADSPA_Data smooth = *(plugin_data->smooth);
154
/* Input (array of floats of length sample_count) */
155
const LADSPA_Data * const input = plugin_data->input;
157
/* Output (array of floats of length sample_count) */
158
LADSPA_Data * const output = plugin_data->output;
159
float accum = plugin_data->accum;
160
float * buffer = plugin_data->buffer;
161
int buffer_pos = plugin_data->buffer_pos;
162
float fs = plugin_data->fs;
164
#line 31 "smooth_decimate_1414.xml"
167
float inc = (rate / fs);
168
inc = f_clamp(inc, 0.0f, 1.0f);
170
for (pos = 0; pos < sample_count; pos++) {
174
buffer_pos = (buffer_pos + 1) & 7;
175
buffer[buffer_pos] = input[pos];
177
smoothed = cube_interp(accum, buffer[(buffer_pos - 3) & 7],
178
buffer[(buffer_pos - 2) & 7],
179
buffer[(buffer_pos - 1) & 7],
181
buffer_write(output[pos], LIN_INTERP(smooth, buffer[(buffer_pos - 3) & 7], smoothed));
184
plugin_data->accum = accum;
185
plugin_data->buffer_pos = buffer_pos;
191
#define buffer_write(b, v) (b += (v) * run_adding_gain)
193
#define RUN_REPLACING 0
195
static void setRunAddingGainSmoothDecimate(LADSPA_Handle instance, LADSPA_Data gain) {
196
((SmoothDecimate *)instance)->run_adding_gain = gain;
199
static void runAddingSmoothDecimate(LADSPA_Handle instance, unsigned long sample_count) {
200
SmoothDecimate *plugin_data = (SmoothDecimate *)instance;
201
LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
203
/* Resample rate (float value) */
204
const LADSPA_Data rate = *(plugin_data->rate);
206
/* Smoothing (float value) */
207
const LADSPA_Data smooth = *(plugin_data->smooth);
209
/* Input (array of floats of length sample_count) */
210
const LADSPA_Data * const input = plugin_data->input;
212
/* Output (array of floats of length sample_count) */
213
LADSPA_Data * const output = plugin_data->output;
214
float accum = plugin_data->accum;
215
float * buffer = plugin_data->buffer;
216
int buffer_pos = plugin_data->buffer_pos;
217
float fs = plugin_data->fs;
219
#line 31 "smooth_decimate_1414.xml"
222
float inc = (rate / fs);
223
inc = f_clamp(inc, 0.0f, 1.0f);
225
for (pos = 0; pos < sample_count; pos++) {
229
buffer_pos = (buffer_pos + 1) & 7;
230
buffer[buffer_pos] = input[pos];
232
smoothed = cube_interp(accum, buffer[(buffer_pos - 3) & 7],
233
buffer[(buffer_pos - 2) & 7],
234
buffer[(buffer_pos - 1) & 7],
236
buffer_write(output[pos], LIN_INTERP(smooth, buffer[(buffer_pos - 3) & 7], smoothed));
239
plugin_data->accum = accum;
240
plugin_data->buffer_pos = buffer_pos;
245
LADSPA_PortDescriptor *port_descriptors;
246
LADSPA_PortRangeHint *port_range_hints;
249
#define D_(s) dgettext(PACKAGE, s)
250
setlocale(LC_ALL, "");
251
bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
257
smoothDecimateDescriptor =
258
(LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
260
if (smoothDecimateDescriptor) {
261
smoothDecimateDescriptor->UniqueID = 1414;
262
smoothDecimateDescriptor->Label = "smoothDecimate";
263
smoothDecimateDescriptor->Properties =
264
LADSPA_PROPERTY_HARD_RT_CAPABLE;
265
smoothDecimateDescriptor->Name =
266
D_("Smooth Decimator");
267
smoothDecimateDescriptor->Maker =
268
"Steve Harris <steve@plugin.org.uk>";
269
smoothDecimateDescriptor->Copyright =
271
smoothDecimateDescriptor->PortCount = 4;
273
port_descriptors = (LADSPA_PortDescriptor *)calloc(4,
274
sizeof(LADSPA_PortDescriptor));
275
smoothDecimateDescriptor->PortDescriptors =
276
(const LADSPA_PortDescriptor *)port_descriptors;
278
port_range_hints = (LADSPA_PortRangeHint *)calloc(4,
279
sizeof(LADSPA_PortRangeHint));
280
smoothDecimateDescriptor->PortRangeHints =
281
(const LADSPA_PortRangeHint *)port_range_hints;
283
port_names = (char **)calloc(4, sizeof(char*));
284
smoothDecimateDescriptor->PortNames =
285
(const char **)port_names;
287
/* Parameters for Resample rate */
288
port_descriptors[SMOOTHDECIMATE_RATE] =
289
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
290
port_names[SMOOTHDECIMATE_RATE] =
292
port_range_hints[SMOOTHDECIMATE_RATE].HintDescriptor =
293
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_SAMPLE_RATE | LADSPA_HINT_DEFAULT_MAXIMUM;
294
port_range_hints[SMOOTHDECIMATE_RATE].LowerBound = 0;
295
port_range_hints[SMOOTHDECIMATE_RATE].UpperBound = 1;
297
/* Parameters for Smoothing */
298
port_descriptors[SMOOTHDECIMATE_SMOOTH] =
299
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
300
port_names[SMOOTHDECIMATE_SMOOTH] =
302
port_range_hints[SMOOTHDECIMATE_SMOOTH].HintDescriptor =
303
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MAXIMUM;
304
port_range_hints[SMOOTHDECIMATE_SMOOTH].LowerBound = 0;
305
port_range_hints[SMOOTHDECIMATE_SMOOTH].UpperBound = 1;
307
/* Parameters for Input */
308
port_descriptors[SMOOTHDECIMATE_INPUT] =
309
LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
310
port_names[SMOOTHDECIMATE_INPUT] =
312
port_range_hints[SMOOTHDECIMATE_INPUT].HintDescriptor = 0;
314
/* Parameters for Output */
315
port_descriptors[SMOOTHDECIMATE_OUTPUT] =
316
LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
317
port_names[SMOOTHDECIMATE_OUTPUT] =
319
port_range_hints[SMOOTHDECIMATE_OUTPUT].HintDescriptor = 0;
321
smoothDecimateDescriptor->activate = activateSmoothDecimate;
322
smoothDecimateDescriptor->cleanup = cleanupSmoothDecimate;
323
smoothDecimateDescriptor->connect_port = connectPortSmoothDecimate;
324
smoothDecimateDescriptor->deactivate = NULL;
325
smoothDecimateDescriptor->instantiate = instantiateSmoothDecimate;
326
smoothDecimateDescriptor->run = runSmoothDecimate;
327
smoothDecimateDescriptor->run_adding = runAddingSmoothDecimate;
328
smoothDecimateDescriptor->set_run_adding_gain = setRunAddingGainSmoothDecimate;
333
if (smoothDecimateDescriptor) {
334
free((LADSPA_PortDescriptor *)smoothDecimateDescriptor->PortDescriptors);
335
free((char **)smoothDecimateDescriptor->PortNames);
336
free((LADSPA_PortRangeHint *)smoothDecimateDescriptor->PortRangeHints);
337
free(smoothDecimateDescriptor);