FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Edge/src/K_Rush.cpp at master · Edge-Modules/Edge · GitHub
Edge-Modules
/
Edge
Public
Notifications
You must be signed in to change notification settings
Fork
9
Star
21
Code
Issues
0
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Edge
/
src
/
K_Rush.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
402 lines (268 loc) · 11.4 KB
Breadcrumbs
Edge
/
src
/
K_Rush.cpp
Copy path
File metadata and controls
402 lines (268 loc) · 11.4 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
Edge.hpp
"
#
include
"
dep/dr_wav.h
"
using
namespace
std
;
static
const
size_t
BLOCK_SIZE
=
512
;
static
const
float
PI
=
3
.
1416f
;
/*
*Diode -> in -1V / +1V *
*/
struct
Diode
{
float
phase_in, phase_out =
0
.
0f
;
dsp::Upsampler<
4
,
16
> Upsample;
dsp::Decimator<
4
,
16
> Decimate;
float
Ov_Buffer[
16
] = {
0
};
dsp::RCFilter filter1;
std::string plug_directory = asset::plugin(pluginInstance,
"
res/waves2/
"
);
float
wave[
64
][
256
]={{
0
.
0f
}};
const
std::string wavefiles[
64
]={
"
00.wav
"
,
"
01.wav
"
,
"
02.wav
"
,
"
03.wav
"
,
"
04.wav
"
,
"
05.wav
"
,
"
06.wav
"
,
"
07.wav
"
,
"
08.wav
"
,
"
09.wav
"
,
"
10.wav
"
,
"
11.wav
"
,
"
12.wav
"
,
"
13.wav
"
,
"
14.wav
"
,
"
15.wav
"
,
"
16.wav
"
,
"
17.wav
"
,
"
18.wav
"
,
"
19.wav
"
,
"
20.wav
"
,
"
21.wav
"
,
"
22.wav
"
,
"
23.wav
"
,
"
24.wav
"
,
"
25.wav
"
,
"
26.wav
"
,
"
27.wav
"
,
"
28.wav
"
,
"
29.wav
"
,
"
30.wav
"
,
"
31.wav
"
,
"
32.wav
"
,
"
33.wav
"
,
"
34.wav
"
,
"
35.wav
"
,
"
36.wav
"
,
"
37.wav
"
,
"
38.wav
"
,
"
39.wav
"
,
"
40.wav
"
,
"
41.wav
"
,
"
42.wav
"
,
"
43.wav
"
,
"
44.wav
"
,
"
45.wav
"
,
"
46.wav
"
,
"
47.wav
"
,
"
48.wav
"
,
"
49.wav
"
,
"
50.wav
"
,
"
51.wav
"
,
"
52.wav
"
,
"
53.wav
"
,
"
54.wav
"
,
"
55.wav
"
,
"
56.wav
"
,
"
57.wav
"
,
"
58.wav
"
,
"
59.wav
"
,
"
60.wav
"
,
"
61.wav
"
,
"
62.wav
"
,
"
63.wav
"
};
short
temp_buf[
256
]={
0
};
bool
tab_loaded =
false
;
float
out =
0
.
0f
;
float
faded_type =
0
.
0f
;
bool
first_alg =
true
;
float
l_type =
0
;
float
buf_in[
BLOCK_SIZE
]={
0
.
0f
};
float
buf_out[
BLOCK_SIZE
]={
0
.
0f
};
dsp::RealTimeConvolver *convolver =
NULL
;
Diode
(){
LoadWaves
();
}
~Diode
(){
}
void
LoadWaves
(){
for
(
int
j=
0
; j<
64
; j++){
std::string file_name = plug_directory+wavefiles[j];
const
char
*chemin = file_name.
c_str
();
unsigned
int
channels;
unsigned
int
sampleRate;
drwav_uint64 totalPCMFrameCount;
float
* pSampleData =
drwav_open_file_and_read_pcm_frames_f32
(chemin, &channels, &sampleRate, &totalPCMFrameCount);
for
(
int
i =
0
; i<
256
; i++){
wave[j][i] = pSampleData[i]/
2
.
0f
;
}
drwav_free
(pSampleData);;
}
tab_loaded =
true
;
}
float
proc_f_d1
(
float
in,
float
gain,
float
type,
float
feedback){
if
(!first_alg){
//
gain = (gain+1);
if
(tab_loaded ==
false
){
LoadWaves
();
}
/*
in=(in-(feedback*(gain/8.0f)));
Upsample.process(in,Ov_Buffer);
filter1.setCutoff((44100 *engineGetSampleTime()/4));
float index= 0.0f;
for(int i = 0 ; i< 4 ; i++){
if(Ov_Buffer[i]>=0)
phase_in=1.0f;
if(Ov_Buffer[i]<0)
phase_in= -1.0f;
Ov_Buffer[i] = abs(Ov_Buffer[i]*gain);
index = Ov_Buffer[i]*16;
while(index>255){
index-=255;
}
while(index<0){
index+=255;
}
Ov_Buffer[i] *= 1- ((clamp((gain-1),0.0f,8.0f)*0.2)*(interpolateLinear(wave[(int)type],index)+0.5f));
Ov_Buffer[i] = Ov_Buffer[i]*phase_in;
filter1.process(Ov_Buffer[i]);
Ov_Buffer[i]=filter1.lowpass();
}
in=Decimate.process(Ov_Buffer);
*/
float
sin_in =
sin
(
PI
*in);
int
index = in*
255
;
float
cos_wave =
cos
(
PI
*(gain*wave[(
int
)type][index]));
out = sin_in * cos_wave;
//
float out = clamp(out,-1.0f,1.0f);
return
out ;
}
else
{
if
(tab_loaded ==
false
){
LoadWaves
();
}
float
dif_type = type - faded_type;
if
(dif_type>
0
){
type +=
std::min
(dif_type,
0
.
01f
);
}
if
(dif_type<
0
){
type +=
std::max
(dif_type,-
0
.
01f
);
}
in=(in-(feedback*(gain/
8
.
0f
)));
Upsample.
process
(in,Ov_Buffer);
filter1.
setCutoff
((
44100
* (
APP
->
engine
->
getSampleTime
())));
float
index =
0
.
0f
;
type =
clamp
(type,
0
.
00f
,
14
.
99f
);
//
OVRS
for
(
int
i =
0
; i<
4
; i++){
if
(Ov_Buffer[i]<
0
)
phase_in = -
1
.
0f
;
else
phase_in =
1
.
0f
;
Ov_Buffer[i] =
abs
(Ov_Buffer[i]);
index =
tanh
(Ov_Buffer[i])*
255
;
//
*clamp(((gain/4.0f)-1.0f),0.0f,2.0f);
index=
255
.
0f
-index*
2
;
index =
abs
(index);
clamp
(index,
0
.
01f
,
255
.
0f
);
float
coef1f, coef2f =
0
.
0f
;
float
interp_l =
0
.
0f
;
if
( (
int
)type > type ){
coef1f = (
int
) type - type;
coef2f =
1
- coef1f;
}
else
{
coef2f = type - (
int
) type;
coef1f =
1
- coef2f;
}
interp_l+=
interpolateLinear
(wave[(
int
)type],index)*coef1f;
interp_l+=
interpolateLinear
(wave[(
int
)type+
1
],index)*coef2f;
Ov_Buffer[i] *=
1
- ((
clamp
((gain-
1
),
0
.
0f
,
8
.
0f
)*
0.2
)*(interp_l+
0
.
5f
));
Ov_Buffer[i] *= (gain*
2
.
0f
);
//
Ov_Buffer[i] = tanh(Ov_Buffer[i]);
if
(phase_in>
0
.
0f
)
Ov_Buffer[i] = phase_in*Ov_Buffer[i];
else
Ov_Buffer[i] = phase_in*(Ov_Buffer[i]);
filter1.
process
(Ov_Buffer[i]);
Ov_Buffer[i]=filter1.
lowpass
();
}
in=Decimate.
process
(Ov_Buffer);
//
*phase_in;
out =
tanh
(in);
return
out ;
}
}
};
struct
K_Rush
: Module {
enum
ParamIds {
TRIM_PARAM
,
MIX_PARAM
,
FEEDBACK_PARAM
,
GAIN_PARAM
,
WAVET_PARAM
,
CV_GAIN_PARAM
,
CV_FEEDBACK_PARAM
,
NUM_PARAMS
};
enum
InputIds {
TYPE_INPUT
,
CV_GAIN_INPUT
,
IN_INPUT
,
CV_FEEDBACK_INPUT
,
FEEDBACK_INPUT
,
NUM_INPUTS
};
enum
OutputIds {
OUT_OUTPUT
,
FEEDBACK_OUTPUT
,
NUM_OUTPUTS
};
enum
LightIds {
NUM_LIGHTS
};
float
feed_back =
0
.
0f
;
/*
****************
const float m_thermalVoltage = 0.025864f;
const float m_saturationCurrent = 10e-17f;
float m_resistor = 15000.f;
float m_loadResistor = 7500.f;
float m_loadResistor2 = m_loadResistor * 2.f;
// Derived values
float m_alpha = m_loadResistor2 / m_resistor;
float m_beta = (m_resistor + m_loadResistor2) / (m_thermalVoltage * m_resistor);
float m_delta = (m_loadResistor * m_saturationCurrent) / m_thermalVoltage;
******************
*/
Diode d_pos,d_neg;
K_Rush
() {
config
(
NUM_PARAMS
,
NUM_INPUTS
,
NUM_OUTPUTS
,
NUM_LIGHTS
);
configParam
(
TRIM_PARAM
, -
4
.
0f
,
4
.
0f
,
1
.
0f
);
configParam
(
WAVET_PARAM
,
0
.
0f
,
15
.
0f
,
0
.
0f
);
configParam
(
MIX_PARAM
,
0
.
0f
,
1
.
0f
,
1
.
0f
);
configParam
(
GAIN_PARAM
,
0
.
0f
,
8
.
0f
,
1
.
0f
);
configParam
(
FEEDBACK_PARAM
,
0
.
0f
,
1
.
0f
,
0
.
0f
);
configParam
(
CV_GAIN_PARAM
, -
1
.
0f
,
1
.
0f
,
0
.
0f
);
configParam
(
CV_FEEDBACK_PARAM
,
0
.
0f
,
0
.
3f
,
0
.
0f
);
}
void
process
(
const
ProcessArgs &args)
override
;
//
For more advanced Module features, read Rack's engine.hpp header file
//
- toJson, fromJson: serialization of internal data
//
- onSampleRateChange: event triggered by a change of sample rate
//
- onReset, onRandomize, onCreate, onDelete: implements special behavior when user clicks these from the context menu
json_t
*
dataToJson
()
override
{
json_t
*rootJ =
json_object
();
json_object_set_new
(rootJ,
"
first_alg
"
,
json_integer
(d_pos.
first_alg
));
return
rootJ;
}
void
dataFromJson
(
json_t
*rootJ)
override
{
json_t
*first_algJ =
json_object_get
(rootJ,
"
first_alg
"
);
if
(d_pos.
first_alg
)
d_pos.
first_alg
=
json_integer_value
(first_algJ);
}
};
void
K_Rush::process
(
const
ProcessArgs &args) {
float
gain = params[
GAIN_PARAM
].
getValue
();
float
feed_back =
clamp
((params[
FEEDBACK_PARAM
].
getValue
() + (params[
CV_FEEDBACK_PARAM
].
getValue
()*inputs[
CV_FEEDBACK_INPUT
].
getVoltageSum
())),
0
.
0f
,
1
.
0f
)*(inputs[
FEEDBACK_INPUT
].
getVoltage
()/
5
.
0f
);
//
float in = (inputs[IN_INPUT].value/5.0f)-((inputs[FEEDBACK_INPUT].value/5.0f)/clamp(16/gain,1.0f,16.0f) *feed_back);
float
in = (inputs[
IN_INPUT
].
getVoltageSum
()/
5.0
)*params[
TRIM_PARAM
].
getValue
();
if
(inputs[
CV_GAIN_INPUT
].
active
)
gain += (inputs[
CV_GAIN_INPUT
].
getVoltageSum
()*params[
CV_GAIN_PARAM
].
getValue
());
gain =
clamp
(gain,
0
.
0f
,
8
.
0f
);
float
type_diode = params[
WAVET_PARAM
].
getValue
()+(inputs[
TYPE_INPUT
].
getVoltage
() *
2
.
0f
);
in = d_pos.
proc_f_d1
(in ,gain,type_diode,feed_back);
outputs[
OUT_OUTPUT
].
setVoltage
((params[
MIX_PARAM
].
getValue
()*in*
5
)+((
1
-params[
MIX_PARAM
].
getValue
())*inputs[
IN_INPUT
].
getVoltageSum
()));
outputs[
FEEDBACK_OUTPUT
].
setVoltage
(in*
5
);
}
struct
K_RushWidget
: ModuleWidget {
//
Menu *createContextMenu();
K_RushWidget
(K_Rush *
module
){
setModule
(
module
);
setPanel
(
APP
->
window
->
loadSvg
(
asset::plugin
(pluginInstance,
"
res/K_Rush.svg
"
)));
//
addParam(createParamWidget<RoundSmallBlackKnob>(Vec(15.2, 85.5), module, K_Rush::TRIM_PARAM, -4.0f, 4.0f, 1.0f));
addParam
(createParam<RoundSmallBlackKnob>(
Vec
(
15.2
,
85.5
),
module
, K_Rush::
TRIM_PARAM
));
addParam
(createParam<RoundBlackKnob>(
Vec
(
60.5
,
82.8
),
module
, K_Rush::
WAVET_PARAM
));
addParam
(createParam<RoundSmallBlackKnob>(
Vec
(
110.9
,
85.5
),
module
, K_Rush::
MIX_PARAM
));
addParam
(createParam<RoundLargeBlackKnob>(
Vec
(
12.2
,
158.7
),
module
, K_Rush::
GAIN_PARAM
));
addParam
(createParam<RoundLargeBlackKnob>(
Vec
(
100
,
256.7
),
module
, K_Rush::
FEEDBACK_PARAM
));
addParam
(createParam<RoundSmallBlackKnob>(
Vec
(
106.9
,
165.7
),
module
, K_Rush::
CV_GAIN_PARAM
));
addParam
(createParam<RoundSmallBlackKnob>(
Vec
(
19.3
,
263.8
),
module
, K_Rush::
CV_FEEDBACK_PARAM
));
addInput
(createInput<PJ301MPort>(
Vec
(
62.3
,
125
),
module
, K_Rush::
TYPE_INPUT
));
addInput
(createInput<PJ301MPort>(
Vec
(
62.3
,
205
),
module
, K_Rush::
CV_GAIN_INPUT
));
addInput
(createInput<PJ301MPort>(
Vec
(
62.3
,
302.6
),
module
, K_Rush::
CV_FEEDBACK_INPUT
));
addInput
(createInput<PJ301MPort>(
Vec
(
9.3
,
345
),
module
, K_Rush::
FEEDBACK_INPUT
));
addInput
(createInput<PJ301MPort>(
Vec
(
62.3
,
345
),
module
, K_Rush::
IN_INPUT
));
addOutput
(createOutput<PJ301MPort>(
Vec
(
115.3
,
345
),
module
, K_Rush::
OUT_OUTPUT
));
}
struct
AlgoSelecItem
: MenuItem {
K_Rush *pt_kr;
void
onAction
(
const
event::Action &e)
override
{
pt_kr->
d_pos
.
first_alg
=
true
;
}
void
step
()
override
{
rightText = (pt_kr->
d_pos
.
first_alg
==
true
) ?
"
✔
"
:
"
"
;
MenuItem::step
();
}
};
struct
AlgoSelecItem2
: MenuItem {
K_Rush *pt_kr;
void
onAction
(
const
event::Action &e)
override
{
pt_kr->
d_pos
.
first_alg
=
false
;
}
void
step
()
override
{
rightText = (pt_kr->
d_pos
.
first_alg
==
false
) ?
"
✔
"
:
"
"
;
MenuItem::step
();
}
};
void
appendContextMenu
(Menu *menu)
override
{
K_Rush *pt_kr =
dynamic_cast
<K_Rush*>(
module
);
//
assert(pt_kr);
if
( pt_kr){
menu->
addChild
(construct<MenuEntry>());
//
menu->addChild(construct<MenuLabel>(&MenuLabel::text, "Not so blank panels"));
menu->
addChild
(construct<AlgoSelecItem>(&AlgoSelecItem::text,
"
1rst Algo
"
,&AlgoSelecItem::pt_kr,pt_kr));
menu->
addChild
(construct<AlgoSelecItem2>(&AlgoSelecItem2::text,
"
2nd Algo
"
,&AlgoSelecItem2::pt_kr,pt_kr));
}
}
};
Model *modelK_Rush = createModel<K_Rush, K_RushWidget>(
"
K_Rush
"
);
Back
|
FazBrowse Home
|
New Git URL