-
Notifications
You must be signed in to change notification settings - Fork 0
/
abcEC.c
302 lines (233 loc) · 9.29 KB
/
abcEC.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
#include <stdlib.h>
#include <string.h>
#include <ladspa.h>
#define ABC_INPUT1 0
#define ABC_INPUT2 1
#define ABC_OUT1 2
#define ABC_OUT2 3
#define ABC_OUT3 4
#define ABC_OUT4 5
#define ABC_OUT5 6
#define ABC_REARGAIN 7
#define ABC_CENTREGAIN 8
static LADSPA_Descriptor *abcDescriptor = NULL;
typedef struct {
LADSPA_Data *input1;
LADSPA_Data *input2;
LADSPA_Data *out1;
LADSPA_Data *out2;
LADSPA_Data *out3;
LADSPA_Data *out4;
LADSPA_Data *out5;
LADSPA_Data *reargain;
LADSPA_Data *centregain;
} Abc;
const LADSPA_Descriptor* ladspa_descriptor(unsigned long index) {
switch (index) {
case 0:
return abcDescriptor;
default:
return NULL;
}
}
static void cleanupAbc(LADSPA_Handle instance) {
free(instance);
}
static void connectPortAbc(
LADSPA_Handle instance,
unsigned long port,
LADSPA_Data *data) {
Abc *plugin;
plugin = (Abc *)instance;
switch (port) {
case ABC_INPUT1:
plugin->input1 = data;
break;
case ABC_INPUT2:
plugin->input2 = data;
break;
case ABC_OUT1:
plugin->out1 = data;
break;
case ABC_OUT2:
plugin->out2 = data;
break;
case ABC_OUT3:
plugin->out3 = data;
break;
case ABC_OUT4:
plugin->out4 = data;
break;
case ABC_OUT5:
plugin->out5 = data;
break;
case ABC_REARGAIN:
plugin->reargain = data;
break;
case ABC_CENTREGAIN:
plugin->centregain = data;
break;
}
}
static LADSPA_Handle instantiateAbc(const LADSPA_Descriptor *descriptor, unsigned long s_rate) {
Abc *plugin_data = (Abc *)malloc(sizeof(Abc));
return (LADSPA_Handle)plugin_data;
}
static void runAbc(LADSPA_Handle instance, unsigned long sample_count) {
Abc *plugin_data = (Abc *)instance;
/* Input 1 (array of floats of length sample_count) */
const LADSPA_Data * const input1 = plugin_data->input1;
/* Input 2 (array of floats of length sample_count) */
const LADSPA_Data * const input2 = plugin_data->input2;
/* Output 1 (array of floats of length sample_count) */
LADSPA_Data * const out1 = plugin_data->out1;
/* Output 2 (array of floats of length sample_count) */
LADSPA_Data * const out2 = plugin_data->out2;
/* Output 3 (array of floats of length sample_count) */
LADSPA_Data * const out3 = plugin_data->out3;
/* Output 4 (array of floats of length sample_count) */
LADSPA_Data * const out4 = plugin_data->out4;
/* Output 5 (array of floats of length sample_count) */
LADSPA_Data * const out5 = plugin_data->out5;
/* rear amplitude (linear [0..100]) */
const LADSPA_Data reargain = *(plugin_data->reargain);
/* centre amplitude (linear [0..100]) */
const LADSPA_Data centregain = *(plugin_data->centregain);
unsigned long pos;
double coef = (double) reargain / 100.0;
double coef2 = (double) centregain / 100.0;
for (pos = 0; pos < sample_count; pos++) {
const LADSPA_Data in1 = input1[pos];
const LADSPA_Data in2 = input2[pos];
out1[pos] = in1;
out2[pos] = in2;
out3[pos] = coef * (in1/2 - 0.7 * in2/2);
out4[pos] = coef * (in2/2 - 0.7 * in1/2);
out5[pos] = (-in1 - in2) * coef2;
}
}
static void runaddingAbc(LADSPA_Handle instance, unsigned long sample_count) {
Abc *plugin_data = (Abc *)instance;
/* Input 1 (array of floats of length sample_count) */
const LADSPA_Data * const input1 = plugin_data->input1;
/* Input 2 (array of floats of length sample_count) */
const LADSPA_Data * const input2 = plugin_data->input2;
/* Output 1 (array of floats of length sample_count) */
LADSPA_Data * const out1 = plugin_data->out1;
/* Output 2 (array of floats of length sample_count) */
LADSPA_Data * const out2 = plugin_data->out2;
/* Output 3 (array of floats of length sample_count) */
LADSPA_Data * const out3 = plugin_data->out3;
/* Output 4 (array of floats of length sample_count) */
LADSPA_Data * const out4 = plugin_data->out4;
/* Output 5 (array of floats of length sample_count) */
LADSPA_Data * const out5 = plugin_data->out5;
/* rear amplitude (linear [0..100]) */
const LADSPA_Data reargain = *(plugin_data->reargain);
/* centre amplitude (linear [0..100]) */
const LADSPA_Data centregain = *(plugin_data->centregain);
unsigned long pos;
double coef = (double) reargain / 100.0;
double coef2 = (double) centregain / 100.0;
for (pos = 0; pos < sample_count; pos++) {
const LADSPA_Data in1 = input1[pos];
const LADSPA_Data in2 = input2[pos];
out1[pos] = in1;
out2[pos] = in2;
out3[pos] = coef * (in1/2 - 0.7 * in2/2) + out3[pos];
out4[pos] = coef * (in2/2 - 0.7 * in1/2) + out4[pos];
out5[pos] = (-in1 - in2) * coef2 + out5[pos];
}
}
void _init() {
char **port_names;
LADSPA_PortDescriptor *port_descriptors;
LADSPA_PortRangeHint *port_range_hints;
#define D_(s) (s)
abcDescriptor = (LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
if (abcDescriptor) {
abcDescriptor->UniqueID = 3824;
abcDescriptor->Label = "abcEC";
abcDescriptor->Properties = LADSPA_PROPERTY_HARD_RT_CAPABLE;
abcDescriptor->Name = D_("Stereo to abc with stereobase extension with centre.");
abcDescriptor->Maker = "Markko Merzin";
abcDescriptor->Copyright = "GPL";
abcDescriptor->PortCount = 9;
port_descriptors = (LADSPA_PortDescriptor *)calloc(9, sizeof(LADSPA_PortDescriptor));
abcDescriptor->PortDescriptors = (const LADSPA_PortDescriptor *)port_descriptors;
port_range_hints = (LADSPA_PortRangeHint *)calloc(9, sizeof(LADSPA_PortRangeHint));
abcDescriptor->PortRangeHints = (const LADSPA_PortRangeHint *)port_range_hints;
port_names = (char **)calloc(9, sizeof(char*));
abcDescriptor->PortNames = (const char **)port_names;
/* Parameters for Input 1 */
port_descriptors[ABC_INPUT1] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
port_names[ABC_INPUT1] = D_("Input 1");
port_range_hints[ABC_INPUT1].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_INPUT1].LowerBound = -1;
port_range_hints[ABC_INPUT1].UpperBound = +1;
/* Parameters for Input 2 */
port_descriptors[ABC_INPUT2] = LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
port_names[ABC_INPUT2] = D_("Input 2");
port_range_hints[ABC_INPUT2].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_INPUT2].LowerBound = -1;
port_range_hints[ABC_INPUT2].UpperBound = +1;
/* Parameters for Output 1 */
port_descriptors[ABC_OUT1] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[ABC_OUT1] = D_("Output 1");
port_range_hints[ABC_OUT1].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_OUT1].LowerBound = -1;
port_range_hints[ABC_OUT1].UpperBound = +1;
/* Parameters for Output 2 */
port_descriptors[ABC_OUT2] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[ABC_OUT2] = D_("Output 2");
port_range_hints[ABC_OUT2].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_OUT2].LowerBound = -1;
port_range_hints[ABC_OUT2].UpperBound = +1;
/* Parameters for Output 3 */
port_descriptors[ABC_OUT3] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[ABC_OUT3] = D_("Output 3");
port_range_hints[ABC_OUT3].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_OUT3].LowerBound = -1;
port_range_hints[ABC_OUT3].UpperBound = +1;
/* Parameters for Output 4 */
port_descriptors[ABC_OUT4] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[ABC_OUT4] = D_("Output 4");
port_range_hints[ABC_OUT4].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_OUT4].LowerBound = -1;
port_range_hints[ABC_OUT4].UpperBound = +1;
/* Parameters for Output 5 */
port_descriptors[ABC_OUT5] = LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
port_names[ABC_OUT5] = D_("Output 5");
port_range_hints[ABC_OUT5].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE;
port_range_hints[ABC_OUT5].LowerBound = -1;
port_range_hints[ABC_OUT5].UpperBound = +1;
/* Parameters for Rear amplitude */
port_descriptors[ABC_REARGAIN] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
port_names[ABC_REARGAIN] = D_("Rear amplitude [0..100]");
port_range_hints[ABC_REARGAIN].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
port_range_hints[ABC_REARGAIN].LowerBound = 0;
port_range_hints[ABC_REARGAIN].UpperBound = 100;
/* Parameters for Centre amplitude */
port_descriptors[ABC_CENTREGAIN] = LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
port_names[ABC_CENTREGAIN] = D_("Rear amplitude [0..100]");
port_range_hints[ABC_CENTREGAIN].HintDescriptor = LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
port_range_hints[ABC_CENTREGAIN].LowerBound = 0;
port_range_hints[ABC_CENTREGAIN].UpperBound = 100;
abcDescriptor->activate = NULL;
abcDescriptor->cleanup = cleanupAbc;
abcDescriptor->connect_port = connectPortAbc;
abcDescriptor->deactivate = NULL;
abcDescriptor->instantiate = instantiateAbc;
abcDescriptor->run = runAbc;
abcDescriptor->run_adding = runaddingAbc;
abcDescriptor->set_run_adding_gain = NULL;
}
}
void _fini() {
if (abcDescriptor) {
free((LADSPA_PortDescriptor *)abcDescriptor->PortDescriptors);
free((char **)abcDescriptor->PortNames);
free((LADSPA_PortRangeHint *)abcDescriptor->PortRangeHints);
free(abcDescriptor);
}
}