-
Notifications
You must be signed in to change notification settings - Fork 164
Expand file tree
/
Copy pathfaustLimiter.h
More file actions
938 lines (767 loc) · 31 KB
/
faustLimiter.h
File metadata and controls
938 lines (767 loc) · 31 KB
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
/* ------------------------------------------------------------
name: "limiter"
Code generated with Faust 2.28.3 (https://faust.grame.fr)
Compilation options: -lang cpp -inpl -scal -ftz 0
------------------------------------------------------------ */
#ifndef __faustLimiter_H__
#define __faustLimiter_H__
// Music 256a / CS 476a | fall 2016
// CCRMA, Stanford University
//
// Author: Romain Michon (rmichonATccrmaDOTstanfordDOTedu)
// Description: Simple Faust architecture file to easily integrate a Faust DSP module
// in a JUCE project
// needed by any Faust arch file
/************************** BEGIN misc.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef __misc__
#define __misc__
#include <algorithm>
#include <map>
#include <cstdlib>
#include <string.h>
#include <fstream>
#include <string>
/************************** BEGIN meta.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef __meta__
#define __meta__
struct Meta
{
virtual ~Meta() {};
virtual void declare(const char* key, const char* value) = 0;
};
#endif
/************************** END meta.h **************************/
using std::max;
using std::min;
struct XXXX_Meta : std::map<const char*, const char*>
{
void declare(const char* key, const char* value) { (*this)[key] = value; }
};
struct MY_Meta : Meta, std::map<const char*, const char*>
{
void declare(const char* key, const char* value) { (*this)[key] = value; }
};
static int lsr(int x, int n) { return int(((unsigned int)x) >> n); }
static int int2pow2(int x) { int r = 0; while ((1<<r) < x) r++; return r; }
static long lopt(char* argv[], const char* name, long def)
{
for (int i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return std::atoi(argv[i+1]);
return def;
}
static long lopt1(int argc, char* argv[], const char* longname, const char* shortname, long def)
{
for (int i = 2; i < argc; i++) {
if (strcmp(argv[i-1], shortname) == 0 || strcmp(argv[i-1], longname) == 0) {
return atoi(argv[i]);
}
}
return def;
}
static const char* lopts(char* argv[], const char* name, const char* def)
{
for (int i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return argv[i+1];
return def;
}
static const char* lopts1(int argc, char* argv[], const char* longname, const char* shortname, const char* def)
{
for (int i = 2; i < argc; i++) {
if (strcmp(argv[i-1], shortname) == 0 || strcmp(argv[i-1], longname) == 0) {
return argv[i];
}
}
return def;
}
static bool isopt(char* argv[], const char* name)
{
for (int i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return true;
return false;
}
static std::string pathToContent(const std::string& path)
{
std::ifstream file(path.c_str(), std::ifstream::binary);
file.seekg(0, file.end);
int size = int(file.tellg());
file.seekg(0, file.beg);
// And allocate buffer to that a single line can be read...
char* buffer = new char[size + 1];
file.read(buffer, size);
// Terminate the string
buffer[size] = 0;
std::string result = buffer;
file.close();
delete [] buffer;
return result;
}
#endif
/************************** END misc.h **************************/
// allows to control a Faust DSP module in a simple manner by using parameter's path
/************************** BEGIN MapUI.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef FAUST_MAPUI_H
#define FAUST_MAPUI_H
#include <vector>
#include <map>
#include <string>
/************************** BEGIN UI.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2020 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef __UI_H__
#define __UI_H__
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
/*******************************************************************************
* UI : Faust DSP User Interface
* User Interface as expected by the buildUserInterface() method of a DSP.
* This abstract class contains only the method that the Faust compiler can
* generate to describe a DSP user interface.
******************************************************************************/
struct Soundfile;
template <typename REAL>
struct UIReal
{
UIReal() {}
virtual ~UIReal() {}
// -- widget's layouts
virtual void openTabBox(const char* label) = 0;
virtual void openHorizontalBox(const char* label) = 0;
virtual void openVerticalBox(const char* label) = 0;
virtual void closeBox() = 0;
// -- active widgets
virtual void addButton(const char* label, REAL* zone) = 0;
virtual void addCheckButton(const char* label, REAL* zone) = 0;
virtual void addVerticalSlider(const char* label, REAL* zone, REAL init, REAL min, REAL max, REAL step) = 0;
virtual void addHorizontalSlider(const char* label, REAL* zone, REAL init, REAL min, REAL max, REAL step) = 0;
virtual void addNumEntry(const char* label, REAL* zone, REAL init, REAL min, REAL max, REAL step) = 0;
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, REAL* zone, REAL min, REAL max) = 0;
virtual void addVerticalBargraph(const char* label, REAL* zone, REAL min, REAL max) = 0;
// -- soundfiles
virtual void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) = 0;
// -- metadata declarations
virtual void declare(REAL* zone, const char* key, const char* val) {}
};
struct UI : public UIReal<FAUSTFLOAT>
{
UI() {}
virtual ~UI() {}
};
#endif
/************************** END UI.h **************************/
/************************** BEGIN PathBuilder.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef FAUST_PATHBUILDER_H
#define FAUST_PATHBUILDER_H
#include <vector>
#include <string>
#include <algorithm>
/*******************************************************************************
* PathBuilder : Faust User Interface
* Helper class to build complete hierarchical path for UI items.
******************************************************************************/
class PathBuilder
{
protected:
std::vector<std::string> fControlsLevel;
public:
PathBuilder() {}
virtual ~PathBuilder() {}
std::string buildPath(const std::string& label)
{
std::string res = "/";
for (size_t i = 0; i < fControlsLevel.size(); i++) {
res += fControlsLevel[i];
res += "/";
}
res += label;
std::replace(res.begin(), res.end(), ' ', '_');
return res;
}
std::string buildLabel(std::string label)
{
std::replace(label.begin(), label.end(), ' ', '_');
return label;
}
void pushLabel(const std::string& label) { fControlsLevel.push_back(label); }
void popLabel() { fControlsLevel.pop_back(); }
};
#endif // FAUST_PATHBUILDER_H
/************************** END PathBuilder.h **************************/
/*******************************************************************************
* MapUI : Faust User Interface
* This class creates a map of complete hierarchical path and zones for each UI items.
******************************************************************************/
class MapUI : public UI, public PathBuilder
{
protected:
// Complete path map
std::map<std::string, FAUSTFLOAT*> fPathZoneMap;
// Label zone map
std::map<std::string, FAUSTFLOAT*> fLabelZoneMap;
public:
MapUI() {}
virtual ~MapUI() {}
// -- widget's layouts
void openTabBox(const char* label)
{
pushLabel(label);
}
void openHorizontalBox(const char* label)
{
pushLabel(label);
}
void openVerticalBox(const char* label)
{
pushLabel(label);
}
void closeBox()
{
popLabel();
}
// -- active widgets
void addButton(const char* label, FAUSTFLOAT* zone)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
void addCheckButton(const char* label, FAUSTFLOAT* zone)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT fmin, FAUSTFLOAT fmax, FAUSTFLOAT step)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT fmin, FAUSTFLOAT fmax, FAUSTFLOAT step)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT fmin, FAUSTFLOAT fmax, FAUSTFLOAT step)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
// -- passive widgets
void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT fmin, FAUSTFLOAT fmax)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT fmin, FAUSTFLOAT fmax)
{
fPathZoneMap[buildPath(label)] = zone;
fLabelZoneMap[label] = zone;
}
// -- soundfiles
virtual void addSoundfile(const char* label, const char* filename, Soundfile** sf_zone) {}
// -- metadata declarations
virtual void declare(FAUSTFLOAT* zone, const char* key, const char* val)
{}
// set/get
void setParamValue(const std::string& path, FAUSTFLOAT value)
{
if (fPathZoneMap.find(path) != fPathZoneMap.end()) {
*fPathZoneMap[path] = value;
} else if (fLabelZoneMap.find(path) != fLabelZoneMap.end()) {
*fLabelZoneMap[path] = value;
}
}
FAUSTFLOAT getParamValue(const std::string& path)
{
if (fPathZoneMap.find(path) != fPathZoneMap.end()) {
return *fPathZoneMap[path];
} else if (fLabelZoneMap.find(path) != fLabelZoneMap.end()) {
return *fLabelZoneMap[path];
} else {
return FAUSTFLOAT(0);
}
}
// map access
std::map<std::string, FAUSTFLOAT*>& getMap() { return fPathZoneMap; }
int getParamsCount() { return int(fPathZoneMap.size()); }
std::string getParamAddress(int index)
{
if (index < 0 || index > int(fPathZoneMap.size())) {
return "";
} else {
auto it = fPathZoneMap.begin();
while (index-- > 0 && it++ != fPathZoneMap.end()) {}
return it->first;
}
}
std::string getParamAddress(FAUSTFLOAT* zone)
{
for (auto& it : fPathZoneMap) {
if (it.second == zone) return it.first;
}
return "";
}
FAUSTFLOAT* getParamZone(const std::string& str)
{
if (fPathZoneMap.find(str) != fPathZoneMap.end()) {
return fPathZoneMap[str];
}
if (fLabelZoneMap.find(str) != fLabelZoneMap.end()) {
return fLabelZoneMap[str];
}
return nullptr;
}
FAUSTFLOAT* getParamZone(int index)
{
if (index < 0 || index > int(fPathZoneMap.size())) {
return nullptr;
} else {
auto it = fPathZoneMap.begin();
while (index-- > 0 && it++ != fPathZoneMap.end()) {}
return it->second;
}
}
static bool endsWith(const std::string& str, const std::string& end)
{
size_t l1 = str.length();
size_t l2 = end.length();
return (l1 >= l2) && (0 == str.compare(l1 - l2, l2, end));
}
};
#endif // FAUST_MAPUI_H
/************************** END MapUI.h **************************/
// needed by any Faust arch file
/************************** BEGIN faustdsp.h **************************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2017 GRAME, Centre National de Creation Musicale
---------------------------------------------------------------------
This Architecture section is free software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 3 of
the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; If not, see <http://www.gnu.org/licenses/>.
EXCEPTION : As a special exception, you may create a larger work
that contains this FAUST architecture section and distribute
that work under terms of your choice, so long as this FAUST
architecture section is not modified.
************************************************************************/
#ifndef __dsp__
#define __dsp__
#include <string>
#include <vector>
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
struct UI;
struct Meta;
/**
* DSP memory manager.
*/
struct dsp_memory_manager {
virtual ~dsp_memory_manager() {}
virtual void* allocate(size_t size) = 0;
virtual void destroy(void* ptr) = 0;
};
/**
* Signal processor definition.
*/
class faustdsp {
public:
faustdsp() {}
virtual ~faustdsp() {}
/* Return instance number of audio inputs */
virtual int getNumInputs() = 0;
/* Return instance number of audio outputs */
virtual int getNumOutputs() = 0;
/**
* Trigger the ui_interface parameter with instance specific calls
* to 'openTabBox', 'addButton', 'addVerticalSlider'... in order to build the UI.
*
* @param ui_interface - the user interface builder
*/
virtual void buildUserInterface(UI* ui_interface) = 0;
/* Returns the sample rate currently used by the instance */
virtual int getSampleRate() = 0;
/**
* Global init, calls the following methods:
* - static class 'classInit': static tables initialization
* - 'instanceInit': constants and instance state initialization
*
* @param sample_rate - the sampling rate in Hertz
*/
virtual void init(int sample_rate) = 0;
/**
* Init instance state
*
* @param sample_rate - the sampling rate in Hertz
*/
virtual void instanceInit(int sample_rate) = 0;
/**
* Init instance constant state
*
* @param sample_rate - the sampling rate in Hertz
*/
virtual void instanceConstants(int sample_rate) = 0;
/* Init default control parameters values */
virtual void instanceResetUserInterface() = 0;
/* Init instance state (delay lines...) */
virtual void instanceClear() = 0;
/**
* Return a clone of the instance.
*
* @return a copy of the instance on success, otherwise a null pointer.
*/
virtual faustdsp* clone() = 0;
/**
* Trigger the Meta* parameter with instance specific calls to 'declare' (key, value) metadata.
*
* @param m - the Meta* meta user
*/
virtual void metadata(Meta* m) = 0;
/**
* DSP instance computation, to be called with successive in/out audio buffers.
*
* @param count - the number of frames to compute
* @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
* @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, double or quad)
*
*/
virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) = 0;
/**
* DSP instance computation: alternative method to be used by subclasses.
*
* @param date_usec - the timestamp in microsec given by audio driver.
* @param count - the number of frames to compute
* @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (either float, double or quad)
* @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (either float, double or quad)
*
*/
virtual void compute(double /*date_usec*/, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { compute(count, inputs, outputs); }
};
/**
* Generic DSP decorator.
*/
class decorator_dsp : public faustdsp {
protected:
faustdsp* fDSP;
public:
decorator_dsp(faustdsp* faustdsp = nullptr):fDSP(faustdsp) {}
virtual ~decorator_dsp() { delete fDSP; }
virtual int getNumInputs() { return fDSP->getNumInputs(); }
virtual int getNumOutputs() { return fDSP->getNumOutputs(); }
virtual void buildUserInterface(UI* ui_interface) { fDSP->buildUserInterface(ui_interface); }
virtual int getSampleRate() { return fDSP->getSampleRate(); }
virtual void init(int sample_rate) { fDSP->init(sample_rate); }
virtual void instanceInit(int sample_rate) { fDSP->instanceInit(sample_rate); }
virtual void instanceConstants(int sample_rate) { fDSP->instanceConstants(sample_rate); }
virtual void instanceResetUserInterface() { fDSP->instanceResetUserInterface(); }
virtual void instanceClear() { fDSP->instanceClear(); }
virtual decorator_dsp* clone() { return new decorator_dsp(fDSP->clone()); }
virtual void metadata(Meta* m) { fDSP->metadata(m); }
// Beware: subclasses usually have to overload the two 'compute' methods
virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { fDSP->compute(count, inputs, outputs); }
virtual void compute(double date_usec, int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) { fDSP->compute(date_usec, count, inputs, outputs); }
};
/**
* DSP factory class.
*/
class dsp_factory {
protected:
// So that to force sub-classes to use deleteDSPFactory(dsp_factory* factory);
virtual ~dsp_factory() {}
public:
virtual std::string getName() = 0;
virtual std::string getSHAKey() = 0;
virtual std::string getDSPCode() = 0;
virtual std::string getCompileOptions() = 0;
virtual std::vector<std::string> getLibraryList() = 0;
virtual std::vector<std::string> getIncludePathnames() = 0;
virtual faustdsp* createDSPInstance() = 0;
virtual void setMemoryManager(dsp_memory_manager* manager) = 0;
virtual dsp_memory_manager* getMemoryManager() = 0;
};
/**
* On Intel set FZ (Flush to Zero) and DAZ (Denormals Are Zero)
* flags to avoid costly denormals.
*/
#ifdef __SSE__
#include <xmmintrin.h>
#ifdef __SSE2__
#define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8040)
#else
#define AVOIDDENORMALS _mm_setcsr(_mm_getcsr() | 0x8000)
#endif
#else
#define AVOIDDENORMALS
#endif
#endif
/************************** END faustdsp.h **************************/
// tags used by the Faust compiler to paste the generated c++ code
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
#include <algorithm>
#include <cmath>
#include <math.h>
#ifndef FAUSTCLASS
#define FAUSTCLASS faustLimiter
#endif
#ifdef __APPLE__
#define exp10f __exp10f
#define exp10 __exp10
#endif
class faustLimiter : public faustdsp {
private:
int fSampleRate;
float fConst0;
FAUSTFLOAT fHslider0;
FAUSTFLOAT fEntry0;
FAUSTFLOAT fHslider1;
float fRec2[2];
float fRec1[2];
FAUSTFLOAT fEntry1;
float fRec0[2];
public:
void metadata(Meta* m) {
m->declare("analyzers.lib/name", "Faust Analyzer Library");
m->declare("analyzers.lib/version", "0.1");
m->declare("basics.lib/name", "Faust Basic Element Library");
m->declare("basics.lib/version", "0.1");
m->declare("compressors.lib/compression_gain_mono:author", "Julius O. Smith III");
m->declare("compressors.lib/compression_gain_mono:copyright", "Copyright (C) 2014-2020 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("compressors.lib/compression_gain_mono:license", "MIT-style STK-4.3 license");
m->declare("compressors.lib/compressor_stereo:author", "Julius O. Smith III");
m->declare("compressors.lib/compressor_stereo:copyright", "Copyright (C) 2014-2020 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("compressors.lib/compressor_stereo:license", "MIT-style STK-4.3 license");
m->declare("compressors.lib/name", "Faust Compressor Effect Library");
m->declare("compressors.lib/version", "0.0");
m->declare("filename", "limiter.dsp");
m->declare("maths.lib/author", "GRAME");
m->declare("maths.lib/copyright", "GRAME");
m->declare("maths.lib/license", "LGPL with exception");
m->declare("maths.lib/name", "Faust Math Library");
m->declare("maths.lib/version", "2.3");
m->declare("name", "limiter");
m->declare("platform.lib/name", "Generic Platform Library");
m->declare("platform.lib/version", "0.1");
m->declare("signals.lib/name", "Faust Signal Routing Library");
m->declare("signals.lib/version", "0.0");
}
virtual int getNumInputs() {
return 2;
}
virtual int getNumOutputs() {
return 2;
}
virtual int getInputRate(int channel) {
int rate;
switch ((channel)) {
case 0: {
rate = 1;
break;
}
case 1: {
rate = 1;
break;
}
default: {
rate = -1;
break;
}
}
return rate;
}
virtual int getOutputRate(int channel) {
int rate;
switch ((channel)) {
case 0: {
rate = 1;
break;
}
case 1: {
rate = 1;
break;
}
default: {
rate = -1;
break;
}
}
return rate;
}
static void classInit(int sample_rate) {
}
virtual void instanceConstants(int sample_rate) {
fSampleRate = sample_rate;
fConst0 = (1.0f / std::min<float>(192000.0f, std::max<float>(1.0f, float(fSampleRate))));
}
virtual void instanceResetUserInterface() {
fHslider0 = FAUSTFLOAT(1.0000000000000001e-05f);
fEntry0 = FAUSTFLOAT(12.0f);
fHslider1 = FAUSTFLOAT(0.25f);
fEntry1 = FAUSTFLOAT(-3.0f);
}
virtual void instanceClear() {
for (int l0 = 0; (l0 < 2); l0 = (l0 + 1)) {
fRec2[l0] = 0.0f;
}
for (int l1 = 0; (l1 < 2); l1 = (l1 + 1)) {
fRec1[l1] = 0.0f;
}
for (int l2 = 0; (l2 < 2); l2 = (l2 + 1)) {
fRec0[l2] = 0.0f;
}
}
virtual void init(int sample_rate) {
classInit(sample_rate);
instanceInit(sample_rate);
}
virtual void instanceInit(int sample_rate) {
instanceConstants(sample_rate);
instanceResetUserInterface();
instanceClear();
}
virtual faustLimiter* clone() {
return new faustLimiter();
}
virtual int getSampleRate() {
return fSampleRate;
}
virtual void buildUserInterface(UI* ui_interface) {
ui_interface->openVerticalBox("limiter");
ui_interface->addHorizontalSlider("attack", &fHslider0, 9.99999975e-06f, 0.0f, 1.0f, 0.00100000005f);
ui_interface->addNumEntry("ratio", &fEntry0, 12.0f, 1.0f, 20.0f, 0.100000001f);
ui_interface->addHorizontalSlider("release", &fHslider1, 0.25f, 0.0f, 2.0f, 0.00999999978f);
ui_interface->addNumEntry("threshold", &fEntry1, -3.0f, -24.0f, 0.0f, 0.00999999978f);
ui_interface->closeBox();
}
virtual void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {
FAUSTFLOAT* input0 = inputs[0];
FAUSTFLOAT* input1 = inputs[1];
FAUSTFLOAT* output0 = outputs[0];
FAUSTFLOAT* output1 = outputs[1];
float fSlow0 = std::max<float>(fConst0, float(fHslider0));
float fSlow1 = (0.5f * fSlow0);
int iSlow2 = (std::fabs(fSlow1) < 1.1920929e-07f);
float fSlow3 = (iSlow2 ? 0.0f : std::exp((0.0f - (fConst0 / (iSlow2 ? 1.0f : fSlow1)))));
float fSlow4 = ((1.0f / std::max<float>(1.00000001e-07f, float(fEntry0))) + -1.0f);
int iSlow5 = (std::fabs(fSlow0) < 1.1920929e-07f);
float fSlow6 = (iSlow5 ? 0.0f : std::exp((0.0f - (fConst0 / (iSlow5 ? 1.0f : fSlow0)))));
float fSlow7 = std::max<float>(fConst0, float(fHslider1));
int iSlow8 = (std::fabs(fSlow7) < 1.1920929e-07f);
float fSlow9 = (iSlow8 ? 0.0f : std::exp((0.0f - (fConst0 / (iSlow8 ? 1.0f : fSlow7)))));
float fSlow10 = float(fEntry1);
float fSlow11 = (1.0f - fSlow3);
for (int i = 0; (i < count); i = (i + 1)) {
float fTemp0 = float(input0[i]);
float fTemp1 = float(input1[i]);
float fTemp2 = std::fabs((std::fabs(fTemp0) + std::fabs(fTemp1)));
float fTemp3 = ((fRec1[1] > fTemp2) ? fSlow9 : fSlow6);
fRec2[0] = ((fRec2[1] * fTemp3) + (fTemp2 * (1.0f - fTemp3)));
fRec1[0] = fRec2[0];
fRec0[0] = ((fRec0[1] * fSlow3) + (fSlow4 * (std::max<float>(((20.0f * std::log10(fRec1[0])) - fSlow10), 0.0f) * fSlow11)));
float fTemp4 = std::pow(10.0f, (0.0500000007f * fRec0[0]));
output0[i] = FAUSTFLOAT((fTemp0 * fTemp4));
output1[i] = FAUSTFLOAT((fTemp1 * fTemp4));
fRec2[1] = fRec2[0];
fRec1[1] = fRec1[0];
fRec0[1] = fRec0[0];
}
}
};
#endif