This repository has been archived by the owner on Aug 17, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathVA.soul
4190 lines (3379 loc) · 141 KB
/
VA.soul
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
/** MIT License
Copyright (c) 2022 Zhe Deng
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
/** SOUL-VA (https://github.com/thezhe/SOUL-VA)
Effects are 'Processors' under 'VA::HighLevel'
Use with SOUL v1.0.82
The interface is nearly identical to soul::filters EXCEPT:
- Each effect has at least input and output SampleType streams named 'in' and 'out'
- All input events are of type 'float'
- Max gain applied via an effect (excluding Makeup) is about +6 dB.
In practice (depending on sampling rate), this value may be a few dB higher due to over/undersampling interpolation filters.
- No user-defined types:
*'SampleType' is float64<2>
*The internal 'CoeffType' is float64<2>
*Coefficient 'updateInterval' is every 1024 samples at 44.1kHz
or every (48/44.1)*1024 samples at 48 kHz (scales with sample rate)
- Parameters not suitable for modulation are commented as 'UNSMOOTHED' in their annotations.
Annotations with "boolean" and "text" values are assumed to be unsuitable for modulation.
- Meta parameters will have "Meta" in their event endpoint names.
- Expanded set of vector-friendly functions (see 'Vectorized Intrinsic/Helper' sections)
- Algebraic operations are preferred to avoid expensive transcendentals while providing superior
accuracy and click-free modulation when compared to lookup tables
See: https://en.wikipedia.org/wiki/Algebraic_function
- Non-iterative, analytical solutions are preferred, but not always guaranteed
See: https://math.stackexchange.com/questions/935405/what-s-the-difference-between-analytical-and-numerical-approaches-to-problems
- Common sampling rates from 44.1 to 192 kHz are supported, but the internal sampling rate will always be either
44.1 or 48 kHz. This allows for consistent rendering and antialiasing of all effects, including ones that behave
differently depending on sample rate.
- Each section is marked with a date of last stable update (MM/DD/YYYY)
*/
/** Next version (1.1.0) changelog
- New Effects: TheExpressor, TheSplit, TheUtility
- New QA Framework: PLUG-QA
- Updated Effects
- All common sample rates from 44.1 to 192 kHz supported
*/
/** Task List
- generic ADAA snippet and refactor
- smoothed parameter compile time
- TheSlewEQ, match 44.1 and 48 kHz sound, soft clip
- TheBass, TheSplit update to 192kHz support and TheExpressor standard
- low attack times the split, and compensate attack * 2 for attacks & sustains
- more Processors, include integrator processors, more modularity and oversampling/ADAA granularity
- TheBass boilerplate, abs before stereo link and rectified lan
- small dx approximation for hysteretic L
*/
namespace VA
{
/*==============================================================================
VA::HighLevel Processors 03/17/22
==============================================================================*/
/** High-level Processors made of components from 'VA' and 'soul' namespaces
ALL effects can behave nonlinearly and add their own 'virtual analog warmth'
*/
namespace HighLevel
{
/** Transient Designer with accurate
Use case: Mix the attack/sustain portions of a signal
*/
namespace TheSlap
{
graph Processor (float iHpfCutoffHz = 1,
float iStereoLinkPercent = 0,
float iAttackMs = 4,
float iSustainMs = 75,
float iSensitivity_dB = 24,
float iAttack_dB = 0,
float iSustain_dB = -60,
float iMaster_dB = 0)
{
input stream SampleType in;
output stream SampleType out;
input
{
smoothedVolume.volumeIn attackVolIn [[ name: "Attack", min: FLOAT_MIN_VOLUME - 0.1f, max: 12, init: iAttack_dB, step: 0.1f, unit: "dB", group: "Volume" ]];
smoothedVolume1.volumeIn sustainVolIn [[ name: "Sustain", min: FLOAT_MIN_VOLUME - 0.1f, max: 12, init: iSustain_dB, step: 0.1f, unit: "dB", group: "Volume" ]];
smoothedVolume2.volumeIn masterIn [[ name: "Master", min: -12, max: 12, init: iMaster_dB, step: 0.1f, unit: "dB", group: "Volume" ]];
}
let
{
internalDS0 = Internal::Processor (iHpfCutoffHz, iStereoLinkPercent, iAttackMs, iSustainMs, iSensitivity_dB);
internalDS2 = Internal::Processor (iHpfCutoffHz, iStereoLinkPercent, iAttackMs, iSustainMs, iSensitivity_dB) / 2;
internalDS4 = Internal::Processor (iHpfCutoffHz, iStereoLinkPercent, iAttackMs, iSustainMs, iSensitivity_dB) / 4;
mux3To1Fs = Mux3To1Fs::Processor;
mux3To1Fs1 = Mux3To1Fs::Processor;
smoothedVolume = SmoothedVolume::Processor (iAttack_dB);
smoothedVolume1 = SmoothedVolume::Processor (iSustain_dB);
sum = Sum::Processor;
smoothedVolume2 = SmoothedVolume::Processor (iMaster_dB);
}
connection
{
//shared input events
//dynamically downsample to 44.1/48 kHz
[sinc] in -> internalDS0.in, internalDS2.in, internalDS4.in;
[sinc] internalDS0.attackOut -> mux3To1Fs.in;
[sinc] internalDS2.attackOut -> mux3To1Fs.in1;
[sinc] internalDS4.attackOut -> mux3To1Fs.in2;
[sinc] internalDS0.sustainOut -> mux3To1Fs1.in;
[sinc] internalDS2.sustainOut -> mux3To1Fs1.in1;
[sinc] internalDS4.sustainOut -> mux3To1Fs1.in2;
//volume
mux3To1Fs.out -> smoothedVolume.in;
mux3To1Fs1.out -> smoothedVolume1.in;
smoothedVolume.out -> sum.in;
smoothedVolume1.out -> sum.in1;
sum.out -> smoothedVolume2.in;
smoothedVolume2.out -> out;
}
}
namespace Internal
{
graph Processor (float iHpfCutoffHz,
float iStereoLinkPercent,
float iAttackMs,
float iSustainMs,
float iSensitivity_dB)
{
input stream SampleType in;
output stream SampleType attackOut, sustainOut;
input
{
splitAttackSustain.cutoffHP_In;
splitAttackSustain.stereoLinkIn;
splitAttackSustain.attackIn;
splitAttackSustain.sustainIn;
splitAttackSustain.sensitivityIn;
}
let
{
splitAttackSustain = SplitAttackSustain::Processor (iHpfCutoffHz, iStereoLinkPercent, iAttackMs, iSustainMs, iSensitivity_dB);
}
connection
{
in -> splitAttackSustain.in;
splitAttackSustain.attackOut -> attackOut;
splitAttackSustain.sustainOut -> sustainOut;
}
}
}
}
/** Utility Processor
Use case: Mix, Pan, Makeup, and Complement
Notes:
- This is a common Processor and may be used in other Processors in this namespace
- Use directly; DO NOT over/undersample or add additional filtering.
*/
namespace TheUtility
{
namespace PanModeIdx
{
let Unlinked = 0;
let Linked = 1;
let Inverted = 2;
let NumIdxs = 3;
}
namespace AB_ModeIdx
{
let Dry = false;
let Wet = true;
let NumIdxs = 2;
}
namespace VolumeModeIdx
{
let WetDry = 0;
let WetMix = 1;
let WetAB = 2;
let NumIdxs = 3;
}
graph Processor(bool iWetComplementBool = false,
bool iInvertL_Bool = false,
bool iInvertR_Bool = false,
float iWet_dB = 0,
float iDry_dB = 0,
float iMixPercent = 100,
bool iAB_ModeIdx = AB_ModeIdx::Wet,
int iVolumeModeIdx = VolumeModeIdx::WetDry,
float iPanDry = 0,
float iPanWet = 0,
int iPanModeIdx = PanModeIdx::Unlinked)
{
input stream SampleType in, dryIn;
output stream SampleType out;
input
{
mux2To1.idxIn complementIn [[ name: "Complement", init: float (iWetComplementBool), boolean, group: "Wet" ]];
phaseInverts.invertL_In [[ name: "Invert L", init: float (iInvertL_Bool), boolean, group: "Wet" ]];
phaseInverts.invertR_In [[ name: "Invert R", init: float (iInvertR_Bool), boolean, group: "Wet" ]];
upWet.in volumeWetIn [[ name: "Wet", min: FLOAT_MIN_VOLUME - 0.1f, max: 24, init: iWet_dB, step: 0.1f, unit: "dB", group: "Volume" ]]; //maps to -inf dB if below FLOAT_MIN_VOLUME
upDry.in volumeDryIn [[ name: "Dry", min: FLOAT_MIN_VOLUME - 0.1f, max: 24, init: iDry_dB, step: 0.1f, unit: "dB", group: "Volume" ]];
upMix.in mixIn [[ name: "Mix", min: 0, max: 100, init: iMixPercent, unit: "%", step: 1, group: "Volume" ]];
upAB.in AB_In [[ name: "A/B", init: float (iAB_ModeIdx), boolean, text: "Dry|Wet", group: "Volume" ]];
event float volumeModeIn [[ name: "Mode", min: 0, init: iVolumeModeIdx, text: "Wet-Dry|Wet-Mix|Wet-A/B", group: "Volume" ]];
upPanWet.in panWetIn [[ name: "Wet", min: -1, max: 1, init: iPanWet, step: 0.01f, group: "Pan" ]];
upPanDry.in panDryIn [[ name: "Dry", min: -1, max: 1, init: iPanDry, step: 0.01f, group: "Pan" ]];
event float panModeMetaIn [[ name: "Mode", min: 0, init: iPanModeIdx, text: "Unlinked|Linked|Inverted", group: "Pan" ]];
}
let
{
//Wet
mux2To1 = Mux2To1::Processor (iWetComplementBool);
difference = Difference::Processor;
phaseInverts = PhaseInverts::Processor (iInvertL_Bool, iInvertR_Bool);
//Volume
upWet = UP::Processor (UP::ParameterType (iWet_dB), UP::ModeIdx::VolumeToGain);
upDry = UP::Processor (UP::ParameterType (iDry_dB), UP::ModeIdx::VolumeToGain);
upMix = UP::Processor (UP::ParameterType (iMixPercent), UP::ModeIdx::MixToGains);
upAB = UP::Processor (UP::ParameterType (iAB_ModeIdx), UP::ModeIdx::AB_ToGains);
//Pan
upPanWet = UP::Processor (UP::ParameterType (iPanWet), UP::ModeIdx::PanToGain);
upPanDry = UP::Processor (UP::ParameterType (iPanDry), UP::ModeIdx::PanToGain);
//gains, muxes, smoothing
streamToEvents = StreamToEvents::Processor;
streamToEvents1 = StreamToEvents::Processor;
sp = SP::Processor (SP::ParameterType (1), SP::ModeIdx::StereoGainsToGains);
applyGains = ApplyGains::Processor;
applyGain = ApplyGain::Processor;
applyGain1 = ApplyGain::Processor;
applyGain3 = ApplyGain::Processor;
applyGain4 = ApplyGain::Processor;
mux3To1 = Mux3To1::Processor (iVolumeModeIdx);
mux3To1_1 = Mux3To1::Processor (iVolumeModeIdx);
}
connection
{
//events
volumeModeIn -> mux3To1.idxIn, mux3To1_1.idxIn;
//Wet
dryIn -> difference.in;
in -> difference.in1, mux2To1.in;
difference.out -> mux2To1.in1;
mux2To1.out -> phaseInverts.in;
//Volume and Pan (Wet)
upWet.out -> applyGain.in, applyGain1.in, mux3To1.in;
upMix.out1 -> applyGain.b;
applyGain.out -> mux3To1.in1;
upAB.out1 -> applyGain1.b;
applyGain1.out -> mux3To1.in2;
upPanWet.out -> applyGain3.in;
mux3To1.out -> applyGain3.b;
applyGain3.out -> streamToEvents.in;
streamToEvents.out -> sp.in2;
streamToEvents.out1 -> sp.in3;
//Volume and Pan (Dry)
upDry.out -> mux3To1_1.in;
upMix.out -> mux3To1_1.in1;
upAB.out -> mux3To1_1.in2;
mux3To1_1.out -> applyGain4.in;
upPanDry.out -> applyGain4.b;
applyGain4.out -> streamToEvents1;
streamToEvents1.out -> sp.in;
streamToEvents1.out1 -> sp.in1;
//Apply Volume and Pan
dryIn -> applyGains.in;
sp.out -> applyGains.b;
phaseInverts.out -> applyGains.in1;
sp.out1 -> applyGains.b1;
applyGains.out -> out;
}
}
}
/** Signal splitter
Use case: Center/Sides (spatial), Crossover (frequency), Loud/Soft (amplitude), Attack/Sustain (time)
*/
namespace TheSplit
{
namespace Modes
{
let CenterSides = 0;
let LowHigh = 1;
let AttackSustain = 2;
let LoudSoft = 3;
let NumModes = 4;
}
graph Processor(int iMode = Modes::CenterSides,
bool iSwapOutputsBool = false,
float iCenterSidesPercent = 100,
float iFrequencyHz = 1000,
float iAttackMs = 4,
float iSustainMs = 30,
float iSensitivity_dB = 24,
float iThreshold_dB = -30,
float iReleaseMs = 30,
float iStereoLinkLsPercent = 0)
{
input stream SampleType in;
output stream SampleType out, out1;
input event
{
float modeIn [[ name: "Mode", min: 0, init: iMode, text: "C&S|L&H|A&S|L&S", group: "Main" /*UNSMOOTHED*/ ]];
float swapIn [[ name: "Output Swap", init: float (iSwapOutputsBool), boolean, group: "Main" /*UNSMOOTHED*/ ]];
float centerSidesIn [[ name: "Split Amount", min: 0, max: 100, init: iCenterSidesPercent, unit: "%", step: 1, group: "Centers & Sides" ]];
float frequencyIn [[ name: "Frequency", min: 20, max: 20000, init: iFrequencyHz, step: 1, unit: "Hz", group: "Lows & Highs" ]];
float attackIn [[ name: "Attack", min: 4, max: 26, init: iAttackMs, step: 1, unit: "ms", group: "Attacks & Sustains" ]];
float sustainIn [[ name: "Sustain", min: 30, max: 200, init: iSustainMs, step: 1, unit: "ms", group: "Attacks & Sustains" ]];
float sensitivityIn [[ name: "Sensitivity", min: 0, max: 36, init: iSensitivity_dB, step: 1, unit: "dB", group: "Attacks & Sustains" ]];
float thresholdIn [[ name: "Threshold", min: -50, max: 0, init: iThreshold_dB, unit: "dB", step: 1, group: "Louds & Softs" ]];
float releaseIn [[ name: "Release", min: 30, max: 999, init: iReleaseMs, unit: "ms", step: 1, group: "Louds & Softs" ]];
float stereoLinkLsIn [[ name: "Stereo Link", min: 0, max: 100, init: iStereoLinkLsPercent, unit: "%", step: 1, group: "Louds & Softs" ]];
}
let
{
internalDS0 = Internal::Processor (iMode, iSwapOutputsBool, iCenterSidesPercent, iFrequencyHz, iAttackMs, iSustainMs, iSensitivity_dB, iThreshold_dB, iReleaseMs, iStereoLinkLsPercent);
internalDS2 = Internal::Processor (iMode, iSwapOutputsBool, iCenterSidesPercent, iFrequencyHz, iAttackMs, iSustainMs, iSensitivity_dB, iThreshold_dB, iReleaseMs, iStereoLinkLsPercent) / 2;
internalDS4 = Internal::Processor (iMode, iSwapOutputsBool, iCenterSidesPercent, iFrequencyHz, iAttackMs, iSustainMs, iSensitivity_dB, iThreshold_dB, iReleaseMs, iStereoLinkLsPercent) / 4;
mux3To1Fs = Mux3To1Fs::Processor;
mux3To1Fs1 = Mux3To1Fs::Processor;
}
connection
{
//shared input events
modeIn -> internalDS0.modeIn, internalDS2.modeIn, internalDS4.modeIn;
swapIn -> internalDS0.swapIn, internalDS2.swapIn, internalDS4.swapIn;
frequencyIn -> internalDS0.frequencyIn, internalDS2.frequencyIn, internalDS4.frequencyIn;
attackIn -> internalDS0.attackIn, internalDS2.attackIn, internalDS4.attackIn;
releaseIn -> internalDS0.releaseIn, internalDS2.releaseIn, internalDS4.releaseIn;
sensitivityIn -> internalDS0.sensitivityIn, internalDS2.sensitivityIn, internalDS4.sensitivityIn;
thresholdIn -> internalDS0.thresholdIn, internalDS2.thresholdIn, internalDS4.thresholdIn;
releaseIn -> internalDS0.releaseIn, internalDS2.releaseIn, internalDS4.releaseIn;
stereoLinkLsIn -> internalDS0.stereoLinkLsIn, internalDS2.stereoLinkLsIn, internalDS4.stereoLinkLsIn;
//dynamically downsample to 44.1/48 kHz
[sinc] in -> internalDS0.in, internalDS2.in, internalDS4.in;
[sinc] internalDS0.out -> mux3To1Fs.in;
[sinc] internalDS2.out -> mux3To1Fs.in1;
[sinc] internalDS4.out -> mux3To1Fs.in2;
[sinc] internalDS0.out1 -> mux3To1Fs1.in;
[sinc] internalDS2.out1 -> mux3To1Fs1.in1;
[sinc] internalDS4.out1 -> mux3To1Fs1.in2;
mux3To1Fs.out -> out;
mux3To1Fs1.out -> out1;
}
}
namespace Internal
{
graph Processor(int iMode,
bool iSwapOutputsBool,
float iCenterSidesPercent,
float iFrequencyHz,
float iAttackMs,
float iSustainMs,
float iSensitivity_dB,
float iThreshold_dB,
float iReleaseMs,
float iStereoLinkLsPercent)
{
input stream SampleType in;
output stream SampleType out, out1;
input
{
event float modeIn;
event float swapIn;
splitCenterSides.centerSidesIn;
pCrossover.frequencyIn;
splitAttackSustain.attackIn;
splitAttackSustain.sustainIn;
splitAttackSustain.sensitivityIn;
splitLoudSoft.thresholdIn;
splitLoudSoft.releaseIn;
splitLoudSoft.stereoLinkIn stereoLinkLsIn;
}
let
{
//non-boilerplate Processors
splitCenterSides = SplitCenterSides::Processor (iCenterSidesPercent);
pCrossover = filt::tpt::crossover::Processor (iFrequencyHz);
splitAttackSustain = SplitAttackSustain::Processor (1, 100, iAttackMs, iSustainMs, iSensitivity_dB);
splitLoudSoft = SplitLoudSoft::Processor (iThreshold_dB, iReleaseMs, iStereoLinkLsPercent);
mux4To1_0 = Mux4To1::Processor (iMode);
mux4To1_1 = Mux4To1::Processor (iMode);
mux2To1_0 = Mux2To1::Processor (iSwapOutputsBool);
mux2To1_1 = Mux2To1::Processor (iSwapOutputsBool);
//boilerplate Processors
dcBlockerIn = DC_Blocker::Processor;
dcBlockerOut = DC_Blocker::Processor;
dcBlockerOut1 = DC_Blocker::Processor;
}
connection
{
modeIn -> mux4To1_0.idxIn, mux4To1_1.idxIn;
swapIn -> mux2To1_0.idxIn, mux2To1_1.idxIn;
in -> dcBlockerIn -> splitCenterSides.in, pCrossover.in, splitLoudSoft.in, splitAttackSustain.in;
splitCenterSides.centerOut -> mux4To1_0.in;
splitCenterSides.sidesOut -> mux4To1_1.in;
pCrossover.lowOut -> mux4To1_0.in1;
pCrossover.highOut -> mux4To1_1.in1;
splitAttackSustain.attackOut -> mux4To1_0.in2;
splitAttackSustain.sustainOut -> mux4To1_1.in2;
splitLoudSoft.loudOut -> mux4To1_0.in3;
splitLoudSoft.softOut -> mux4To1_1.in3;
mux4To1_0.out -> mux2To1_0.in, mux2To1_1.in1;
mux4To1_1.out -> mux2To1_0.in1, mux2To1_1.in;
mux2To1_0.out -> dcBlockerOut -> out;
mux2To1_1.out -> dcBlockerOut1 -> out1;
}
}
}
}
/** Upwards/Downwards (Ex)pander/Com(pressor) with a colored knee
Notes:
- Use case: limiter, general dynamics processor, parallel/ny compression, sidechain, emphasis/de-emphasis
- Tail: 0.5 s
*/
namespace TheExpressor
{
graph Processor(bool iSidechainBool = false,
float iAttackMs = 0.1f,
float iReleaseMs = 30,
float iStereoLinkPercent = 0,
float iThreshold_dB = -50,
float iRatio = 20,
float iRatio1 = 1,
float iSoftness_dB = 0,
float iColor_dB = 0,
float iHpfCutoffHz = 1,
float iMakeup_dB = 0,
float iMixPercent = 100)
{
input stream SampleType in, scIn;
output stream SampleType out, guiOut;
input
{
event float attackIn [[ name: "Attack", min: 0.1f, max: 50, init: iAttackMs, unit: "ms", step: 0.1, group: "Main"]];
event float releaseIn [[ name: "Release", min: 30, max: 3000, init: iReleaseMs, unit: "ms", step: 1, group: "Main" ]];
event float thresholdIn [[ name: "Threshold", min: -50.f, max: 0.f, init: iThreshold_dB, unit: "dB", step: 0.1f, group: "Main" ]];
event float ratioIn [[ name: "Post-Threshold", min: 0.5f, max: 20.f, init: iRatio, step: 0.1f, group: "Ratios" ]];
event float ratio1In [[ name: "Pre-Threshold", min: 0.5f, max: 1.5f, init: iRatio1, step: 0.1f, group: "Ratios" ]];
event float sidechainIn [[ name: "Sidechain", init: float (iSidechainBool), boolean, group: "Detector" /*UNSMOOTHED*/ ]];
event float cutoffHP_In [[ name: "High Pass", min: 1, max: 500, init: iHpfCutoffHz, unit: "Hz", step: 1, group: "Detector"]];
event float stereoLinkIn [[ name: "Stereo Link", min: 0, max: 100, init: iStereoLinkPercent, unit: "%", step: 1, group: "Detector" ]];
event float softnessIn [[ name: "Softness", min: 0, max: 24, init: iSoftness_dB, unit: "dB", step: 0.1f, group: "Knee" ]];
event float colorIn [[ name: "Color", min: -24, max: 24, init: iColor_dB, unit: "dB", step: 0.1f, group: "Knee" ]];
smoothedVolume.volumeIn makeupIn [[ name: "Makeup", min: -6, max: 50, init: iMakeup_dB, step: 0.1f, unit: "dB", group: "Utility" ]];
smoothedMixPan.mixIn [[ name: "Mix", min: 0, max: 100, init: iMixPercent, unit: "%", step: 1, group: "Utility" ]];
}
let
{
internalDS0 = Internal::Processor (iSidechainBool, iAttackMs, iReleaseMs, iStereoLinkPercent, iThreshold_dB, iRatio, iRatio1, iSoftness_dB, iColor_dB, iHpfCutoffHz);
internalDS2 = Internal::Processor (iSidechainBool, iAttackMs, iReleaseMs, iStereoLinkPercent, iThreshold_dB, iRatio, iRatio1, iSoftness_dB, iColor_dB, iHpfCutoffHz) / 2;
internalDS4 = Internal::Processor (iSidechainBool, iAttackMs, iReleaseMs, iStereoLinkPercent, iThreshold_dB, iRatio, iRatio1, iSoftness_dB, iColor_dB, iHpfCutoffHz) / 4;
mux3To1Fs = Mux3To1Fs::Processor;
mux3To1Fs1 = Mux3To1Fs::Processor;
smoothedVolume = SmoothedVolume::Processor (iMakeup_dB);
smoothedMixPan = SmoothedMixPan::Processor (iMixPercent, 0);
}
connection
{
//input event float
attackIn -> internalDS0.attackIn, internalDS2.attackIn, internalDS4.attackIn;
releaseIn -> internalDS0.releaseIn, internalDS2.releaseIn, internalDS4.releaseIn;
thresholdIn -> internalDS0.thresholdIn, internalDS2.thresholdIn, internalDS4.thresholdIn;
ratioIn -> internalDS0.ratioIn, internalDS2.ratioIn, internalDS4.ratioIn;
ratio1In -> internalDS0.ratio1In, internalDS2.ratio1In, internalDS4.ratio1In;
sidechainIn -> internalDS0.sidechainIn, internalDS2.sidechainIn, internalDS4.sidechainIn;
cutoffHP_In -> internalDS0.cutoffHP_In, internalDS2.cutoffHP_In, internalDS4.cutoffHP_In;
stereoLinkIn -> internalDS0.stereoLinkIn, internalDS2.stereoLinkIn, internalDS4.stereoLinkIn;
softnessIn -> internalDS0.softnessIn, internalDS2.softnessIn, internalDS4.softnessIn;
colorIn -> internalDS0.colorIn, internalDS2.colorIn, internalDS4.colorIn;
//apply 3 downsampling rates
[sinc] in -> internalDS0.in, internalDS2.in, internalDS4.in;
[sinc] scIn -> internalDS0.scIn, internalDS2.scIn, internalDS4.scIn;
[sinc] internalDS0.out -> mux3To1Fs.in;
[sinc] internalDS2.out -> mux3To1Fs.in1;
[sinc] internalDS4.out -> mux3To1Fs.in2;
[sinc] internalDS0.guiOut -> mux3To1Fs1.in;
[sinc] internalDS2.guiOut -> mux3To1Fs1.in1;
[sinc] internalDS4.guiOut -> mux3To1Fs1.in2;
mux3To1Fs1.out -> guiOut;
//utility
in -> smoothedMixPan.dryIn;
mux3To1Fs.out -> smoothedVolume.in;
smoothedVolume.out -> smoothedMixPan.wetIn;
smoothedMixPan.out -> out;
}
}
namespace Internal
{
graph Processor(bool iSidechainBool,
float iAttackMs,
float iReleaseMs,
float iStereoLinkPercent,
float iThreshold_dB,
float iRatio,
float iRatio1,
float iSoftness_dB,
float iColor_dB,
float iHpfCutoffHz)
{
input stream SampleType in, scIn;
output stream SampleType out, guiOut;
input
{
mux2To1.idxIn sidechainIn;
detector.cutoffHP_In;
detector.stereoLinkIn;
ballisticsFilter.attackIn;
ballisticsFilter.releaseIn;
ctfColor.thresholdIn;
ctfColor.ratioIn;
ctfColor.ratio1In;
ctfColor.softnessIn;
ctfColor.colorIn;
}
let
{
dcBlocker = DC_Blocker::Processor;
mux2To1 = Mux2To1::Processor (iSidechainBool);
detector = Detector::Processor (iHpfCutoffHz, iStereoLinkPercent);
ballisticsFilter = BallisticsFilter::Processor (iAttackMs, iReleaseMs);
ctfColor = CTF_Color::Processor (iThreshold_dB, iRatio, iRatio1, iSoftness_dB, iColor_dB);
applyGain = ApplyGain::Processor;
}
connection
{
in -> dcBlocker -> applyGain.in;
in -> mux2To1.in;
scIn -> mux2To1.in1;
mux2To1.out -> detector.in;
detector.out -> ballisticsFilter.in;
ballisticsFilter.out -> ctfColor.in;
ctfColor.out -> applyGain.b, guiOut;
applyGain.out -> out;
}
}
}
}
/** Modulated 'DelayLine' with 'LadderLpfS' attached to its output
Notes:
- Use case: chorus, slow flange, doubler, stereo widener
- Loosely based on Boss CE-3 Chorus Pedal
- Tail: 0.5 s
*/
namespace TheChorus
{
graph Processor(float iDepthPercent = 0,
float iRateHz = 0,
float iWidthDeg = 0,
float iDelayMs = 0,
int iMode = Lfo::Modes::Triangle,
float iCutoffHz = 3000,
float iMakeup_dB = 0,
float iMixPercent = 100,
float iPan = 0)
{
input stream SampleType in;
output stream SampleType out;
input
{
event float depthIn [[ name: "Depth", min: 0, max: 100, init: iDepthPercent, unit: "%", step: 1, group: "Main" ]];
event float rateIn [[ name: "Rate", min: 0.1, max: 4.0, init: iRateHz, unit: "Hz", step: 0.1, group: "Main" ]];
event float widthIn [[ name: "Width", min: -180, max: 180, init: iWidthDeg, unit: "deg", step: 1, group: "Main" /*UNSMOOTHED*/ ]];
event float delayIn [[ name: "Min Delay", min: 0, max: 35, init: iDelayMs, unit: "ms", step: 1, group: "LFO" /*UNSMOOTHED*/ ]];
event float modeIn [[ name: "Waveform", init: iMode, boolean, text: "Tri|Sine", group: "LFO" /*UNSMOOTHED*/ ]];
event float cutoffIn [[ name: "Cutoff", min: 3000, max: 18000, init: iCutoffHz, unit: "Hz", step: 1, group: "BBD Ladder" ]];
smoothedVolume.volumeIn makeupIn [[ name: "Makeup", min: -12, max: 12, init: iMakeup_dB, step: 0.1f, unit: "dB", group: "Utility" ]];
smoothedMixPan.mixIn [[ name: "Mix", min: 0, max: 100, init: iMixPercent, unit: "%", step: 1, group: "Utility" ]];
smoothedMixPan.panIn [[ name: "Pan", min: -1, max: 1, init: iPan, step: 0.01f, group: "Utility" ]];
}
let
{
internalDS0 = Internal::Processor (iDepthPercent, iRateHz, iWidthDeg, iMode, iDelayMs, iCutoffHz);
internalDS2 = Internal::Processor (iDepthPercent, iRateHz, iWidthDeg, iMode, iDelayMs, iCutoffHz) / 2;
internalDS4 = Internal::Processor (iDepthPercent, iRateHz, iWidthDeg, iMode, iDelayMs, iCutoffHz) / 4;
mux3To1Fs = Mux3To1Fs::Processor;
smoothedVolume = SmoothedVolume::Processor (iMakeup_dB);
smoothedMixPan = SmoothedMixPan::Processor (iMixPercent, iPan);
}
connection
{
//shared input events
depthIn -> internalDS0.depthIn, internalDS2.depthIn, internalDS4.depthIn;
rateIn -> internalDS0.rateIn, internalDS2.rateIn, internalDS4.rateIn;
widthIn -> internalDS0.widthIn, internalDS2.widthIn, internalDS4.widthIn;
delayIn -> internalDS0.delayIn, internalDS2.delayIn, internalDS4.delayIn;
modeIn -> internalDS0.modeIn, internalDS2.modeIn, internalDS4.modeIn;
cutoffIn -> internalDS0.cutoffIn, internalDS2.cutoffIn, internalDS4.cutoffIn;
//dynamically downsample to 44.1/48 kHz
[sinc] in -> internalDS0.in, internalDS2.in, internalDS4.in;
[sinc] internalDS0.out -> mux3To1Fs.in;
[sinc] internalDS2.out -> mux3To1Fs.in1;
[sinc] internalDS4.out -> mux3To1Fs.in2;
//utility
in -> smoothedMixPan.dryIn;
mux3To1Fs.out -> smoothedVolume.in;
smoothedVolume.out -> smoothedMixPan.wetIn;
smoothedMixPan.out -> out;
}
}
namespace Internal
{
graph Processor (float iDepthPercent,
float iRateHz,
float iWidthDeg,
int iMode,
float iDelayMs,
float iCutoffHz)
{
input stream SampleType in;
output stream SampleType out;
input
{
lfo.depthIn;
lfo.rateIn;
lfo.widthIn;
lfo.modeIn;
delayLine.delayIn;
ladderLpfS.cutoffIn;
}
let
{
dcBlocker = DC_Blocker::Processor;
lfo = Lfo::Processor (iDepthPercent, iRateHz, iWidthDeg, iMode);
delayLine = DelayLine::Processor (iDelayMs, 35, 4);
ladderLpfS = LadderLpfS::Processor (iCutoffHz, 1, 0.5f);
}
connection
{
lfo.out -> delayLine.lfoIn;
in -> dcBlocker -> delayLine.in;
delayLine.out -> ladderLpfS.in;
ladderLpfS.out -> out;
}
}
}
}
/** 'OnepoleC' in all pass mode modulated by 'LanADAA'
Use case: boost and sustain low frequencies
*/
namespace TheBass
{
graph Processor (float iNonlinearity = 250, float iStereoLinkPercent = 100)
{
input stream SampleType in;
output stream SampleType out;
input
{
event float nonlinearityIn [[ name: "Nonlin", min: 0, max: 350, init: iNonlinearity, step: 1 /*UNSMOOTHED*/]];
stereoLink.stereoLinkIn;
autoSmoothedVolume.parameterIn volumeIn;
//smoothedMixPan.mixIn;
//smoothedMixPan.panIn;
}
let
{
stereoLink = StereoLink::Processor (iStereoLinkPercent);
internal = Internal::Processor (iNonlinearity) * 2;
onepoleMixer = OnepoleMixer::Processor (OnepoleMixer::ModeIdx::AP, 0);
//boilerplate Processors
dcBlockerIn = filt::dc_blocker::Processor (0.1);
autoSmoothedVolume = AutoSmoothedVolume::Processor (AutoParameter::Modes::Volume_OnepoleC_Lan);
// smoothedMixPan = SmoothedMixPan::Processor (iMixPercent, iPan);
}
connection
{
nonlinearityIn -> internal.nonlinearityIn;
nonlinearityIn -> autoSmoothedVolume.controlIn;
in -> dcBlockerIn -> stereoLink.in, internal.in;
stereoLink.out -> internal.Lin;
internal.highpassOut -> onepoleMixer.highpassIn;
internal.lowpassOut -> onepoleMixer.lowpassIn;
onepoleMixer.out -> autoSmoothedVolume.in;
autoSmoothedVolume.out -> out;
}
}
namespace Internal
{
graph Processor (float iNonlinearity)
{
input stream SampleType in, Lin;
output stream SampleType highpassOut, lowpassOut;
input
{
L.nonlinearityIn;
}
let
{
L = LanADAA::Processor (iNonlinearity);
onepoleC = OnepoleC::Processor;
}
connection
{
in -> onepoleC.in;
Lin -> L.in;
L.Omega -> onepoleC.Omega;
onepoleC.highpassOut -> highpassOut;
onepoleC.lowpassOut -> lowpassOut;
}
}
}
}
/** A dummy processor that doesn't modify streams
Use case: debugging
*/
namespace TheDummy
{
graph Processor()
{
input stream SampleType in;
output stream SampleType out;
connection
{
in -> out;
}
}
}
} //namespace HighLevel
/*==============================================================================
Filter Processors 04/09/22
==============================================================================*/
/** Ladder Low Pass Filter with variable order and saturating state
Notes:
- currently hard-coded to 4th order lpf
- Resonance up to 2 reccomended
- Even though its nonlinear, the filter can become unstable if using an unbounded nonlinearity
i.e., the filter can self-oscillate with nonlinear functions like 'tanh'
*/
namespace LadderLpfS
{
graph Processor (float iCutoff, float iResonance, float iNonlinearity)
{
input stream SampleType in;
output stream SampleType out;
input
{
smoothedParameter0.in cutoffIn [[ name: "Cutoff", min: 3000, max: 18000, init: iCutoff, unit: "Hz", step: 1 ]];
smoothedParameter1.in resonanceIn [[ name: "Resonance", min: 0, max: 2, init: iResonance, step: 0.01f ]];
internal.nonlinearityIn;
}
let
{
smoothedParameter0 = UnsmoothedParameter::Processor (UnsmoothedParameter::ParameterType (iCutoff), UnsmoothedParameter::ModeIdx::CutoffToOmega);
smoothedParameter1 = SmoothedParameter::Processor (SmoothedParameter::ParameterType (iResonance), SmoothedParameter::ModeIdx::GainToGain);
internal = Internal::Processor (iNonlinearity) * 2;
}
connection
{
smoothedParameter0.out -> internal.OmegaIn;
smoothedParameter1.out -> internal.kIn;
in -> internal.in;
internal.out -> out;
}
}
namespace Internal
{
struct Coeffs
{
SampleType g; //G for onepole stages
SampleType k; //resonance
SampleType N; //nonlinearity
}
void updatePerSample (Coeffs& c, SampleType Omega, SampleType k, float64 fs)
{
c.g = vOmegaToG_Onepole (Omega, fs);
c.k = k;
}
namespace M (int order)
{
static_assert (order % 2 == 0, "LadderFilter::M [[Filter Processors]]");
void update (Coeffs& c, float nonlinearity, float64 fs)
{
c.N = float (88200 / fs) * nonlinearity * (1.f + float (c.k[0])); //nonlinearity scaled according to fs and other params
}
struct State
{
SampleType[order] s;
}
SampleType process (State& s, SampleType x, const Coeffs& c)
{
let xNorm = x * (ONE + c.k); //normalize magnitude at 0 Hz to 0 dB
var S = ZERO;
var G = ONE;
for (int i = order - 1; i > -1; --i)
{
S += G * s.s.at(i);
G *= c.g;
}
//input to first lowpass ('u')
var y = (xNorm - c.k * S) / (ONE + c.k * G);
//'order' lowpasses in series
for (int i = 0; i < order; ++i)
{
let v = (y - s.s.at(i)) * c.g;
y = vBBD(v + s.s.at(i), c.N); //saturation
s.s.at(i) = v + y;
}
return y;
}
}
processor Processor (float iNonlinearity, int order = 4)
{
input stream SampleType in;
output stream SampleType out;
input stream SampleType OmegaIn, kIn;
input event float nonlinearityIn [[ name: "Nonlin", min: 0, max: 1, init: iNonlinearity, step: 0.01]];
event nonlinearityIn (float v) { nonlinearity = v; recalc = true; }
float nonlinearity = iNonlinearity;
bool recalc = true;
static_assert (order == 4, "LadderLpfS::Processor [[Filter Processors]] Other filter orders not yet implemented.");