-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgen_exported.cpp
More file actions
263 lines (222 loc) · 7.69 KB
/
gen_exported.cpp
File metadata and controls
263 lines (222 loc) · 7.69 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
#include "gen_exported.h"
namespace gen_exported {
/*******************************************************************************************************************
Copyright (c) 2012 Cycling '74
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.
*******************************************************************************************************************/
// global noise generator
Noise noise;
static const int GENLIB_LOOPCOUNT_BAIL = 100000;
// The State struct contains all the state and procedures for the gendsp kernel
typedef struct State {
CommonState __commonstate;
Delay m_delay_5;
SineCycle m_cycle_7;
SineCycle m_cycle_6;
SineData __sinedata;
double m_fb_4;
double m_depth_3;
double m_centre_1;
double samplerate;
double m_rate_2;
int vectorsize;
int __exception;
// re-initialize all member variables;
inline void reset(double __sr, int __vs) {
__exception = 0;
vectorsize = __vs;
samplerate = __sr;
m_centre_1 = 500;
m_rate_2 = 0.1;
m_depth_3 = 150;
m_fb_4 = 0.8;
m_delay_5.reset("m_delay_5", 4410);
m_cycle_6.reset(samplerate, 0);
m_cycle_7.reset(samplerate, 0);
genlib_reset_complete(this);
};
// the signal processing routine;
inline int perform(t_sample ** __ins, t_sample ** __outs, int __n) {
vectorsize = __n;
const t_sample * __in1 = __ins[0];
t_sample * __out1 = __outs[0];
t_sample * __out2 = __outs[1];
if (__exception) {
return __exception;
} else if (( (__in1 == 0) || (__out1 == 0) || (__out2 == 0) )) {
__exception = GENLIB_ERR_NULL_BUFFER;
return __exception;
};
double mul_1261 = (m_rate_2 * 1.31);
// the main sample loop;
while ((__n--)) {
const double in1 = (*(__in1++));
m_cycle_6.freq(m_rate_2);
double cycle_1269 = m_cycle_6(__sinedata);
double cycleindex_1270 = m_cycle_6.phase();
double mul_1267 = (cycle_1269 * m_depth_3);
double add_1268 = (mul_1267 + m_centre_1);
m_cycle_7.freq(mul_1261);
double cycle_1265 = m_cycle_7(__sinedata);
double cycleindex_1266 = m_cycle_7.phase();
double mul_1263 = (cycle_1265 * m_depth_3);
double add_1264 = (mul_1263 + m_centre_1);
double tap_1272 = m_delay_5.read_linear(add_1268);
double tap_1273 = m_delay_5.read_linear(add_1264);
double out2 = (tap_1273 + in1);
double out1 = (tap_1272 + in1);
double mul_1259 = (tap_1272 * m_fb_4);
m_delay_5.write((mul_1259 + in1));
m_delay_5.step();
// assign results to output buffer;
(*(__out1++)) = out1;
(*(__out2++)) = out2;
};
return __exception;
};
inline void set_centre(double _value) {
m_centre_1 = (_value < 10 ? 10 : (_value > 1000 ? 1000 : _value));
};
inline void set_rate(double _value) {
m_rate_2 = (_value < 0.01 ? 0.01 : (_value > 5 ? 5 : _value));
};
inline void set_depth(double _value) {
m_depth_3 = (_value < 10 ? 10 : (_value > 300 ? 300 : _value));
};
inline void set_fb(double _value) {
m_fb_4 = (_value < -0.999 ? -0.999 : (_value > 0.999 ? 0.999 : _value));
};
} State;
///
/// Configuration for the genlib API
///
/// Number of signal inputs and outputs
int gen_kernel_numins = 1;
int gen_kernel_numouts = 2;
int num_inputs() { return gen_kernel_numins; }
int num_outputs() { return gen_kernel_numouts; }
int num_params() { return 4; }
/// Assistive lables for the signal inputs and outputs
const char * gen_kernel_innames[] = { "in1" };
const char * gen_kernel_outnames[] = { "out1", "out2" };
/// Invoke the signal process of a State object
int perform(CommonState *cself, t_sample **ins, long numins, t_sample **outs, long numouts, long n) {
State * self = (State *)cself;
return self->perform(ins, outs, n);
}
/// Reset all parameters and stateful operators of a State object
void reset(CommonState *cself) {
State * self = (State *)cself;
self->reset(cself->sr, cself->vs);
}
/// Set a parameter of a State object
void setparameter(CommonState *cself, long index, double value, void *ref) {
State * self = (State *)cself;
switch (index) {
case 0: self->set_centre(value); break;
case 1: self->set_rate(value); break;
case 2: self->set_depth(value); break;
case 3: self->set_fb(value); break;
default: break;
}
}
/// Get the value of a parameter of a State object
void getparameter(CommonState *cself, long index, double *value) {
State *self = (State *)cself;
switch (index) {
case 0: *value = self->m_centre_1; break;
case 1: *value = self->m_rate_2; break;
case 2: *value = self->m_depth_3; break;
case 3: *value = self->m_fb_4; break;
default: break;
}
}
/// Allocate and configure a new State object and it's internal CommonState:
void * create(double sr, long vs) {
State *self = new State;
self->reset(sr, vs);
ParamInfo *pi;
self->__commonstate.inputnames = gen_kernel_innames;
self->__commonstate.outputnames = gen_kernel_outnames;
self->__commonstate.numins = gen_kernel_numins;
self->__commonstate.numouts = gen_kernel_numouts;
self->__commonstate.sr = sr;
self->__commonstate.vs = vs;
self->__commonstate.params = (ParamInfo *)genlib_sysmem_newptr(4 * sizeof(ParamInfo));
self->__commonstate.numparams = 4;
// initialize parameter 0 ("m_centre_1")
pi = self->__commonstate.params + 0;
pi->name = "centre";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_centre_1;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 10;
pi->outputmax = 1000;
pi->exp = 0;
pi->units = ""; // no units defined
// initialize parameter 1 ("m_rate_2")
pi = self->__commonstate.params + 1;
pi->name = "rate";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_rate_2;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 0.01;
pi->outputmax = 5;
pi->exp = 0;
pi->units = ""; // no units defined
// initialize parameter 2 ("m_depth_3")
pi = self->__commonstate.params + 2;
pi->name = "depth";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_depth_3;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = 10;
pi->outputmax = 300;
pi->exp = 0;
pi->units = ""; // no units defined
// initialize parameter 3 ("m_fb_4")
pi = self->__commonstate.params + 3;
pi->name = "fb";
pi->paramtype = GENLIB_PARAMTYPE_FLOAT;
pi->defaultvalue = self->m_fb_4;
pi->defaultref = 0;
pi->hasinputminmax = false;
pi->inputmin = 0;
pi->inputmax = 1;
pi->hasminmax = true;
pi->outputmin = -0.999;
pi->outputmax = 0.999;
pi->exp = 0;
pi->units = ""; // no units defined
return self;
}
/// Release all resources and memory used by a State object:
void destroy(CommonState *cself) {
State * self = (State *)cself;
genlib_sysmem_freeptr(cself->params);
delete self;
}
} // gen_exported::