-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathNoiseLFO.cpp
More file actions
518 lines (412 loc) · 11.5 KB
/
NoiseLFO.cpp
File metadata and controls
518 lines (412 loc) · 11.5 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
//------------------------------------------------------------------------------
// This file was generated using the Faust compiler (https://faust.grame.fr),
// and the Faust post-processor (https://github.com/jpcima/faustpp).
//
// Source: NoiseLFO.dsp
// Name: NoiseLFO
// Author:
// Copyright:
// License:
// Version:
//------------------------------------------------------------------------------
#include "NoiseLFO.hpp"
#include <utility>
#include <cmath>
class NoiseLFO::BasicDsp {
public:
virtual ~BasicDsp() {}
};
//------------------------------------------------------------------------------
// Begin the Faust code section
namespace {
template <class T> inline T min(T a, T b) { return (a < b) ? a : b; }
template <class T> inline T max(T a, T b) { return (a > b) ? a : b; }
class Meta {
public:
// dummy
void declare(...) {}
};
class UI {
public:
// dummy
void openHorizontalBox(...) {}
void openVerticalBox(...) {}
void closeBox(...) {}
void declare(...) {}
void addButton(...) {}
void addCheckButton(...) {}
void addVerticalSlider(...) {}
void addHorizontalSlider(...) {}
void addVerticalBargraph(...) {}
};
typedef NoiseLFO::BasicDsp dsp;
} // namespace
#define FAUSTPP_VIRTUAL // do not declare any methods virtual
#define FAUSTPP_PRIVATE public // do not hide any members
#define FAUSTPP_PROTECTED public // do not hide any members
// define the DSP in the anonymous namespace
#define FAUSTPP_BEGIN_NAMESPACE namespace {
#define FAUSTPP_END_NAMESPACE }
#if defined(__GNUC__)
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wunused-parameter"
#endif
#ifndef FAUSTPP_PRIVATE
# define FAUSTPP_PRIVATE private
#endif
#ifndef FAUSTPP_PROTECTED
# define FAUSTPP_PROTECTED protected
#endif
#ifndef FAUSTPP_VIRTUAL
# define FAUSTPP_VIRTUAL virtual
#endif
#ifndef FAUSTPP_BEGIN_NAMESPACE
# define FAUSTPP_BEGIN_NAMESPACE
#endif
#ifndef FAUSTPP_END_NAMESPACE
# define FAUSTPP_END_NAMESPACE
#endif
FAUSTPP_BEGIN_NAMESPACE
#ifndef FAUSTFLOAT
#define FAUSTFLOAT float
#endif
FAUSTPP_END_NAMESPACE
#include <algorithm>
#include <cmath>
#include <math.h>
FAUSTPP_BEGIN_NAMESPACE
#ifndef FAUSTCLASS
#define FAUSTCLASS NoiseLFODsp
#endif
#ifdef __APPLE__
#define exp10f __exp10f
#define exp10 __exp10
#endif
class NoiseLFODsp : public dsp {
FAUSTPP_PRIVATE:
int fSampleRate;
float fConst0;
float fConst1;
FAUSTFLOAT fHslider0;
int iVec0[2];
float fConst2;
float fRec6[2];
float fRec7[2];
int iRec8[2];
float fRec5[2];
float fRec4[2];
float fRec3[2];
float fRec2[2];
float fRec1[2];
float fRec0[2];
public:
void metadata(Meta* m) {
m->declare("basics.lib/name", "Faust Basic Element Library");
m->declare("basics.lib/version", "0.1");
m->declare("filename", "NoiseLFO.dsp");
m->declare("filters.lib/lowpass0_highpass1", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("filters.lib/lowpass0_highpass1:author", "Julius O. Smith III");
m->declare("filters.lib/lowpass:author", "Julius O. Smith III");
m->declare("filters.lib/lowpass:copyright", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("filters.lib/lowpass:license", "MIT-style STK-4.3 license");
m->declare("filters.lib/name", "Faust Filters Library");
m->declare("filters.lib/nlf2:author", "Julius O. Smith III");
m->declare("filters.lib/nlf2:copyright", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("filters.lib/nlf2:license", "MIT-style STK-4.3 license");
m->declare("filters.lib/tf1:author", "Julius O. Smith III");
m->declare("filters.lib/tf1:copyright", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("filters.lib/tf1:license", "MIT-style STK-4.3 license");
m->declare("filters.lib/tf1s:author", "Julius O. Smith III");
m->declare("filters.lib/tf1s:copyright", "Copyright (C) 2003-2019 by Julius O. Smith III <jos@ccrma.stanford.edu>");
m->declare("filters.lib/tf1s:license", "MIT-style STK-4.3 license");
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.1");
m->declare("name", "NoiseLFO");
m->declare("noises.lib/name", "Faust Noise Generator Library");
m->declare("noises.lib/version", "0.0");
m->declare("oscillators.lib/name", "Faust Oscillator Library");
m->declare("oscillators.lib/version", "0.0");
}
FAUSTPP_VIRTUAL int getNumInputs() {
return 0;
}
FAUSTPP_VIRTUAL int getNumOutputs() {
return 1;
}
FAUSTPP_VIRTUAL int getInputRate(int channel) {
int rate;
switch ((channel)) {
default: {
rate = -1;
break;
}
}
return rate;
}
FAUSTPP_VIRTUAL int getOutputRate(int channel) {
int rate;
switch ((channel)) {
case 0: {
rate = 1;
break;
}
default: {
rate = -1;
break;
}
}
return rate;
}
static void classInit(int sample_rate) {
}
FAUSTPP_VIRTUAL void instanceConstants(int sample_rate) {
fSampleRate = sample_rate;
fConst0 = std::min<float>(192000.0f, std::max<float>(1.0f, float(fSampleRate)));
fConst1 = (3.14159274f / fConst0);
fConst2 = (6.28318548f / fConst0);
}
FAUSTPP_VIRTUAL void instanceResetUserInterface() {
fHslider0 = FAUSTFLOAT(1.0f);
}
FAUSTPP_VIRTUAL void instanceClear() {
for (int l0 = 0; (l0 < 2); l0 = (l0 + 1)) {
iVec0[l0] = 0;
}
for (int l1 = 0; (l1 < 2); l1 = (l1 + 1)) {
fRec6[l1] = 0.0f;
}
for (int l2 = 0; (l2 < 2); l2 = (l2 + 1)) {
fRec7[l2] = 0.0f;
}
for (int l3 = 0; (l3 < 2); l3 = (l3 + 1)) {
iRec8[l3] = 0;
}
for (int l4 = 0; (l4 < 2); l4 = (l4 + 1)) {
fRec5[l4] = 0.0f;
}
for (int l5 = 0; (l5 < 2); l5 = (l5 + 1)) {
fRec4[l5] = 0.0f;
}
for (int l6 = 0; (l6 < 2); l6 = (l6 + 1)) {
fRec3[l6] = 0.0f;
}
for (int l7 = 0; (l7 < 2); l7 = (l7 + 1)) {
fRec2[l7] = 0.0f;
}
for (int l8 = 0; (l8 < 2); l8 = (l8 + 1)) {
fRec1[l8] = 0.0f;
}
for (int l9 = 0; (l9 < 2); l9 = (l9 + 1)) {
fRec0[l9] = 0.0f;
}
}
FAUSTPP_VIRTUAL void init(int sample_rate) {
classInit(sample_rate);
instanceInit(sample_rate);
}
FAUSTPP_VIRTUAL void instanceInit(int sample_rate) {
instanceConstants(sample_rate);
instanceResetUserInterface();
instanceClear();
}
FAUSTPP_VIRTUAL NoiseLFODsp* clone() {
return new NoiseLFODsp();
}
FAUSTPP_VIRTUAL int getSampleRate() {
return fSampleRate;
}
FAUSTPP_VIRTUAL void buildUserInterface(UI* ui_interface) {
ui_interface->openVerticalBox("NoiseLFO");
ui_interface->declare(&fHslider0, "1", "");
ui_interface->declare(&fHslider0, "symbol", "frequency");
ui_interface->declare(&fHslider0, "unit", "Hz");
ui_interface->addHorizontalSlider("Frequency", &fHslider0, 1.0f, 0.0f, 100.0f, 1.0f);
ui_interface->closeBox();
}
FAUSTPP_VIRTUAL void compute(int count, FAUSTFLOAT** inputs, FAUSTFLOAT** outputs) {
FAUSTFLOAT* output0 = outputs[0];
float fSlow0 = float(fHslider0);
float fSlow1 = (1.0f / std::tan((fConst1 * fSlow0)));
float fSlow2 = (1.0f / (fSlow1 + 1.0f));
float fSlow3 = (1.0f - fSlow1);
float fSlow4 = (fConst2 * fSlow0);
float fSlow5 = std::sin(fSlow4);
float fSlow6 = std::cos(fSlow4);
for (int i = 0; (i < count); i = (i + 1)) {
iVec0[0] = 1;
fRec6[0] = ((fSlow5 * fRec7[1]) + (fSlow6 * fRec6[1]));
fRec7[0] = ((float((1 - iVec0[1])) + (fSlow6 * fRec7[1])) - (fSlow5 * fRec6[1]));
int iTemp0 = ((fRec6[1] <= 0.0f) & (fRec6[0] > 0.0f));
iRec8[0] = ((1103515245 * iRec8[1]) + 12345);
fRec5[0] = ((fRec5[1] * float((1 - iTemp0))) + (4.65661287e-10f * (float(iRec8[0]) * float(iTemp0))));
fRec4[0] = (0.0f - (fSlow2 * ((fSlow3 * fRec4[1]) - (fRec5[0] + fRec5[1]))));
fRec3[0] = (0.0f - (fSlow2 * ((fSlow3 * fRec3[1]) - (fRec4[0] + fRec4[1]))));
fRec2[0] = (0.0f - (fSlow2 * ((fSlow3 * fRec2[1]) - (fRec3[0] + fRec3[1]))));
fRec1[0] = (0.0f - (fSlow2 * ((fSlow3 * fRec1[1]) - (fRec2[0] + fRec2[1]))));
fRec0[0] = (0.0f - (fSlow2 * ((fSlow3 * fRec0[1]) - (fRec1[0] + fRec1[1]))));
output0[i] = FAUSTFLOAT(fRec0[0]);
iVec0[1] = iVec0[0];
fRec6[1] = fRec6[0];
fRec7[1] = fRec7[0];
iRec8[1] = iRec8[0];
fRec5[1] = fRec5[0];
fRec4[1] = fRec4[0];
fRec3[1] = fRec3[0];
fRec2[1] = fRec2[0];
fRec1[1] = fRec1[0];
fRec0[1] = fRec0[0];
}
}
};
FAUSTPP_END_NAMESPACE
#if defined(__GNUC__)
# pragma GCC diagnostic pop
#endif
//------------------------------------------------------------------------------
// End the Faust code section
NoiseLFO::NoiseLFO()
{
NoiseLFODsp *dsp = new NoiseLFODsp;
fDsp.reset(dsp);
dsp->instanceResetUserInterface();
}
NoiseLFO::~NoiseLFO()
{
}
void NoiseLFO::init(float sample_rate)
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
dsp.classInit(sample_rate);
dsp.instanceConstants(sample_rate);
clear();
}
void NoiseLFO::clear() noexcept
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
dsp.instanceClear();
}
void NoiseLFO::process(
float *out0,
unsigned count) noexcept
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
float *inputs[] = {
0
};
float *outputs[] = {
out0,
};
dsp.compute(count, inputs, outputs);
}
const char *NoiseLFO::parameter_label(unsigned index) noexcept
{
switch (index) {
case 0:
return "Frequency";
default:
return 0;
}
}
const char *NoiseLFO::parameter_short_label(unsigned index) noexcept
{
switch (index) {
case 0:
return "";
default:
return 0;
}
}
const char *NoiseLFO::parameter_symbol(unsigned index) noexcept
{
switch (index) {
case 0:
return "frequency";
default:
return 0;
}
}
const char *NoiseLFO::parameter_unit(unsigned index) noexcept
{
switch (index) {
case 0:
return "Hz";
default:
return 0;
}
}
const NoiseLFO::ParameterRange *NoiseLFO::parameter_range(unsigned index) noexcept
{
switch (index) {
case 0: {
static const ParameterRange range = { 1, 0, 100 };
return ⦥
}
default:
return 0;
}
}
bool NoiseLFO::parameter_is_trigger(unsigned index) noexcept
{
switch (index) {
default:
return false;
}
}
bool NoiseLFO::parameter_is_boolean(unsigned index) noexcept
{
switch (index) {
default:
return false;
}
}
bool NoiseLFO::parameter_is_integer(unsigned index) noexcept
{
switch (index) {
default:
return false;
}
}
bool NoiseLFO::parameter_is_logarithmic(unsigned index) noexcept
{
switch (index) {
default:
return false;
}
}
float NoiseLFO::get_parameter(unsigned index) const noexcept
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
switch (index) {
case 0:
return dsp.fHslider0;
default:
(void)dsp;
return 0;
}
}
void NoiseLFO::set_parameter(unsigned index, float value) noexcept
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
switch (index) {
case 0:
dsp.fHslider0 = value;
break;
default:
(void)dsp;
(void)value;
break;
}
}
float NoiseLFO::get_frequency() const noexcept
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
return dsp.fHslider0;
}
void NoiseLFO::set_frequency(float value) noexcept
{
NoiseLFODsp &dsp = static_cast<NoiseLFODsp &>(*fDsp);
dsp.fHslider0 = value;
}