forked from supercollider/sc3-plugins
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathHOABeamDirac2Hoa2.cpp
More file actions
1167 lines (985 loc) · 42.3 KB
/
HOABeamDirac2Hoa2.cpp
File metadata and controls
1167 lines (985 loc) · 42.3 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
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
//----------------------------------------------------------
// name: "HOABeamDirac2Hoa2"
// version: "1.0"
// author: "Pierre Lecomte"
// license: "GPL"
// copyright: "(c) Pierre Lecomte 2016"
//
// Code generated with Faust 0.9.95 (http://faust.grame.fr)
//----------------------------------------------------------
/* link with */
#include <math.h>
#ifndef FAUSTPOWER
#define FAUSTPOWER
#include <cmath>
template <int N> inline int faustpower(int x) { return faustpower<N/2>(x) * faustpower<N-N/2>(x); }
template <> inline int faustpower<0>(int x) { return 1; }
template <> inline int faustpower<1>(int x) { return x; }
template <> inline int faustpower<2>(int x) { return x*x; }
template <int N> inline double faustpower(double x) { return faustpower<N/2>(x) * faustpower<N-N/2>(x); }
template <> inline double faustpower<0>(double x) { return 1; }
template <> inline double faustpower<1>(double x) { return x; }
template <> inline double faustpower<2>(double x) { return x*x; }
#endif
// If other than 'faust2sc --prefix Faust' is used, sed this as well:
#if !defined(SC_FAUST_PREFIX)
# define SC_FAUST_PREFIX "Faust"
#endif
//-------------------------------------------------------------------
// FAUST architecture file for SuperCollider.
// Copyright (C) 2005-2012 Stefan Kersten.
//
// This program 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 2 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, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
// 02111-1307 USA
//-------------------------------------------------------------------
#include <map>
#include <string>
#include <string.h>
#include <SC_PlugIn.h>
/************************************************************************
IMPORTANT NOTE : this file contains two clearly delimited sections :
the ARCHITECTURE section (in two parts) and the USER section. Each section
is governed by its own copyright and license. Please check individually
each section for license and copyright information.
*************************************************************************/
/*******************BEGIN ARCHITECTURE SECTION (part 1/2)****************/
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 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.
************************************************************************
************************************************************************/
/******************************************************************************
*******************************************************************************
FAUST DSP
*******************************************************************************
*******************************************************************************/
#ifndef __dsp__
#define __dsp__
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
class UI;
struct Meta;
/**
* Signal processor definition.
*/
class dsp {
public:
dsp() {}
virtual ~dsp() {}
/* Return instance number of audio inputs */
virtual int getNumInputs() = 0;
/* Return instance number of audio outputs */
virtual int getNumOutputs() = 0;
/**
* Trigger the UI* parameter with instance specific calls
* to 'addBtton', 'addVerticalSlider'... in order to build the UI.
*
* @param ui_interface - the UI* 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 table initialisation
* - 'instanceInit' : constants and instance table initialisation
*
* @param samplingRate - the sampling rate in Herz
*/
virtual void init(int samplingRate) = 0;
/** Init instance state
*
* @param samplingRate - the sampling rate in Herz
*/
virtual void instanceInit(int samplingRate) = 0;
/** Init instance constant state
*
* @param samplingRate - the sampling rate in Herz
*/
virtual void instanceConstants(int samplingRate) = 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 dsp* 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 sucessive in/out audio buffers.
*
* @param count - the nomber of frames to compute
* @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, doucbe or quad)
* @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, doucbe 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 nomber of frames to compute
* @param inputs - the input audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, doucbe or quad)
* @param outputs - the output audio buffers as an array of non-interleaved FAUSTFLOAT samples (eiher float, doucbe 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 dsp {
protected:
dsp* fDSP;
public:
decorator_dsp(dsp* dsp = 0):fDSP(dsp) {}
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 samplingRate) { fDSP->init(samplingRate); }
virtual void instanceInit(int samplingRate) { fDSP->instanceInit(samplingRate); }
virtual void instanceConstants(int samplingRate) { fDSP->instanceConstants(samplingRate); }
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) { return fDSP->metadata(m); }
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); }
};
/**
* 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
/************************************************************************
FAUST Architecture File
Copyright (C) 2003-2016 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_UI_H
#define FAUST_UI_H
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
/*******************************************************************************
* UI : Faust User Interface
* This abstract class contains only the method that the faust compiler can
* generate to describe a DSP interface.
******************************************************************************/
class UI
{
public:
UI() {}
virtual ~UI() {}
// -- 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, FAUSTFLOAT* zone) = 0;
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) = 0;
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) = 0;
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) = 0;
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step) = 0;
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) = 0;
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) = 0;
// -- metadata declarations
virtual void declare(FAUSTFLOAT*, const char*, const char*) {}
};
//----------------------------------------------------------------
// Generic decorator
//----------------------------------------------------------------
class DecoratorUI : public UI
{
protected:
UI* fUI;
public:
DecoratorUI(UI* ui = 0):fUI(ui)
{}
virtual ~DecoratorUI() { delete fUI; }
// -- widget's layouts
virtual void openTabBox(const char* label) { fUI->openTabBox(label); }
virtual void openHorizontalBox(const char* label) { fUI->openHorizontalBox(label); }
virtual void openVerticalBox(const char* label) { fUI->openVerticalBox(label); }
virtual void closeBox() { fUI->closeBox(); }
// -- active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone) { fUI->addButton(label, zone); }
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone) { fUI->addCheckButton(label, zone); }
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ fUI->addVerticalSlider(label, zone, init, min, max, step); }
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ fUI->addHorizontalSlider(label, zone, init, min, max, step); }
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ fUI->addNumEntry(label, zone, init, min, max, step); }
// -- passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{ fUI->addHorizontalBargraph(label, zone, min, max); }
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{ fUI->addVerticalBargraph(label, zone, min, max); }
virtual void declare(FAUSTFLOAT* zone, const char* key, const char* val) { fUI->declare(zone, key, val); }
};
#endif
/************************************************************************
************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 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/>.
************************************************************************
************************************************************************/
#ifndef __misc__
#define __misc__
#include <algorithm>
#include <map>
#include <string.h>
#include <stdlib.h>
/************************************************************************
************************************************************************
FAUST Architecture File
Copyright (C) 2003-2011 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/>.
************************************************************************
************************************************************************/
#ifndef __meta__
#define __meta__
struct Meta
{
virtual void declare(const char* key, const char* value) = 0;
virtual ~Meta() {};
};
#endif
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; }
};
inline int lsr(int x, int n) { return int(((unsigned int)x) >> n); }
inline int int2pow2(int x) { int r = 0; while ((1<<r) < x) r++; return r; }
inline long lopt(char* argv[], const char* name, long def)
{
int i;
for (i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return atoi(argv[i+1]);
return def;
}
inline bool isopt(char* argv[], const char* name)
{
int i;
for (i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return true;
return false;
}
inline const char* lopts(char* argv[], const char* name, const char* def)
{
int i;
for (i = 0; argv[i]; i++) if (!strcmp(argv[i], name)) return argv[i+1];
return def;
}
#endif
using namespace std;
#if defined(__GNUC__) && __GNUC__ >= 4
# define FAUST_EXPORT __attribute__((visibility("default")))
#else
# define FAUST_EXPORT SC_API_EXPORT
#endif
//----------------------------------------------------------------------------
// Vector intrinsics
//----------------------------------------------------------------------------
//----------------------------------------------------------------------------
// Metadata
//----------------------------------------------------------------------------
class MetaData : public Meta
, public std::map<std::string, std::string>
{
public:
void declare(const char* key, const char* value)
{
(*this)[key] = value;
}
};
//----------------------------------------------------------------------------
// Control counter
//----------------------------------------------------------------------------
class ControlCounter : public UI
{
public:
ControlCounter()
: mNumControlInputs(0),
mNumControlOutputs(0)
{ }
size_t getNumControls() const { return getNumControlInputs(); }
size_t getNumControlInputs() const { return mNumControlInputs; }
size_t getNumControlOutputs() const { return mNumControlOutputs; }
// Layout widgets
virtual void openTabBox(const char* label) { }
virtual void openHorizontalBox(const char* label) { }
virtual void openVerticalBox(const char* label) { }
virtual void closeBox() { }
// Active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone)
{ addControlInput(); }
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
{ addControlInput(); }
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ addControlInput(); }
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ addControlInput(); }
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ addControlInput(); }
// Passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{ addControlOutput(); }
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max)
{ addControlOutput(); }
protected:
void addControlInput() { mNumControlInputs++; }
void addControlOutput() { mNumControlOutputs++; }
private:
size_t mNumControlInputs;
size_t mNumControlOutputs;
};
//----------------------------------------------------------------------------
// UI control
//----------------------------------------------------------------------------
struct Control
{
typedef void (*UpdateFunction)(Control* self, FAUSTFLOAT value);
UpdateFunction updateFunction;
FAUSTFLOAT* zone;
FAUSTFLOAT min, max;
inline void update(FAUSTFLOAT value)
{
(*updateFunction)(this, value);
}
static void simpleUpdate(Control* self, FAUSTFLOAT value)
{
*self->zone = value;
}
static void boundedUpdate(Control* self, FAUSTFLOAT value)
{
*self->zone = sc_clip(value, self->min, self->max);
}
};
//----------------------------------------------------------------------------
// Control allocator
//----------------------------------------------------------------------------
class ControlAllocator : public UI
{
public:
ControlAllocator(Control* controls)
: mControls(controls)
{ }
// Layout widgets
virtual void openTabBox(const char* label) { }
virtual void openHorizontalBox(const char* label) { }
virtual void openVerticalBox(const char* label) { }
virtual void closeBox() { }
// Active widgets
virtual void addButton(const char* label, FAUSTFLOAT* zone)
{ addSimpleControl(zone); }
virtual void addCheckButton(const char* label, FAUSTFLOAT* zone)
{ addSimpleControl(zone); }
virtual void addVerticalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ addBoundedControl(zone, min, max, step); }
virtual void addHorizontalSlider(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ addBoundedControl(zone, min, max, step); }
virtual void addNumEntry(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT init, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{ addBoundedControl(zone, min, max, step); }
// Passive widgets
virtual void addHorizontalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) { }
virtual void addVerticalBargraph(const char* label, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max) { }
private:
void addControl(Control::UpdateFunction updateFunction, FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT /* step */)
{
Control* ctrl = mControls++;
ctrl->updateFunction = updateFunction;
ctrl->zone = zone;
ctrl->min = min;
ctrl->max = max;
}
void addSimpleControl(FAUSTFLOAT* zone)
{
addControl(Control::simpleUpdate, zone, 0.f, 0.f, 0.f);
}
void addBoundedControl(FAUSTFLOAT* zone, FAUSTFLOAT min, FAUSTFLOAT max, FAUSTFLOAT step)
{
addControl(Control::boundedUpdate, zone, min, max, step);
}
private:
Control* mControls;
};
//----------------------------------------------------------------------------
// FAUST generated code
//----------------------------------------------------------------------------
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
#ifndef FAUSTCLASS
#define FAUSTCLASS mydsp
#endif
class mydsp : public dsp {
private:
FAUSTFLOAT fcheckbox0;
double fConst0;
double fConst1;
FAUSTFLOAT fentry0;
double fRec0[2];
double fRec1[2];
FAUSTFLOAT fslider0;
FAUSTFLOAT fslider1;
double fRec2[2];
double fRec3[2];
double fRec4[2];
FAUSTFLOAT fslider2;
int fSamplingFreq;
public:
virtual void metadata(Meta* m) {
m->declare("name", "HOABeamDirac2Hoa2");
m->declare("version", "1.0");
m->declare("author", "Pierre Lecomte");
m->declare("license", "GPL");
m->declare("copyright", "(c) Pierre Lecomte 2016");
m->declare("lib/lebedev.lib/name", "Lebdev grids and weights");
m->declare("lib/lebedev.lib/version", "1.0");
m->declare("lib/lebedev.lib/author", "Pierre Lecomte");
m->declare("lib/lebedev.lib/license", "GPL");
m->declare("lib/lebedev.lib/copyright", "(c) Pierre Lecomte 2014");
m->declare("lib/ymn.lib/name", "Spherical Harmonics library");
m->declare("lib/ymn.lib/version", "1.0");
m->declare("lib/ymn.lib/author", "Pierre Lecomte");
m->declare("lib/ymn.lib/license", "GPL");
m->declare("lib/ymn.lib/copyright", "(c) Pierre Lecomte 2016");
m->declare("lib/nfc.lib/name", "NF And NFC Filters Library");
m->declare("lib/nfc.lib/version", "1.0");
m->declare("lib/nfc.lib/author", "Pierre Lecomte");
m->declare("lib/nfc.lib/license", "GPL");
m->declare("lib/nfc.lib/copyright", "(c) Pierre Lecomte 2014");
m->declare("lib/gui.lib/name", "GUI Library");
m->declare("lib/gui.lib/version", "1.0");
m->declare("lib/gui.lib/author", "Pierre Lecomte");
m->declare("lib/gui.lib/license", "GPL");
m->declare("lib/gui.lib/copyright", "(c) Pierre Lecomte 2016");
m->declare("basic.lib/name", "Faust Basic Element Library");
m->declare("basic.lib/version", "0.0");
m->declare("math.lib/name", "Faust Math Library");
m->declare("math.lib/version", "2.0");
m->declare("math.lib/author", "GRAME");
m->declare("math.lib/copyright", "GRAME");
m->declare("math.lib/license", "LGPL with exception");
m->declare("signal.lib/name", "Faust Signal Routing Library");
m->declare("signal.lib/version", "0.0");
}
virtual int getNumInputs() { return 9; }
virtual int getNumOutputs() { return 9; }
static void classInit(int samplingFreq) {
}
virtual void instanceConstants(int samplingFreq) {
fSamplingFreq = samplingFreq;
fConst0 = min(1.92e+05, max(1.0, (double)fSamplingFreq));
fConst1 = (1.0 / fConst0);
}
virtual void instanceResetUserInterface() {
fcheckbox0 = 0.0;
fentry0 = 1.0;
fslider0 = 0.0;
fslider1 = 0.0;
fslider2 = 0.0;
}
virtual void instanceClear() {
for (int i=0; i<2; i++) fRec0[i] = 0;
for (int i=0; i<2; i++) fRec1[i] = 0;
for (int i=0; i<2; i++) fRec2[i] = 0;
for (int i=0; i<2; i++) fRec3[i] = 0;
for (int i=0; i<2; i++) fRec4[i] = 0;
}
virtual void init(int samplingFreq) {
classInit(samplingFreq);
instanceInit(samplingFreq);
}
virtual void instanceInit(int samplingFreq) {
instanceConstants(samplingFreq);
instanceResetUserInterface();
instanceClear();
}
virtual mydsp* clone() {
return new mydsp();
}
virtual int getSampleRate() {
return fSamplingFreq;
}
virtual void buildUserInterface(UI* ui_interface) {
ui_interface->openHorizontalBox("Parameters");
ui_interface->declare(0, "2", "");
ui_interface->openVerticalBox("On/Off");
ui_interface->addCheckButton("On", &fcheckbox0);
ui_interface->closeBox();
ui_interface->declare(&fentry0, "3", "");
ui_interface->declare(&fentry0, "unit", "s");
ui_interface->addNumEntry("Crossfade", &fentry0, 1.0, 0.1, 1e+01, 0.1);
ui_interface->declare(&fslider1, "4", "");
ui_interface->declare(&fslider1, "unit", "dB");
ui_interface->addVerticalSlider("Gain", &fslider1, 0.0, -2e+01, 2e+01, 0.1);
ui_interface->declare(&fslider2, "5", "");
ui_interface->addVerticalSlider("Azimuth", &fslider2, 0.0, -1.5707963267948966, 1.5707963267948966, 0.1);
ui_interface->declare(&fslider0, "6", "");
ui_interface->addVerticalSlider("Elevation", &fslider0, 0.0, -1.5707963267948966, 1.5707963267948966, 0.1);
ui_interface->closeBox();
}
virtual void compute (int count, FAUSTFLOAT** input, FAUSTFLOAT** output) {
double fSlow0 = double(fcheckbox0);
int iSlow1 = int(fSlow0);
double fSlow2 = double(fentry0);
double fSlow3 = (fConst1 / fSlow2);
int iSlow4 = int(((1 - fSlow0) > 0));
double fSlow5 = (fConst0 * fSlow2);
int iSlow6 = int((fSlow0 > 0));
double fSlow7 = double(fslider0);
double fSlow8 = sin(fSlow7);
double fSlow9 = ((3 * faustpower<2>(fSlow8)) + -1);
double fSlow10 = (1.118033988749895 * fSlow9);
double fSlow11 = (0.0010000000000000009 * pow(10,(0.05 * double(fslider1))));
double fSlow12 = cos(fSlow7);
double fSlow13 = double(fslider2);
double fSlow14 = cos(fSlow13);
double fSlow15 = sin(fSlow13);
double fSlow16 = sin((2 * fSlow7));
double fSlow17 = faustpower<2>(fSlow12);
double fSlow18 = (2 * fSlow13);
double fSlow19 = sin(fSlow18);
double fSlow20 = cos(fSlow18);
double fSlow21 = (0.13783222385544802 * (fSlow12 * fSlow15));
double fSlow22 = (0.13783222385544802 * fSlow8);
double fSlow23 = (0.13783222385544802 * (fSlow12 * fSlow14));
double fSlow24 = (0.15410111101537496 * (fSlow17 * fSlow19));
double fSlow25 = (0.15410111101537496 * (fSlow16 * fSlow15));
double fSlow26 = (0.08897031792714714 * fSlow9);
double fSlow27 = (0.15410111101537496 * (fSlow16 * fSlow14));
double fSlow28 = (0.15410111101537496 * (fSlow17 * fSlow20));
FAUSTFLOAT* input0 = input[0];
FAUSTFLOAT* input1 = input[1];
FAUSTFLOAT* input2 = input[2];
FAUSTFLOAT* input3 = input[3];
FAUSTFLOAT* input4 = input[4];
FAUSTFLOAT* input5 = input[5];
FAUSTFLOAT* input6 = input[6];
FAUSTFLOAT* input7 = input[7];
FAUSTFLOAT* input8 = input[8];
FAUSTFLOAT* output0 = output[0];
FAUSTFLOAT* output1 = output[1];
FAUSTFLOAT* output2 = output[2];
FAUSTFLOAT* output3 = output[3];
FAUSTFLOAT* output4 = output[4];
FAUSTFLOAT* output5 = output[5];
FAUSTFLOAT* output6 = output[6];
FAUSTFLOAT* output7 = output[7];
FAUSTFLOAT* output8 = output[8];
for (int i=0; i<count; i++) {
double fTemp0 = (double)input0[i];
fRec0[0] = ((iSlow4)?fSlow5:max((double)0, (fRec0[1] + -1)));
fRec1[0] = ((iSlow6)?0:min(fSlow5, (fRec1[1] + 1)));
double fTemp1 = (double)input6[i];
fRec2[0] = (fSlow11 + (0.999 * fRec2[1]));
double fTemp2 = (fTemp1 * fRec2[0]);
fRec3[0] = ((iSlow4)?0:min(fSlow5, (fRec3[1] + 1)));
fRec4[0] = ((iSlow6)?fSlow5:max((double)0, (fRec4[1] + -1)));
double fTemp3 = (fTemp0 * fRec2[0]);
double fTemp4 = (double)input2[i];
double fTemp5 = (fTemp4 * fRec2[0]);
double fTemp6 = (double)input3[i];
double fTemp7 = (fTemp6 * fRec2[0]);
double fTemp8 = (double)input1[i];
double fTemp9 = (fTemp8 * fRec2[0]);
double fTemp10 = (double)input5[i];
double fTemp11 = (fTemp10 * fRec2[0]);
double fTemp12 = (double)input7[i];
double fTemp13 = (fTemp12 * fRec2[0]);
double fTemp14 = (double)input4[i];
double fTemp15 = (fTemp14 * fRec2[0]);
double fTemp16 = (double)input8[i];
double fTemp17 = (fTemp16 * fRec2[0]);
double fTemp18 = (((fSlow10 * ((iSlow1)?(fSlow3 * (fTemp2 * fRec3[0])):(fSlow3 * (fTemp2 * fRec4[0])))) + (((iSlow1)?(fSlow3 * (fTemp3 * fRec3[0])):(fSlow3 * (fTemp3 * fRec4[0]))) + (1.7320508075688772 * ((fSlow8 * ((iSlow1)?(fSlow3 * (fTemp5 * fRec3[0])):(fSlow3 * (fTemp5 * fRec4[0])))) + (fSlow12 * ((fSlow14 * ((iSlow1)?(fSlow3 * (fTemp7 * fRec3[0])):(fSlow3 * (fTemp7 * fRec4[0])))) + (fSlow15 * ((iSlow1)?(fSlow3 * (fTemp9 * fRec3[0])):(fSlow3 * (fTemp9 * fRec4[0])))))))))) + (1.9364916731037085 * ((fSlow16 * ((fSlow15 * ((iSlow1)?(fSlow3 * (fTemp11 * fRec3[0])):(fSlow3 * (fTemp11 * fRec4[0])))) + (fSlow14 * ((iSlow1)?(fSlow3 * (fTemp13 * fRec3[0])):(fSlow3 * (fTemp13 * fRec4[0])))))) + (fSlow17 * ((fSlow19 * ((iSlow1)?(fSlow3 * (fTemp15 * fRec3[0])):(fSlow3 * (fTemp15 * fRec4[0])))) + (fSlow20 * ((iSlow1)?(fSlow3 * (fTemp17 * fRec3[0])):(fSlow3 * (fTemp17 * fRec4[0])))))))));
output0[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp0 * fRec0[0])):(fSlow3 * (fTemp0 * fRec1[0]))) + (0.07957747154594767 * fTemp18));
output1[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp8 * fRec0[0])):(fSlow3 * (fTemp8 * fRec1[0]))) + (fSlow21 * fTemp18));
output2[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp4 * fRec0[0])):(fSlow3 * (fTemp4 * fRec1[0]))) + (fSlow22 * fTemp18));
output3[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp6 * fRec0[0])):(fSlow3 * (fTemp6 * fRec1[0]))) + (fSlow23 * fTemp18));
output4[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp14 * fRec0[0])):(fSlow3 * (fTemp14 * fRec1[0]))) + (fSlow24 * fTemp18));
output5[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp10 * fRec0[0])):(fSlow3 * (fTemp10 * fRec1[0]))) + (fSlow25 * fTemp18));
output6[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp1 * fRec0[0])):(fSlow3 * (fTemp1 * fRec1[0]))) + (fSlow26 * fTemp18));
output7[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp12 * fRec0[0])):(fSlow3 * (fTemp12 * fRec1[0]))) + (fSlow27 * fTemp18));
output8[i] = (FAUSTFLOAT)(((iSlow1)?(fSlow3 * (fTemp16 * fRec0[0])):(fSlow3 * (fTemp16 * fRec1[0]))) + (fSlow28 * fTemp18));
// post processing
fRec4[1] = fRec4[0];
fRec3[1] = fRec3[0];
fRec2[1] = fRec2[0];
fRec1[1] = fRec1[0];
fRec0[1] = fRec0[0];
}
}
};
//----------------------------------------------------------------------------
// SuperCollider/Faust interface
//----------------------------------------------------------------------------
struct Faust : public Unit
{
// Faust dsp instance
FAUSTCLASS* mDSP;
// Buffers for control to audio rate conversion
float** mInBufCopy;
float* mInBufValue;
// Controls
size_t mNumControls;
// NOTE: This needs to be the last field!
//
// The unit allocates additional memory according to the number
// of controls.
Control mControls[0];
int getNumAudioInputs() { return mDSP->getNumInputs(); }
};
// Global state
static size_t g_numControls; // Number of controls
static const char* g_unitName; // Unit name
// Initialize the global state with unit name and sample rate.
void initState(const std::string& name, int sampleRate);
// Return the unit size in bytes, including static fields and controls.
static size_t unitSize();
// Convert a file name to a valid unit name.
static std::string fileNameToUnitName(const std::string& fileName);
// Convert the XML unit name to a valid class name.
static std::string normalizeClassName(const std::string& name);
void initState(const std::string& name, int sampleRate)
{
g_unitName = strdup(name.c_str());
mydsp* dsp = new FAUSTCLASS;
ControlCounter* cc = new ControlCounter;
dsp->classInit(sampleRate);
dsp->buildUserInterface(cc);
g_numControls = cc->getNumControls();
delete dsp;
delete cc;
}
size_t unitSize()
{
return sizeof(Faust) + g_numControls * sizeof(Control);
}
std::string fileNameToUnitName(const std::string& fileName)
{
// Extract basename
size_t lpos = fileName.rfind('/', fileName.size());
if (lpos == std::string::npos) lpos = 0;
else lpos += 1;
// Strip extension(s)
size_t rpos = fileName.find('.', lpos);
// Return substring
return fileName.substr(lpos, rpos > lpos ? rpos - lpos : 0);
}
// Globals
static InterfaceTable *ft;
// The SuperCollider UGen class name generated here must match
// that generated by faust2sc:
static std::string normalizeClassName(const std::string& name)
{
std::string s;
char c;
unsigned int i=0;
bool upnext=true;
while ((c=name[i++])) {
if (upnext) { c = toupper(c); upnext=false; }
if ( (c == '_') || (c == '-') || isspace(c)) { upnext=true; continue; }
s += c;
if (i > 31) { break; }
}
return s;
}
extern "C"
{
#ifdef SC_API_EXPORT
int api_version(void);
#endif
void load(InterfaceTable*);
void Faust_next(Faust*, int);
void Faust_next_copy(Faust*, int);
void Faust_next_clear(Faust*, int);
void Faust_Ctor(Faust*);
void Faust_Dtor(Faust*);
};
inline static void fillBuffer(float* dst, int n, float v)
{
Fill(n, dst, v);
}
inline static void fillBuffer(float* dst, int n, float v0, float v1)
{
Fill(n, dst, v0, (v1 - v0) / n);
}
inline static void copyBuffer(float* dst, int n, float* src)
{
Copy(n, dst, src);
}
inline static void Faust_updateControls(Faust* unit)
{
Control* controls = unit->mControls;
int numControls = unit->mNumControls;
int curControl = unit->mDSP->getNumInputs();
for (int i=0; i < numControls; ++i) {
float value = IN0(curControl);
(controls++)->update(value);
curControl++;
}
}
void Faust_next(Faust* unit, int inNumSamples)
{
// update controls
Faust_updateControls(unit);
// dsp computation
unit->mDSP->compute(inNumSamples, unit->mInBuf, unit->mOutBuf);
}
void Faust_next_copy(Faust* unit, int inNumSamples)
{
// update controls
Faust_updateControls(unit);
// Copy buffers
for (int i = 0; i < unit->getNumAudioInputs(); ++i) {
float* b = unit->mInBufCopy[i];
if (INRATE(i) == calc_FullRate) {
// Audio rate: copy buffer
copyBuffer(b, inNumSamples, unit->mInBuf[i]);
} else {
// Control rate: linearly interpolate input
float v1 = IN0(i);
fillBuffer(b, inNumSamples, unit->mInBufValue[i], v1);
unit->mInBufValue[i] = v1;
}
}
// dsp computation
unit->mDSP->compute(inNumSamples, unit->mInBufCopy, unit->mOutBuf);
}