1
1
#include " dcb.h"
2
2
#include " rnd.h"
3
3
4
+ struct UniH {
5
+ float val[16 ]={};
6
+ void next (RND &rnd,bool bi,int chn) {
7
+ val[chn]=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
8
+ }
9
+ float get (int chn) {
10
+ return val[chn];
11
+ }
12
+ };
13
+
14
+ struct MinH {
15
+ float val[16 ]={};
16
+ void next (RND &rnd,bool bi,int chn,float strength) {
17
+ if (strength==1 .f ) {
18
+ val[chn]=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
19
+ } else {
20
+ double outm=rnd.nextMin ((int )strength);
21
+ if (bi) {
22
+ val[chn]=rnd.nextCoin ()?(float )outm*5 .f :(float )-outm*5 .f ;
23
+ } else {
24
+ val[chn]=(float )outm*10 .f ;
25
+ }
26
+ }
27
+ }
28
+ float get (int chn) {
29
+ return val[chn];
30
+ }
31
+ };
32
+
33
+ struct WBH {
34
+ float val[16 ]={};
35
+ void next (RND &rnd,bool bi,int chn,float strength) {
36
+ if (strength==1 .f ) {
37
+ val[chn]=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
38
+ } else {
39
+ double outw=rnd.nextWeibull (strength);
40
+ if (bi) {
41
+ val[chn]=rnd.nextCoin ()?(float )outw*5 .f :(float )-outw*5 .f ;
42
+ } else {
43
+ val[chn]=(float )outw*10 .f ;
44
+ }
45
+ }
46
+ }
47
+ float get (int chn) {
48
+ return val[chn];
49
+ }
50
+ };
51
+
52
+ struct TriH {
53
+ float val[16 ]={};
54
+ void next (RND &rnd,bool bi,int chn,float strength) {
55
+ if (strength==1 .f ) {
56
+ val[chn]=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
57
+ } else {
58
+ double outt=rnd.nextTri ((int )strength);
59
+ val[chn]=(float )outt*10 .f -(bi?5 .f :0 .f );
60
+ }
61
+ }
62
+ float get (int chn) {
63
+ return val[chn];
64
+ }
65
+ };
66
+
67
+
4
68
struct RndH2 : Module {
5
69
enum ParamIds {
6
- BI_PARAM,STRENGTH_PARAM,CHANNELS_PARAM,SEED_PARAM,RANGE_PARAM,RANGE_CV_PARAM,OFFSET_PARAM,OFFSET_CV_PARAM,NUM_PARAMS
70
+ BI_PARAM,STRENGTH_PARAM,CHANNELS_PARAM,SEED_PARAM,RANGE_PARAM,RANGE_CV_PARAM,OFFSET_PARAM,OFFSET_CV_PARAM,SLEW_PARAM, NUM_PARAMS
7
71
};
8
72
enum InputIds {
9
73
CLOCK_INPUT,RST_INPUT,SEED_INPUT,STRENGTH_INPUT,RANGE_INPUT,OFFSET_INPUT,NUM_INPUTS
@@ -17,7 +81,14 @@ struct RndH2 : Module {
17
81
RND rnd;
18
82
dsp::SchmittTrigger clockTrigger[16 ];
19
83
dsp::SchmittTrigger rstTrigger;
20
-
84
+ dsp::SlewLimiter slewLimiterUni[16 ];
85
+ dsp::SlewLimiter slewLimiterWB[16 ];
86
+ dsp::SlewLimiter slewLimiterTri[16 ];
87
+ dsp::SlewLimiter slewLimiterMin[16 ];
88
+ UniH uniH;
89
+ WBH wbH;
90
+ MinH minH;
91
+ TriH triH;
21
92
RndH2 () {
22
93
config (NUM_PARAMS,NUM_INPUTS,NUM_OUTPUTS,NUM_LIGHTS);
23
94
configInput (SEED_INPUT," SEED" );
@@ -29,8 +100,9 @@ struct RndH2 : Module {
29
100
configParam (OFFSET_CV_PARAM,0 .f ,1 .f ,0 .f ," Offset CV" );
30
101
configParam (BI_PARAM,0 .f ,1 .f ,1 .f ," BI-Polar" );
31
102
configParam (STRENGTH_PARAM,1 .f ,20 .f ,1 .f ," Strength" );
32
- configParam (CHANNELS_PARAM,1 .f ,16 .f ,8 .f ," Polyphonic Channels" );
103
+ configParam (CHANNELS_PARAM,1 .f ,16 .f ,1 .f ," Polyphonic Channels" );
33
104
configParam (SEED_PARAM,0 ,1 ,0 ," Random Seed" );
105
+ configParam (SLEW_PARAM,0 .0f ,1 .f ,0 .f ," Slew" );
34
106
configInput (SEED_INPUT," Random Seed" );
35
107
configInput (CLOCK_INPUT," Clock" );
36
108
configInput (RST_INPUT," Reset" );
@@ -57,67 +129,21 @@ struct RndH2 : Module {
57
129
return f*range+offset;
58
130
}
59
131
60
- void nextMin (float strength,bool bi,int chn) {
61
- if (strength==1 .f ) {
62
- auto out=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
63
- outputs[MIN_OUTPUT].setVoltage (modify (out,chn),chn);
64
- } else {
65
- double outm=rnd.nextMin ((int )strength);
66
- if (bi) {
67
- float out=rnd.nextCoin ()?(float )outm*5 .f :(float )-outm*5 .f ;
68
- outputs[MIN_OUTPUT].setVoltage (modify (out,chn),chn);
69
- } else {
70
- outputs[MIN_OUTPUT].setVoltage (modify ((float )outm*10 .f ,chn),chn);
71
- }
72
- }
73
- }
74
-
75
- void nextWB (float strength,bool bi,int chn) {
76
- if (strength==1 .f ) {
77
- auto out=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
78
- outputs[WB_OUTPUT].setVoltage (modify (out,chn),chn);
79
- } else {
80
- double outw=rnd.nextWeibull (strength);
81
- if (bi) {
82
- auto out=rnd.nextCoin ()?(float )outw*5 .f :(float )-outw*5 .f ;
83
- outputs[WB_OUTPUT].setVoltage (modify (out,chn),chn);
84
- } else {
85
- outputs[WB_OUTPUT].setVoltage (modify ((float )outw*10 .f ,chn),chn);
86
- }
87
- }
88
- }
89
-
90
- void nextTri (float strength,bool bi,int chn) {
91
- if (strength==1 .f ) {
92
- auto out=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
93
- outputs[TRI_OUTPUT].setVoltage (modify (out,chn),chn);
94
- } else {
95
- double outt=rnd.nextTri ((int )strength);
96
- auto out=(float )outt*10 .f -(bi?5 .f :0 .f );
97
- outputs[TRI_OUTPUT].setVoltage (modify (out,chn),chn);
98
- }
99
- }
100
-
101
- void nextUni (bool bi,int chn) {
102
- auto out=float (rnd.nextDouble ()*10 -(bi?5 :0 ));
103
- outputs[UNI_OUTPUT].setVoltage (modify (out,chn),chn);
104
- }
105
-
106
132
void next (int chn,bool bi=false ) {
107
133
float strength=params[STRENGTH_PARAM].getValue ();
108
134
strength=clamp (inputs[STRENGTH_INPUT].getNormalPolyVoltage (strength*.5f ,chn)*2 .f ,1 .f ,20 .f );
109
135
if (outputs[MIN_OUTPUT].isConnected ())
110
- nextMin (strength ,bi,chn);
136
+ minH. next (rnd ,bi,chn,strength );
111
137
if (outputs[WB_OUTPUT].isConnected ())
112
- nextWB (strength ,bi,chn);
138
+ wbH. next (rnd ,bi,chn,strength );
113
139
if (outputs[TRI_OUTPUT].isConnected ())
114
- nextTri (strength ,bi,chn);
140
+ triH. next (rnd ,bi,chn,strength );
115
141
if (outputs[UNI_OUTPUT].isConnected ())
116
- nextUni ( bi,chn);
142
+ uniH. next (rnd, bi,chn);
117
143
}
118
144
119
-
120
145
void process (const ProcessArgs &args) override {
146
+ float slew=(params[SLEW_PARAM].getValue ()+0 .001f )*1000 ;
121
147
float bi=params[BI_PARAM].getValue ();
122
148
int channels=params[CHANNELS_PARAM].getValue ();
123
149
bool channelParam=false ;
@@ -130,14 +156,20 @@ struct RndH2 : Module {
130
156
channelParam=true ;
131
157
}
132
158
}
159
+ for (int c=0 ;c<channels;c++) {
160
+ slewLimiterUni[c].setRiseFall (1 /slew,1 /slew);
161
+ slewLimiterWB[c].setRiseFall (1 /slew,1 /slew);
162
+ slewLimiterTri[c].setRiseFall (1 /slew,1 /slew);
163
+ slewLimiterMin[c].setRiseFall (1 /slew,1 /slew);
164
+ }
133
165
if (rstTrigger.process (inputs[RST_INPUT].getVoltage ())) {
134
166
if (inputs[SEED_INPUT].isConnected ()) {
135
167
getParamQuantity (SEED_PARAM)->setValue (inputs[SEED_INPUT].getVoltage ()*0.1 );
136
168
}
137
169
float seedParam=params[SEED_PARAM].getValue ();
138
170
seedParam=floorf (seedParam*10000 )/10000 ;
139
171
auto seedInput=(unsigned long long )(floor ((double )seedParam*(double )ULONG_MAX));
140
- INFO (" %.8f %lld" ,seedParam,seedInput);
172
+ // INFO("%.8f %lld",seedParam,seedInput);
141
173
rnd.reset (seedInput);
142
174
for (int c=0 ;c<channels;c++) {
143
175
next (c,bi>0 .f );
@@ -157,9 +189,28 @@ struct RndH2 : Module {
157
189
}
158
190
}
159
191
}
192
+ for (int c=0 ;c<channels;c++) {
193
+ if (outputs[UNI_OUTPUT].isConnected ())
194
+ outputs[UNI_OUTPUT].setVoltage (slewLimiterUni[c].process (1 .f ,modify (uniH.get (c),c)),c);
195
+ if (outputs[MIN_OUTPUT].isConnected ())
196
+ outputs[MIN_OUTPUT].setVoltage (slewLimiterMin[c].process (1 .f ,modify (minH.get (c),c)),c);
197
+ if (outputs[WB_OUTPUT].isConnected ())
198
+ outputs[WB_OUTPUT].setVoltage (slewLimiterWB[c].process (1 .f ,modify (wbH.get (c),c)),c);
199
+ if (outputs[TRI_OUTPUT].isConnected ())
200
+ outputs[TRI_OUTPUT].setVoltage (slewLimiterTri[c].process (1 .f ,modify (triH.get (c),c)),c);
201
+ }
160
202
} else {
161
- for (int k=0 ;k<channels;k++)
162
- next (k,true );
203
+ for (int c=0 ;c<channels;c++) {
204
+ next (c,true );
205
+ if (outputs[UNI_OUTPUT].isConnected ())
206
+ outputs[UNI_OUTPUT].setVoltage (uniH.get (c),c);
207
+ if (outputs[MIN_OUTPUT].isConnected ())
208
+ outputs[MIN_OUTPUT].setVoltage (minH.get (c),c);
209
+ if (outputs[WB_OUTPUT].isConnected ())
210
+ outputs[WB_OUTPUT].setVoltage (wbH.get (c),c);
211
+ if (outputs[TRI_OUTPUT].isConnected ())
212
+ outputs[TRI_OUTPUT].setVoltage (triH.get (c),c);
213
+ }
163
214
}
164
215
165
216
@@ -193,11 +244,11 @@ struct RndH2Widget : ModuleWidget {
193
244
y+=12 ;
194
245
addParam (createParam<TrimbotWhite>(mm2px (Vec (x,y)),module,RndH2::STRENGTH_PARAM));
195
246
addInput (createInput<SmallPort>(mm2px (Vec (x1,y)),module,RndH2::STRENGTH_INPUT));
196
- y+=12 ;
247
+ y+=9 ;
197
248
auto biPolarButton=createParam<SmallButtonWithLabel>(mm2px (Vec (6.8 ,y)),module,RndH2::BI_PARAM);
198
249
biPolarButton->setLabel (" BiP" );
199
250
addParam (biPolarButton);
200
- y=66 ;
251
+ y=64 ;
201
252
addParam (createParam<TrimbotWhite>(mm2px (Vec (x,y)),module,RndH2::RANGE_PARAM));
202
253
addParam (createParam<TrimbotWhite>(mm2px (Vec (x1,y)),module,RndH2::OFFSET_PARAM));
203
254
y+=8 ;
@@ -206,6 +257,8 @@ struct RndH2Widget : ModuleWidget {
206
257
y+=8 ;
207
258
addParam (createParam<TrimbotWhite>(mm2px (Vec (x,y)),module,RndH2::RANGE_CV_PARAM));
208
259
addParam (createParam<TrimbotWhite>(mm2px (Vec (x1,y)),module,RndH2::OFFSET_CV_PARAM));
260
+ y=92 ;
261
+ addParam (createParam<TrimbotWhite>(mm2px (Vec (6.9 ,y)),module,RndH2::SLEW_PARAM));
209
262
210
263
y=104 ;
211
264
addOutput (createOutput<SmallPort>(mm2px (Vec (x,y)),module,RndH2::WB_OUTPUT));
0 commit comments