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 8 "tape_delay_1211.xml"
30
#include "ladspa-util.h"
32
#define BASE_BUFFER 8 // Tape length (inches)
34
#define TAPEDELAY_SPEED 0
35
#define TAPEDELAY_DA_DB 1
36
#define TAPEDELAY_T1D 2
37
#define TAPEDELAY_T1A_DB 3
38
#define TAPEDELAY_T2D 4
39
#define TAPEDELAY_T2A_DB 5
40
#define TAPEDELAY_T3D 6
41
#define TAPEDELAY_T3A_DB 7
42
#define TAPEDELAY_T4D 8
43
#define TAPEDELAY_T4A_DB 9
44
#define TAPEDELAY_INPUT 10
45
#define TAPEDELAY_OUTPUT 11
47
static LADSPA_Descriptor *tapeDelayDescriptor = NULL;
63
unsigned int buffer_mask;
64
unsigned int buffer_size;
68
unsigned int last_phase;
74
LADSPA_Data run_adding_gain;
78
const LADSPA_Descriptor *ladspa_descriptor(unsigned long index) {
88
return tapeDelayDescriptor;
94
static void activateTapeDelay(LADSPA_Handle instance) {
95
TapeDelay *plugin_data = (TapeDelay *)instance;
96
LADSPA_Data *buffer = plugin_data->buffer;
97
unsigned int buffer_mask = plugin_data->buffer_mask;
98
unsigned int buffer_size = plugin_data->buffer_size;
99
LADSPA_Data last2_in = plugin_data->last2_in;
100
LADSPA_Data last3_in = plugin_data->last3_in;
101
LADSPA_Data last_in = plugin_data->last_in;
102
unsigned int last_phase = plugin_data->last_phase;
103
float phase = plugin_data->phase;
104
int sample_rate = plugin_data->sample_rate;
105
LADSPA_Data z0 = plugin_data->z0;
106
LADSPA_Data z1 = plugin_data->z1;
107
LADSPA_Data z2 = plugin_data->z2;
108
#line 38 "tape_delay_1211.xml"
111
for (i = 0; i < buffer_size; i++) {
119
sample_rate = sample_rate;
123
plugin_data->buffer = buffer;
124
plugin_data->buffer_mask = buffer_mask;
125
plugin_data->buffer_size = buffer_size;
126
plugin_data->last2_in = last2_in;
127
plugin_data->last3_in = last3_in;
128
plugin_data->last_in = last_in;
129
plugin_data->last_phase = last_phase;
130
plugin_data->phase = phase;
131
plugin_data->sample_rate = sample_rate;
132
plugin_data->z0 = z0;
133
plugin_data->z1 = z1;
134
plugin_data->z2 = z2;
138
static void cleanupTapeDelay(LADSPA_Handle instance) {
139
#line 55 "tape_delay_1211.xml"
140
TapeDelay *plugin_data = (TapeDelay *)instance;
141
free(plugin_data->buffer);
145
static void connectPortTapeDelay(
146
LADSPA_Handle instance,
151
plugin = (TapeDelay *)instance;
153
case TAPEDELAY_SPEED:
154
plugin->speed = data;
156
case TAPEDELAY_DA_DB:
157
plugin->da_db = data;
162
case TAPEDELAY_T1A_DB:
163
plugin->t1a_db = data;
168
case TAPEDELAY_T2A_DB:
169
plugin->t2a_db = data;
174
case TAPEDELAY_T3A_DB:
175
plugin->t3a_db = data;
180
case TAPEDELAY_T4A_DB:
181
plugin->t4a_db = data;
183
case TAPEDELAY_INPUT:
184
plugin->input = data;
186
case TAPEDELAY_OUTPUT:
187
plugin->output = data;
192
static LADSPA_Handle instantiateTapeDelay(
193
const LADSPA_Descriptor *descriptor,
194
unsigned long s_rate) {
195
TapeDelay *plugin_data = (TapeDelay *)malloc(sizeof(TapeDelay));
196
LADSPA_Data *buffer = NULL;
197
unsigned int buffer_mask;
198
unsigned int buffer_size;
199
LADSPA_Data last2_in;
200
LADSPA_Data last3_in;
202
unsigned int last_phase;
209
#line 21 "tape_delay_1211.xml"
210
unsigned int mbs = BASE_BUFFER * s_rate;
211
sample_rate = s_rate;
212
for (buffer_size = 4096; buffer_size < mbs;
214
buffer = malloc(buffer_size * sizeof(LADSPA_Data));
215
buffer_mask = buffer_size - 1;
225
plugin_data->buffer = buffer;
226
plugin_data->buffer_mask = buffer_mask;
227
plugin_data->buffer_size = buffer_size;
228
plugin_data->last2_in = last2_in;
229
plugin_data->last3_in = last3_in;
230
plugin_data->last_in = last_in;
231
plugin_data->last_phase = last_phase;
232
plugin_data->phase = phase;
233
plugin_data->sample_rate = sample_rate;
234
plugin_data->z0 = z0;
235
plugin_data->z1 = z1;
236
plugin_data->z2 = z2;
238
return (LADSPA_Handle)plugin_data;
245
#define buffer_write(b, v) (b = v)
247
#define RUN_REPLACING 1
249
static void runTapeDelay(LADSPA_Handle instance, unsigned long sample_count) {
250
TapeDelay *plugin_data = (TapeDelay *)instance;
252
/* Tape speed (inches/sec, 1=normal) (float value) */
253
const LADSPA_Data speed = *(plugin_data->speed);
255
/* Dry level (dB) (float value) */
256
const LADSPA_Data da_db = *(plugin_data->da_db);
258
/* Tap 1 distance (inches) (float value) */
259
const LADSPA_Data t1d = *(plugin_data->t1d);
261
/* Tap 1 level (dB) (float value) */
262
const LADSPA_Data t1a_db = *(plugin_data->t1a_db);
264
/* Tap 2 distance (inches) (float value) */
265
const LADSPA_Data t2d = *(plugin_data->t2d);
267
/* Tap 2 level (dB) (float value) */
268
const LADSPA_Data t2a_db = *(plugin_data->t2a_db);
270
/* Tap 3 distance (inches) (float value) */
271
const LADSPA_Data t3d = *(plugin_data->t3d);
273
/* Tap 3 level (dB) (float value) */
274
const LADSPA_Data t3a_db = *(plugin_data->t3a_db);
276
/* Tap 4 distance (inches) (float value) */
277
const LADSPA_Data t4d = *(plugin_data->t4d);
279
/* Tap 4 level (dB) (float value) */
280
const LADSPA_Data t4a_db = *(plugin_data->t4a_db);
282
/* Input (array of floats of length sample_count) */
283
const LADSPA_Data * const input = plugin_data->input;
285
/* Output (array of floats of length sample_count) */
286
LADSPA_Data * const output = plugin_data->output;
287
LADSPA_Data * buffer = plugin_data->buffer;
288
unsigned int buffer_mask = plugin_data->buffer_mask;
289
unsigned int buffer_size = plugin_data->buffer_size;
290
LADSPA_Data last2_in = plugin_data->last2_in;
291
LADSPA_Data last3_in = plugin_data->last3_in;
292
LADSPA_Data last_in = plugin_data->last_in;
293
unsigned int last_phase = plugin_data->last_phase;
294
float phase = plugin_data->phase;
295
int sample_rate = plugin_data->sample_rate;
296
LADSPA_Data z0 = plugin_data->z0;
297
LADSPA_Data z1 = plugin_data->z1;
298
LADSPA_Data z2 = plugin_data->z2;
300
#line 59 "tape_delay_1211.xml"
302
float increment = f_clamp(speed, 0.0f, 40.0f);
303
float lin_int, lin_inc;
308
const float da = DB_CO(da_db);
309
const float t1a = DB_CO(t1a_db);
310
const float t2a = DB_CO(t2a_db);
311
const float t3a = DB_CO(t3a_db);
312
const float t4a = DB_CO(t4a_db);
313
const unsigned int t1d_s = f_round(t1d * sample_rate);
314
const unsigned int t2d_s = f_round(t2d * sample_rate);
315
const unsigned int t3d_s = f_round(t3d * sample_rate);
316
const unsigned int t4d_s = f_round(t4d * sample_rate);
318
for (pos = 0; pos < sample_count; pos++) {
319
fph = f_trunc(phase);
321
lin_int = phase - (float)fph;
323
out = buffer[(unsigned int)(fph - t1d_s) & buffer_mask] * t1a;
324
out += buffer[(unsigned int)(fph - t2d_s) & buffer_mask] * t2a;
325
out += buffer[(unsigned int)(fph - t3d_s) & buffer_mask] * t3a;
326
out += buffer[(unsigned int)(fph - t4d_s) & buffer_mask] * t4a;
329
lin_inc = 1.0f / (floor(phase) - last_phase + 1);
330
lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc;
332
for (track = last_phase; track < phase; track++) {
334
buffer[track & buffer_mask] =
335
cube_interp(lin_int, last3_in, last2_in, last_in, input[pos]);
339
last_in = input[pos];
340
out += input[pos] * da;
341
buffer_write(output[pos], out);
342
if (phase >= buffer_size) {
343
phase -= buffer_size;
347
// Store current phase in instance
348
plugin_data->phase = phase;
349
plugin_data->last_phase = last_phase;
350
plugin_data->last_in = last_in;
351
plugin_data->last2_in = last2_in;
352
plugin_data->last3_in = last3_in;
353
plugin_data->z0 = z0;
354
plugin_data->z1 = z1;
355
plugin_data->z2 = z2;
361
#define buffer_write(b, v) (b += (v) * run_adding_gain)
363
#define RUN_REPLACING 0
365
static void setRunAddingGainTapeDelay(LADSPA_Handle instance, LADSPA_Data gain) {
366
((TapeDelay *)instance)->run_adding_gain = gain;
369
static void runAddingTapeDelay(LADSPA_Handle instance, unsigned long sample_count) {
370
TapeDelay *plugin_data = (TapeDelay *)instance;
371
LADSPA_Data run_adding_gain = plugin_data->run_adding_gain;
373
/* Tape speed (inches/sec, 1=normal) (float value) */
374
const LADSPA_Data speed = *(plugin_data->speed);
376
/* Dry level (dB) (float value) */
377
const LADSPA_Data da_db = *(plugin_data->da_db);
379
/* Tap 1 distance (inches) (float value) */
380
const LADSPA_Data t1d = *(plugin_data->t1d);
382
/* Tap 1 level (dB) (float value) */
383
const LADSPA_Data t1a_db = *(plugin_data->t1a_db);
385
/* Tap 2 distance (inches) (float value) */
386
const LADSPA_Data t2d = *(plugin_data->t2d);
388
/* Tap 2 level (dB) (float value) */
389
const LADSPA_Data t2a_db = *(plugin_data->t2a_db);
391
/* Tap 3 distance (inches) (float value) */
392
const LADSPA_Data t3d = *(plugin_data->t3d);
394
/* Tap 3 level (dB) (float value) */
395
const LADSPA_Data t3a_db = *(plugin_data->t3a_db);
397
/* Tap 4 distance (inches) (float value) */
398
const LADSPA_Data t4d = *(plugin_data->t4d);
400
/* Tap 4 level (dB) (float value) */
401
const LADSPA_Data t4a_db = *(plugin_data->t4a_db);
403
/* Input (array of floats of length sample_count) */
404
const LADSPA_Data * const input = plugin_data->input;
406
/* Output (array of floats of length sample_count) */
407
LADSPA_Data * const output = plugin_data->output;
408
LADSPA_Data * buffer = plugin_data->buffer;
409
unsigned int buffer_mask = plugin_data->buffer_mask;
410
unsigned int buffer_size = plugin_data->buffer_size;
411
LADSPA_Data last2_in = plugin_data->last2_in;
412
LADSPA_Data last3_in = plugin_data->last3_in;
413
LADSPA_Data last_in = plugin_data->last_in;
414
unsigned int last_phase = plugin_data->last_phase;
415
float phase = plugin_data->phase;
416
int sample_rate = plugin_data->sample_rate;
417
LADSPA_Data z0 = plugin_data->z0;
418
LADSPA_Data z1 = plugin_data->z1;
419
LADSPA_Data z2 = plugin_data->z2;
421
#line 59 "tape_delay_1211.xml"
423
float increment = f_clamp(speed, 0.0f, 40.0f);
424
float lin_int, lin_inc;
429
const float da = DB_CO(da_db);
430
const float t1a = DB_CO(t1a_db);
431
const float t2a = DB_CO(t2a_db);
432
const float t3a = DB_CO(t3a_db);
433
const float t4a = DB_CO(t4a_db);
434
const unsigned int t1d_s = f_round(t1d * sample_rate);
435
const unsigned int t2d_s = f_round(t2d * sample_rate);
436
const unsigned int t3d_s = f_round(t3d * sample_rate);
437
const unsigned int t4d_s = f_round(t4d * sample_rate);
439
for (pos = 0; pos < sample_count; pos++) {
440
fph = f_trunc(phase);
442
lin_int = phase - (float)fph;
444
out = buffer[(unsigned int)(fph - t1d_s) & buffer_mask] * t1a;
445
out += buffer[(unsigned int)(fph - t2d_s) & buffer_mask] * t2a;
446
out += buffer[(unsigned int)(fph - t3d_s) & buffer_mask] * t3a;
447
out += buffer[(unsigned int)(fph - t4d_s) & buffer_mask] * t4a;
450
lin_inc = 1.0f / (floor(phase) - last_phase + 1);
451
lin_inc = lin_inc > 1.0f ? 1.0f : lin_inc;
453
for (track = last_phase; track < phase; track++) {
455
buffer[track & buffer_mask] =
456
cube_interp(lin_int, last3_in, last2_in, last_in, input[pos]);
460
last_in = input[pos];
461
out += input[pos] * da;
462
buffer_write(output[pos], out);
463
if (phase >= buffer_size) {
464
phase -= buffer_size;
468
// Store current phase in instance
469
plugin_data->phase = phase;
470
plugin_data->last_phase = last_phase;
471
plugin_data->last_in = last_in;
472
plugin_data->last2_in = last2_in;
473
plugin_data->last3_in = last3_in;
474
plugin_data->z0 = z0;
475
plugin_data->z1 = z1;
476
plugin_data->z2 = z2;
481
LADSPA_PortDescriptor *port_descriptors;
482
LADSPA_PortRangeHint *port_range_hints;
485
#define D_(s) dgettext(PACKAGE, s)
486
setlocale(LC_ALL, "");
487
bindtextdomain(PACKAGE, PACKAGE_LOCALE_DIR);
493
tapeDelayDescriptor =
494
(LADSPA_Descriptor *)malloc(sizeof(LADSPA_Descriptor));
496
if (tapeDelayDescriptor) {
497
tapeDelayDescriptor->UniqueID = 1211;
498
tapeDelayDescriptor->Label = "tapeDelay";
499
tapeDelayDescriptor->Properties =
501
tapeDelayDescriptor->Name =
502
D_("Tape Delay Simulation");
503
tapeDelayDescriptor->Maker =
504
"Steve Harris <steve@plugin.org.uk>";
505
tapeDelayDescriptor->Copyright =
507
tapeDelayDescriptor->PortCount = 12;
509
port_descriptors = (LADSPA_PortDescriptor *)calloc(12,
510
sizeof(LADSPA_PortDescriptor));
511
tapeDelayDescriptor->PortDescriptors =
512
(const LADSPA_PortDescriptor *)port_descriptors;
514
port_range_hints = (LADSPA_PortRangeHint *)calloc(12,
515
sizeof(LADSPA_PortRangeHint));
516
tapeDelayDescriptor->PortRangeHints =
517
(const LADSPA_PortRangeHint *)port_range_hints;
519
port_names = (char **)calloc(12, sizeof(char*));
520
tapeDelayDescriptor->PortNames =
521
(const char **)port_names;
523
/* Parameters for Tape speed (inches/sec, 1=normal) */
524
port_descriptors[TAPEDELAY_SPEED] =
525
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
526
port_names[TAPEDELAY_SPEED] =
527
D_("Tape speed (inches/sec, 1=normal)");
528
port_range_hints[TAPEDELAY_SPEED].HintDescriptor =
529
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_1;
530
port_range_hints[TAPEDELAY_SPEED].LowerBound = 0;
531
port_range_hints[TAPEDELAY_SPEED].UpperBound = 10;
533
/* Parameters for Dry level (dB) */
534
port_descriptors[TAPEDELAY_DA_DB] =
535
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
536
port_names[TAPEDELAY_DA_DB] =
537
D_("Dry level (dB)");
538
port_range_hints[TAPEDELAY_DA_DB].HintDescriptor =
539
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM;
540
port_range_hints[TAPEDELAY_DA_DB].LowerBound = -90;
541
port_range_hints[TAPEDELAY_DA_DB].UpperBound = 0;
543
/* Parameters for Tap 1 distance (inches) */
544
port_descriptors[TAPEDELAY_T1D] =
545
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
546
port_names[TAPEDELAY_T1D] =
547
D_("Tap 1 distance (inches)");
548
port_range_hints[TAPEDELAY_T1D].HintDescriptor =
549
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
550
port_range_hints[TAPEDELAY_T1D].LowerBound = 0;
551
port_range_hints[TAPEDELAY_T1D].UpperBound = 4;
553
/* Parameters for Tap 1 level (dB) */
554
port_descriptors[TAPEDELAY_T1A_DB] =
555
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
556
port_names[TAPEDELAY_T1A_DB] =
557
D_("Tap 1 level (dB)");
558
port_range_hints[TAPEDELAY_T1A_DB].HintDescriptor =
559
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_0;
560
port_range_hints[TAPEDELAY_T1A_DB].LowerBound = -90;
561
port_range_hints[TAPEDELAY_T1A_DB].UpperBound = 0;
563
/* Parameters for Tap 2 distance (inches) */
564
port_descriptors[TAPEDELAY_T2D] =
565
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
566
port_names[TAPEDELAY_T2D] =
567
D_("Tap 2 distance (inches)");
568
port_range_hints[TAPEDELAY_T2D].HintDescriptor =
569
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_LOW;
570
port_range_hints[TAPEDELAY_T2D].LowerBound = 0;
571
port_range_hints[TAPEDELAY_T2D].UpperBound = 4;
573
/* Parameters for Tap 2 level (dB) */
574
port_descriptors[TAPEDELAY_T2A_DB] =
575
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
576
port_names[TAPEDELAY_T2A_DB] =
577
D_("Tap 2 level (dB)");
578
port_range_hints[TAPEDELAY_T2A_DB].HintDescriptor =
579
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM;
580
port_range_hints[TAPEDELAY_T2A_DB].LowerBound = -90;
581
port_range_hints[TAPEDELAY_T2A_DB].UpperBound = 0;
583
/* Parameters for Tap 3 distance (inches) */
584
port_descriptors[TAPEDELAY_T3D] =
585
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
586
port_names[TAPEDELAY_T3D] =
587
D_("Tap 3 distance (inches)");
588
port_range_hints[TAPEDELAY_T3D].HintDescriptor =
589
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MIDDLE;
590
port_range_hints[TAPEDELAY_T3D].LowerBound = 0;
591
port_range_hints[TAPEDELAY_T3D].UpperBound = 4;
593
/* Parameters for Tap 3 level (dB) */
594
port_descriptors[TAPEDELAY_T3A_DB] =
595
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
596
port_names[TAPEDELAY_T3A_DB] =
597
D_("Tap 3 level (dB)");
598
port_range_hints[TAPEDELAY_T3A_DB].HintDescriptor =
599
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM;
600
port_range_hints[TAPEDELAY_T3A_DB].LowerBound = -90;
601
port_range_hints[TAPEDELAY_T3A_DB].UpperBound = 0;
603
/* Parameters for Tap 4 distance (inches) */
604
port_descriptors[TAPEDELAY_T4D] =
605
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
606
port_names[TAPEDELAY_T4D] =
607
D_("Tap 4 distance (inches)");
608
port_range_hints[TAPEDELAY_T4D].HintDescriptor =
609
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_HIGH;
610
port_range_hints[TAPEDELAY_T4D].LowerBound = 0;
611
port_range_hints[TAPEDELAY_T4D].UpperBound = 4;
613
/* Parameters for Tap 4 level (dB) */
614
port_descriptors[TAPEDELAY_T4A_DB] =
615
LADSPA_PORT_INPUT | LADSPA_PORT_CONTROL;
616
port_names[TAPEDELAY_T4A_DB] =
617
D_("Tap 4 level (dB)");
618
port_range_hints[TAPEDELAY_T4A_DB].HintDescriptor =
619
LADSPA_HINT_BOUNDED_BELOW | LADSPA_HINT_BOUNDED_ABOVE | LADSPA_HINT_DEFAULT_MINIMUM;
620
port_range_hints[TAPEDELAY_T4A_DB].LowerBound = -90;
621
port_range_hints[TAPEDELAY_T4A_DB].UpperBound = 0;
623
/* Parameters for Input */
624
port_descriptors[TAPEDELAY_INPUT] =
625
LADSPA_PORT_INPUT | LADSPA_PORT_AUDIO;
626
port_names[TAPEDELAY_INPUT] =
628
port_range_hints[TAPEDELAY_INPUT].HintDescriptor = 0;
630
/* Parameters for Output */
631
port_descriptors[TAPEDELAY_OUTPUT] =
632
LADSPA_PORT_OUTPUT | LADSPA_PORT_AUDIO;
633
port_names[TAPEDELAY_OUTPUT] =
635
port_range_hints[TAPEDELAY_OUTPUT].HintDescriptor = 0;
637
tapeDelayDescriptor->activate = activateTapeDelay;
638
tapeDelayDescriptor->cleanup = cleanupTapeDelay;
639
tapeDelayDescriptor->connect_port = connectPortTapeDelay;
640
tapeDelayDescriptor->deactivate = NULL;
641
tapeDelayDescriptor->instantiate = instantiateTapeDelay;
642
tapeDelayDescriptor->run = runTapeDelay;
643
tapeDelayDescriptor->run_adding = runAddingTapeDelay;
644
tapeDelayDescriptor->set_run_adding_gain = setRunAddingGainTapeDelay;
649
if (tapeDelayDescriptor) {
650
free((LADSPA_PortDescriptor *)tapeDelayDescriptor->PortDescriptors);
651
free((char **)tapeDelayDescriptor->PortNames);
652
free((LADSPA_PortRangeHint *)tapeDelayDescriptor->PortRangeHints);
653
free(tapeDelayDescriptor);