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 "valve_1209.xml"
30
#include "ladspa-util.h"
33
#define VALVE_DIST_P 1
35
#define VALVE_OUTPUT 3
37
static LADSPA_Descriptor *valveDescriptor = NULL;
46
LADSPA_Data run_adding_gain;
50
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
60
return valveDescriptor;
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"
73
plugin_data->itm1 = itm1;
74
plugin_data->otm1 = otm1;
78
static void cleanupValve(LADSPA_Handle instance) {
82
static void connectPortValve(
83
LADSPA_Handle instance,
88
plugin = (Valve *)instance;
94
plugin->dist_p = data;
100
plugin->output = data;
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;
111
return (LADSPA_Handle)plugin_data;
118
#define buffer_write(b, v) (b = v)
120
#define RUN_REPLACING 1
122
static void runValve(LADSPA_Handle instance, unsigned long sample_count) {
123
Valve *plugin_data = (Valve *)instance;
125
/* Distortion level (float value) */
126
const LADSPA_Data q_p = *(plugin_data->q_p);
128
/* Distortion character (float value) */
129
const LADSPA_Data dist_p = *(plugin_data->dist_p);
131
/* Input (array of floats of length sample_count) */
132
const LADSPA_Data * const input = plugin_data->input;
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;
139
#line 26 "valve_1209.xml"
143
const float q = q_p - 0.999f;
144
const float dist = dist_p * 40.0f + 0.1f;
147
for (pos = 0; pos < sample_count; pos++) {
148
if (input[pos] == q) {
151
fx = input[pos] / (1.0f - f_exp(-dist * input[pos]));
153
otm1 = 0.999f * otm1 + fx - itm1;
154
round_to_zero(&otm1);
156
buffer_write(output[pos], otm1);
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));
163
fx = (input[pos] - q) /
164
(1.0f - f_exp(-dist * (input[pos] - q))) +
165
q / (1.0f - f_exp(dist * q));
167
otm1 = 0.999f * otm1 + fx - itm1;
168
round_to_zero(&otm1);
170
buffer_write(output[pos], otm1);
174
plugin_data->itm1 = itm1;
175
plugin_data->otm1 = otm1;
181
#define buffer_write(b, v) (b += (v) * run_adding_gain)
183
#define RUN_REPLACING 0
185
static void setRunAddingGainValve(LADSPA_Handle instance, LADSPA_Data gain) {
186
((Valve *)instance)->run_adding_gain = gain;
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;
193
/* Distortion level (float value) */
194
const LADSPA_Data q_p = *(plugin_data->q_p);
196
/* Distortion character (float value) */
197
const LADSPA_Data dist_p = *(plugin_data->dist_p);
199
/* Input (array of floats of length sample_count) */
200
const LADSPA_Data * const input = plugin_data->input;
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;
207
#line 26 "valve_1209.xml"
211
const float q = q_p - 0.999f;
212
const float dist = dist_p * 40.0f + 0.1f;
215
for (pos = 0; pos < sample_count; pos++) {
216
if (input[pos] == q) {
219
fx = input[pos] / (1.0f - f_exp(-dist * input[pos]));
221
otm1 = 0.999f * otm1 + fx - itm1;
222
round_to_zero(&otm1);
224
buffer_write(output[pos], otm1);
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));
231
fx = (input[pos] - q) /
232
(1.0f - f_exp(-dist * (input[pos] - q))) +
233
q / (1.0f - f_exp(dist * q));
235
otm1 = 0.999f * otm1 + fx - itm1;
236
round_to_zero(&otm1);
238
buffer_write(output[pos], otm1);
242
plugin_data->itm1 = itm1;
243
plugin_data->otm1 = otm1;
248
LADSPA_PortDescriptor *port_descriptors;
249
LADSPA_PortRangeHint *port_range_hints;
252
#define D_(s) dgettext(PACKAGE, s)
253
setlocale(LC_ALL, "");
254
bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
261
(LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
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 =
274
valveDescriptor->PortCount = 4;
276
port_descriptors = (LADSPA_PortDescriptor *)calloc(4,
277
sizeof(LADSPA_PortDescriptor));
278
valveDescriptor->PortDescriptors =
279
(const LADSPA_PortDescriptor *)port_descriptors;
281
port_range_hints = (LADSPA_PortRangeHint *)calloc(4,
282
sizeof(LADSPA_PortRangeHint));
283
valveDescriptor->PortRangeHints =
284
(const LADSPA_PortRangeHint *)port_range_hints;
286
port_names = (char **)calloc(4, sizeof(char*));
287
valveDescriptor->PortNames =
288
(const char **)port_names;
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;
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;
310
/* Parameters for Input */
311
port_descriptors[VALVE_INPUT] =
312
LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
313
port_names[VALVE_INPUT] =
315
port_range_hints[VALVE_INPUT].HintDescriptor = 0;
317
/* Parameters for Output */
318
port_descriptors[VALVE_OUTPUT] =
319
LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
320
port_names[VALVE_OUTPUT] =
322
port_range_hints[VALVE_OUTPUT].HintDescriptor = 0;
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;
336
if (valveDescriptor) {
337
free((LADSPA_PortDescriptor *)valveDescriptor->PortDescriptors);
338
free((char **)valveDescriptor->PortNames);
339
free((LADSPA_PortRangeHint *)valveDescriptor->PortRangeHints);
340
free(valveDescriptor);