-
Notifications
You must be signed in to change notification settings - Fork 10
/
rkrlv2.C
5034 lines (4281 loc) · 121 KB
/
rkrlv2.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
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//Spencer Jackson
#include<lv2.h>
#include<lv2/lv2plug.in/ns/ext/urid/urid.h>
#include<lv2/lv2plug.in/ns/ext/midi/midi.h>
#include<lv2/lv2plug.in/ns/ext/atom/util.h>
#include<lv2/lv2plug.in/ns/ext/atom/forge.h>
#include<lv2/lv2plug.in/ns/ext/time/time.h>
#include<lv2/lv2plug.in/ns/ext/buf-size/buf-size.h>
#include<lv2/lv2plug.in/ns/ext/options/options.h>
#include<lv2/lv2plug.in/ns/ext/atom/atom.h>
#include<lv2/lv2plug.in/ns/ext/patch/patch.h>
#include<lv2/lv2plug.in/ns/ext/worker/worker.h>
#include<lv2/lv2plug.in/ns/ext/state/state.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include<unistd.h>
#include<samplerate.h>
#include"rkrlv2.h"
#include"EQ.h"
#include"Compressor.h"
#include"Distorsion.h"
#include"Echo.h"
#include"Chorus.h"
#include"APhaser.h"
#include"Harmonizer.h"
#include"RecChord.h"
#include"RecognizeNote.h"
#include"Exciter.h"
#include"Pan.h"
#include"Alienwah.h"
#include"Reverb.h"
#include"Cabinet.h"
#include"MusicDelay.h"
#include"DynamicFilter.h"
#include"NewDist.h"
#include"Valve.h"
#include"Dual_Flange.h"
#include"Ring.h"
#include"MBDist.h"
#include"Arpie.h"
#include"Expander.h"
#include"Shuffle.h"
#include"Synthfilter.h"
#include"MBVvol.h"
#include"RyanWah.h"
#include"RBEcho.h"
#include"CoilCrafter.h"
#include"ShelfBoost.h"
#include"Vocoder.h"
#include"Sequence.h"
#include"Shifter.h"
#include"StompBox.h"
#include"Reverbtron.h"
#include"Echotron.h"
#include"StereoHarm.h"
#include"CompBand.h"
#include"Opticaltrem.h"
#include"Vibe.h"
#include"Infinity.h"
#include"Phaser.h"
#include"Gate.h"
//this is the default hopefully hosts don't use periods of more than this, or they will communicate the max bufsize
#define INTERMEDIATE_BUFSIZE 1024
#define MAX_INPLACE 8192
typedef struct _RKRLV2
{
uint8_t nparams;
uint8_t effectindex;//index of effect
uint16_t period_max;
uint8_t loading_file;//flag to indicate that file load work is underway
uint8_t init_params; //flag to indicate to force parameter (LFO) update & sample update on first run
uint8_t file_changed;
uint8_t prev_bypass;
RvbFile* rvbfile;//file for reverbtron
DlyFile* dlyfile;//file for echotron
//ports
float *input_l_p;
float *input_r_p;
float *output_l_p;
float *output_r_p;
float *bypass_p;
const LV2_Atom_Sequence* atom_in_p;
LV2_Atom_Sequence* atom_out_p;
float *param_p[20];
float *dbg_p;
// no-inplace buffers
float input_buf_l[MAX_INPLACE];
float input_buf_r[MAX_INPLACE];
//various "advanced" lv2 stuffs
LV2_Worker_Schedule* scheduler;
LV2_Atom_Forge forge;
LV2_Atom_Forge_Frame atom_frame;
LV2_URID_Map *urid_map;
struct urids
{
LV2_URID midi_MidiEvent;
LV2_URID atom_Float;
LV2_URID atom_Int;
LV2_URID atom_Object;
LV2_URID atom_Path;
LV2_URID atom_URID;
LV2_URID bufsz_max;
LV2_URID patch_Set;
LV2_URID patch_Get;
LV2_URID patch_property;
LV2_URID patch_value;
LV2_URID filetype_rvb;
LV2_URID filetype_dly;
} URIDs;
//effect modules
EQ* eq; //0, 11
Compressor* comp; //1
Distorsion* dist; //2
Echo* echo; //3
Chorus* chorus; //4
Analog_Phaser* aphase;//5
Harmonizer* harm; //6
RecChord* chordID;
Recognize* noteID;
Exciter* exciter; //7
Pan* pan; //8
Alienwah* alien; //9
Reverb* reve; //10
Cabinet* cab; //12
MusicDelay* mdel; //13
DynamicFilter* wah; //14
NewDist* dere; //15
Valve* valve; //16
Dflange* dflange; //17
Ring* ring; //18
MBDist* mbdist; //19
Arpie* arp; //20
Expander* expand; //21
Shuffle* shuf; //22
Synthfilter* synth; //23
MBVvol* mbvol; //24
RyanWah* mutro; //25
RBEcho* echoverse; //26
CoilCrafter* coil; //27
ShelfBoost* shelf; //28
Vocoder* voc; //29
Sustainer* sus; //30
Sequence* seq; //31
Shifter* shift; //32
StompBox* stomp; //33,34
Reverbtron* revtron;//35
Echotron* echotron; //36
StereoHarm* sharm; //37
CompBand* mbcomp; //38
Opticaltrem* otrem; //39
Vibe* vibe; //40
Infinity* inf; //41
Phaser* phase; //42
Gate* gate; //43
} RKRLV2;
enum other_ports
{
//be sure to account for index of array vs lv2 port index
HARMONIZER_MIDI,//unassigned right now
VOCODER_AUX_IN = 7,
VOCODER_VU_LEVEL = 8
};
// A few helper functions taken from the RKR object
void
wetdry_mix (RKRLV2* plug, float mix, uint32_t period)
{
unsigned int i;
float v1, v2;
if (mix < 0.5f)
{
v1 = 1.0f;
v2 = mix * 2.0f;
}
else
{
v1 = (1.0f - mix) * 2.0f;
v2 = 1.0f;
};
// Reverb and musical delay are exceptions for some reason?
// if ((NumEffect == 8) || (NumEffect == 15))
// v2 *= v2;
for (i = 0; i < period; i++)
{
plug->output_l_p[i] = plug->input_l_p[i] * v2 + plug->output_l_p[i] * v1;
plug->output_r_p[i] = plug->input_r_p[i] * v2 + plug->output_r_p[i] * v1;
};
}
//this finds the peak value
int
have_signal(float* efxoutl, float* efxoutr, uint32_t period)
{
float tmp;
uint32_t i;
float il_sum = 1e-12f;
float ir_sum = 1e-12f;
for (i = 0; i <= period; i++) {
tmp = fabsf (efxoutl[i]);
if (tmp > il_sum) il_sum = tmp;
tmp = fabsf (efxoutr[i]);
if (tmp > ir_sum) ir_sum = tmp;
}
if ((il_sum+ir_sum) > 0.0004999f) return 1;
else return 0;
}
static void
inplace_check (RKRLV2* plug, uint32_t period)
{
if (period > MAX_INPLACE) {
return;
}
if (plug->input_l_p == plug->output_l_p) {
memcpy (plug->input_buf_l, plug->input_l_p, sizeof(float) * period);
plug->input_l_p = plug->input_buf_l;
}
if (plug->input_r_p == plug->output_r_p) {
memcpy (plug->input_buf_r, plug->input_r_p, sizeof(float) * period);
plug->input_r_p = plug->input_buf_l;
}
}
static void
bypass_stereo (RKRLV2* plug, uint32_t nframes)
{
// copy only if needed. memcpy() src/dest memory areas must not overlap.
if (plug->output_l_p != plug->input_l_p) {
memcpy(plug->output_l_p,plug->input_l_p,sizeof(float)*nframes);
}
if (plug->output_r_p != plug->input_r_p) {
memcpy(plug->output_r_p,plug->input_r_p,sizeof(float)*nframes);
}
}
static void
prepare_inplace (RKRLV2* plug, uint32_t nframes)
{
/* When a plugin processes in-place, but the
* host provides separate i/o buffers,
* copy inputs to outputs */
bypass_stereo(plug,nframes);
/* when a host provides inplace buffers,
* make a backup f x-fade IFF required
*/
if (*plug->bypass_p || plug->prev_bypass) {
inplace_check (plug,nframes);
}
}
void
xfade_in (RKRLV2* plug, uint32_t period)
{
unsigned int i;
float v = 0;
float step = 1/(float)period;
//just a linear fade since it's (hopefully) correlated
for (i = 0; i < period; i++)
{
plug->output_l_p[i] = (v)*plug->output_l_p[i] + (1-v)*plug->input_l_p[i];
plug->output_r_p[i] = (v)*plug->output_r_p[i] + (1-v)*plug->input_r_p[i];
v+=step;
}
}
void
xfade_out (RKRLV2* plug, uint32_t period)
{
unsigned int i;
float v = 0;
float step = 1/(float)period;
//just a linear fade since it's (hopefully) correlated
for (i = 0; i < period; i++)
{
plug->output_l_p[i] = (1-v)*plug->output_l_p[i] + v*plug->input_l_p[i];
plug->output_r_p[i] = (1-v)*plug->output_r_p[i] + v*plug->input_r_p[i];
v+=step;
}
}
void
xfade_check (RKRLV2* plug, uint32_t period)
{
if(*plug->bypass_p)
{
plug->prev_bypass = 1;
xfade_out(plug,period);
}
else if(plug->prev_bypass)
{
plug->prev_bypass = 0;
xfade_in(plug,period);
}
}
//TODO: make this return error is required feature not supported
void getFeatures(RKRLV2* plug, const LV2_Feature * const* host_features)
{
uint8_t i,j;
plug->period_max = INTERMEDIATE_BUFSIZE;
plug->loading_file = 0;
plug->file_changed = 0;
plug->scheduler = 0;
plug->urid_map = 0;
for(i=0; host_features[i]; i++)
{ if(!strcmp(host_features[i]->URI,LV2_OPTIONS__options)) { LV2_Options_Option* option; option = (LV2_Options_Option*)host_features[i]->data;
for(j=0; option[j].key; j++)
{
if(option[j].key == plug->URIDs.bufsz_max)
{
if(option[j].type == plug->URIDs.atom_Int)
{
plug->period_max = *(const int*)option[j].value;
}
//other types?
}
}
}
else if(!strcmp(host_features[i]->URI,LV2_WORKER__schedule))
{
plug->scheduler = (LV2_Worker_Schedule*)host_features[i]->data;
}
else if(!strcmp(host_features[i]->URI,LV2_URID__map))
{
plug->urid_map = (LV2_URID_Map *) host_features[i]->data;
if(plug->urid_map)
{
plug->URIDs.midi_MidiEvent = plug->urid_map->map(plug->urid_map->handle,LV2_MIDI__MidiEvent);
plug->URIDs.atom_Float = plug->urid_map->map(plug->urid_map->handle,LV2_ATOM__Float);
plug->URIDs.atom_Int = plug->urid_map->map(plug->urid_map->handle,LV2_ATOM__Int);
plug->URIDs.atom_Object = plug->urid_map->map(plug->urid_map->handle,LV2_ATOM__Object);
plug->URIDs.atom_Path = plug->urid_map->map(plug->urid_map->handle,LV2_ATOM__Path);
plug->URIDs.atom_URID = plug->urid_map->map(plug->urid_map->handle,LV2_ATOM__URID);
plug->URIDs.bufsz_max = plug->urid_map->map(plug->urid_map->handle,LV2_BUF_SIZE__maxBlockLength);
plug->URIDs.patch_Set = plug->urid_map->map(plug->urid_map->handle,LV2_PATCH__Set);
plug->URIDs.patch_Get = plug->urid_map->map(plug->urid_map->handle,LV2_PATCH__Get);
plug->URIDs.patch_property = plug->urid_map->map(plug->urid_map->handle,LV2_PATCH__property);
plug->URIDs.patch_value = plug->urid_map->map(plug->urid_map->handle,LV2_PATCH__value);
plug->URIDs.filetype_rvb = plug->urid_map->map(plug->urid_map->handle,RVBFILE_URI);
plug->URIDs.filetype_dly = plug->urid_map->map(plug->urid_map->handle,DLYFILE_URI);
}
}
}
}
/////////////////////////////////////////
// EFFECTS
////////////////////////////////////////
///// EQ /////////
LV2_Handle init_eqlv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 12;
plug->effectindex = IEQ;
plug->prev_bypass = 1;
getFeatures(plug,host_features);
plug->eq = new EQ(0,0,sample_freq, plug->period_max);
//eq has a bunch of setup stuff. Why isn't this in the EQ initalizer?
for (int i = 0; i <= 45; i += 5)
{
plug->eq->changepar (i + 10, 7);
plug->eq->changepar (i + 14, 0);
}
plug->eq->changepar (11, 31);
plug->eq->changepar (16, 63);
plug->eq->changepar (21, 125);
plug->eq->changepar (26, 250);
plug->eq->changepar (31, 500);
plug->eq->changepar (36, 1000);
plug->eq->changepar (41, 2000);
plug->eq->changepar (46, 4000);
plug->eq->changepar (51, 8000);
plug->eq->changepar (56, 16000);
return plug;
}
void run_eqlv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//check and set changed parameters
i = 0;
val = (int)*plug->param_p[0]+64;//gain
if(plug->eq->getpar(0) != val)
{
plug->eq->changepar(0,val);
}
val = (int)*plug->param_p[1]+64;//q
if(plug->eq->getpar(13) != val)
{
int j;
for(j=0; j<10; j++)
{
plug->eq->changepar(j*5+13,val);
}
}
for(i=2; i<plug->nparams; i++)
{
val = (int)*plug->param_p[i]+64;//various freq. bands
if(plug->eq->getpar(5*i + 2) != val)
{
plug->eq->changepar(5*i+2,val);
}
}
//eq does process in-place ?
prepare_inplace (plug, nframes);
//now set out ports
plug->eq->efxoutl = plug->output_l_p;
plug->eq->efxoutr = plug->output_r_p;
//now run
plug->eq->out(plug->output_l_p,plug->output_r_p,nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->eq->cleanup();
}
return;
}
///// comp /////////
LV2_Handle init_complv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 9;
plug->effectindex = ICOMP;
plug->prev_bypass = 1;
plug->comp = new Compressor(0,0, sample_freq);
return plug;
}
void run_complv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//check and set changed parameters
for(i=0; i<plug->nparams; i++)
{
val = (int)*plug->param_p[i];
if(plug->comp->getpar(i+1) != val)//this effect is 1 indexed
{
plug->comp->Compressor_Change(i+1,val);
}
}
//comp does process in-place
prepare_inplace (plug, nframes);
//now set out ports
plug->comp->efxoutl = plug->output_l_p;
plug->comp->efxoutr = plug->output_r_p;
//now run
plug->comp->out(plug->output_l_p,plug->output_r_p,nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->comp->cleanup();
}
return;
}
///// dist /////////
LV2_Handle init_distlv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 12;
plug->effectindex = IDIST;
plug->prev_bypass = 1;
getFeatures(plug,host_features);
plug->dist = new Distorsion(0,0, sample_freq, plug->period_max, /*oversampling*/2,
/*up interpolation method*/4, /*down interpolation method*/2);
return plug;
}
void run_distlv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//check and set changed parameters
i=0;
val = (int)*plug->param_p[i];//0 Wet/dry
if(plug->dist->getpar(i) != val)
{
plug->dist->changepar(i,val);
}
i++;
val = (int)*plug->param_p[i]+64;//1 pan
if(plug->dist->getpar(i) != val)
{
plug->dist->changepar(i,val);
}
for(i++; i<plug->nparams-1; i++) //2-10
{
val = (int)*plug->param_p[i];
if(plug->dist->getpar(i) != val)
{
plug->dist->changepar(i,val);
}
}
val = (int)*plug->param_p[i++];//skip one index, 12 octave
if(plug->dist->getpar(i) != val)
{
plug->dist->changepar(i,val);
}
inplace_check(plug,nframes);
//now set out ports and global period size
plug->dist->efxoutl = plug->output_l_p;
plug->dist->efxoutr = plug->output_r_p;
//now run
plug->dist->out(plug->input_l_p,plug->input_r_p,nframes);
//and for whatever reason we have to do the wet/dry mix ourselves
wetdry_mix(plug, plug->dist->outvolume, nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->dist->cleanup();
}
return;
}
///// echo /////////
LV2_Handle init_echolv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 9;
plug->effectindex = IECHO;
plug->prev_bypass = 1;
plug->echo = new Echo(0,0,sample_freq);
return plug;
}
void run_echolv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//check and set changed parameters
i=0;
val = (int)*plug->param_p[i];//wet/dry
if(plug->echo->getpar(i) != val)
{
plug->echo->changepar(i,val);
}
i++;//panning is offset
val = (int)*plug->param_p[i]+64;
if(plug->echo->getpar(i) != val)
{
plug->echo->changepar(i,val);
}
i++;//delay is not offset
val = (int)*plug->param_p[i];
if(plug->echo->getpar(i) != val)
{
plug->echo->changepar(i,val);
}
i++;//LR delay is offset
val = (int)*plug->param_p[i]+64;
if(plug->echo->getpar(i) != val)
{
plug->echo->changepar(i,val);
}
for(i++; i<plug->nparams; i++)
{
val = (int)*plug->param_p[i];
if(plug->echo->getpar(i) != val)
{
plug->echo->changepar(i,val);
}
}
inplace_check(plug,nframes);
//now set out ports and global period size
plug->echo->efxoutl = plug->output_l_p;
plug->echo->efxoutr = plug->output_r_p;
//now run
plug->echo->out(plug->input_l_p,plug->input_r_p,nframes);
//and for whatever reason we have to do the wet/dry mix ourselves
wetdry_mix(plug, plug->echo->outvolume, nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->echo->cleanup();
}
return;
}
///// chorus/flanger /////////
LV2_Handle init_choruslv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 12;
plug->effectindex = ICHORUS;
plug->prev_bypass = 1;
plug->chorus = new Chorus(0,0,sample_freq);
return plug;
}
void run_choruslv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//LFO effects require period be set before setting other params
plug->chorus->PERIOD = nframes;
//check and set changed parameters
i=0;
val = (int)*plug->param_p[i];
if(plug->chorus->getpar(i) != val)
{
plug->chorus->changepar(i,val);
}
i++;
val = (int)*plug->param_p[i] +64;// 1 pan offset
if(plug->chorus->getpar(i) != val)
{
plug->chorus->changepar(i,val);
}
for(i++; i<5; i++) //2-4
{
val = (int)*plug->param_p[i];
if(plug->chorus->getpar(i) != val)
{
plug->chorus->changepar(i,val);
}
}
val = (int)*plug->param_p[i] +64;// 5 LR Del. offset
if(plug->chorus->getpar(i) != val)
{
plug->chorus->changepar(i,val);
}
for(i++; i<10; i++) // 6-9
{
val = (int)*plug->param_p[i];
if(plug->chorus->getpar(i) != val)
{
plug->chorus->changepar(i,val);
}
}
//skip param 10
for(; i<plug->nparams; i++)
{
val = (int)*plug->param_p[i];
if(plug->chorus->getpar(i+1) != val)
{
plug->chorus->changepar(i+1,val);
}
}
inplace_check(plug,nframes);
//now set out ports and global period size
plug->chorus->efxoutl = plug->output_l_p;
plug->chorus->efxoutr = plug->output_r_p;
//now run
plug->chorus->out(plug->input_l_p,plug->input_r_p,nframes);
//and for whatever reason we have to do the wet/dry mix ourselves
wetdry_mix(plug, plug->chorus->outvolume, nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->chorus->cleanup();
}
return;
}
///// Analog Phaser /////////
LV2_Handle init_aphaselv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 13;
plug->effectindex = IAPHASE;
plug->prev_bypass = 1;
plug->aphase = new Analog_Phaser(0,0,sample_freq);
return plug;
}
void run_aphaselv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//LFO effects require period be set before setting other params
plug->aphase->PERIOD = nframes;
//check and set changed parameters
for(i=0; i<5; i++) //0-4
{
val = (int)*plug->param_p[i];
if(plug->aphase->getpar(i) != val)
{
plug->aphase->changepar(i,val);
}
}
val = (int)*plug->param_p[i] +64;// 5 LR Del. offset
if(plug->aphase->getpar(i) != val)
{
plug->aphase->changepar(i,val);
}
i++;
val = (int)*plug->param_p[i];// 6
if(plug->aphase->getpar(i) != val)
{
plug->aphase->changepar(i,val);
}
i++;
val = (int)*plug->param_p[i] +64;// 7 Fb offset
if(plug->aphase->getpar(i) != val)
{
plug->aphase->changepar(i,val);
}
for(i++; i<plug->nparams; i++)
{
val = (int)*plug->param_p[i];
if(plug->aphase->getpar(i) != val)
{
plug->aphase->changepar(i,val);
}
}
inplace_check(plug,nframes);
//now set out ports and global period size
plug->aphase->efxoutl = plug->output_l_p;
plug->aphase->efxoutr = plug->output_r_p;
//now run
plug->aphase->out(plug->input_l_p,plug->input_r_p,nframes);
//and for whatever reason we have to do the wet/dry mix ourselves
wetdry_mix(plug, plug->aphase->outvolume, nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->aphase->cleanup();
}
return;
}
//////// harmonizer /////////
LV2_Handle init_harmnomidlv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 10;
plug->effectindex = IHARM_NM;
plug->prev_bypass = 1;
getFeatures(plug,host_features);
//magic numbers: shift qual 4, downsample 5, up qual 4, down qual 2,
plug->harm = new Harmonizer(0,0,4,5,SRC_LINEAR,SRC_SINC_FASTEST, plug->period_max, sample_freq);
plug->noteID = new Recognize(0,0,.6, sample_freq, 440.0, plug->period_max);//.6 is default trigger value
plug->chordID = new RecChord();
return plug;
}
void run_harmnomidlv2(LV2_Handle handle, uint32_t nframes)
{
int i;
int val;
RKRLV2* plug = (RKRLV2*)handle;
if(*plug->bypass_p && plug->prev_bypass)
{
bypass_stereo (plug, nframes);
return;
}
//check and set changed parameters
i = 0;
val = (int)*plug->param_p[i];// 0 wet/dry
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
}
for(i++; i<3; i++) //1-2
{
val = (int)*plug->param_p[i] + 64;
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
}
}
val = (int)*plug->param_p[i] + 12;// 3 interval
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
}
i++;
val = (int)*plug->param_p[i];//4 filter freq
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
}
i++;
val = (int)*plug->param_p[i];//5 select mode
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
plug->chordID->cleanup();
if(!val) plug->harm->changepar(3,plug->harm->getpar(3));
}
for(i++; i<8; i++) //6-7
{
val = (int)*plug->param_p[i];
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
plug->chordID->ctipo = plug->harm->getpar(7);//set chord type
plug->chordID->fundi = plug->harm->getpar(6);//set root note
plug->chordID->cc = 1;//mark chord has changed
}
}
for(; i<10; i++) // 8-9
{
val = (int)*plug->param_p[i] + 64;
if(plug->harm->getpar(i) != val)
{
plug->harm->changepar(i,val);
}
}
// midi mode, not implementing midi here
// val = (int)*plug->param_p[i];// 10 midi mode
// if(plug->aphase->getpar(i) != val)
// {
// plug->aphase->changepar(i,val);
// if(!val) plug->harm->changepar(3,plug->harm->getpar(3));
// }
/*
see Chord() in rkr.fl
harmonizer, need recChord and recNote.
see process.C ln 1507
*/
//TODO may need to make sure input is over some threshold
if(plug->harm->mira && plug->harm->PSELECT)
// && have_signal( plug->input_l_p, plug->input_r_p, nframes))
{
plug->noteID->schmittFloat(plug->input_l_p,plug->input_r_p,nframes);
if(plug->noteID->reconota != -1 && plug->noteID->reconota != plug->noteID->last)
{
if(plug->noteID->afreq > 0.0)
{
plug->chordID->Vamos(0,plug->harm->Pinterval - 12,plug->noteID->reconota);
plug->harm->r_ratio = plug->chordID->r__ratio[0];//pass the found ratio
}
}
}
inplace_check(plug,nframes);
//now set out ports and global period size
plug->harm->efxoutl = plug->output_l_p;
plug->harm->efxoutr = plug->output_r_p;
//now run
plug->harm->out(plug->input_l_p,plug->input_r_p,nframes);
//and for whatever reason we have to do the wet/dry mix ourselves
wetdry_mix(plug, plug->harm->outvolume, nframes);
xfade_check(plug,nframes);
if(plug->prev_bypass)
{
plug->harm->cleanup();
}
return;
}
///// exciter /////////
LV2_Handle init_exciterlv2(const LV2_Descriptor *descriptor,double sample_freq, const char *bundle_path,const LV2_Feature * const* host_features)
{
RKRLV2* plug = (RKRLV2*)malloc(sizeof(RKRLV2));
plug->nparams = 13;
plug->effectindex = IEXCITER;
plug->prev_bypass = 1;