@@ -63,7 +63,7 @@ template <typename SRProvider, int BLOCK_SIZE> struct SimpleLFO
63
63
for (int i = 0 ; i < BLOCK_SIZE; ++i)
64
64
outputBlock[i] = 0 ;
65
65
66
- restartRandomSequence ();
66
+ restartRandomSequence (0 . f );
67
67
}
68
68
69
69
// Move towards this so we can remove the rng member above
@@ -76,7 +76,7 @@ template <typename SRProvider, int BLOCK_SIZE> struct SimpleLFO
76
76
for (int i = 0 ; i < BLOCK_SIZE; ++i)
77
77
outputBlock[i] = 0 ;
78
78
79
- restartRandomSequence ();
79
+ restartRandomSequence (0 . f );
80
80
}
81
81
82
82
enum Shape
@@ -95,14 +95,31 @@ template <typename SRProvider, int BLOCK_SIZE> struct SimpleLFO
95
95
float outputBlock[BLOCK_SIZE];
96
96
float phase{0 };
97
97
98
- inline void restartRandomSequence ()
98
+ inline void restartRandomSequence (double corr )
99
99
{
100
100
rngState[0 ] = urng ();
101
101
rngState[1 ] = urng ();
102
- for (int i = 0 ; i < 4 ; ++i)
102
+ // We have to restart and make sure the correlation filter works so do two things
103
+ // First, warm it up with a quick blast. Second, if it does produce out of bound value
104
+ // then try again.
105
+ for (auto i = 0 ; i < 50 ; ++i)
103
106
{
104
- rngCurrent = dsp::correlated_noise_o2mk2_suppliedrng (rngState[0 ], rngState[1 ], 0 , urng);
105
- rngHistory[3 - i] = rngCurrent;
107
+ rngCurrent =
108
+ dsp::correlated_noise_o2mk2_suppliedrng (rngState[0 ], rngState[1 ], corr, urng);
109
+ }
110
+ int its{0 };
111
+ bool allGood{false };
112
+ while (its < 20 && !allGood)
113
+ {
114
+ allGood = true ;
115
+ for (int i = 0 ; i < 4 ; ++i)
116
+ {
117
+ rngCurrent =
118
+ dsp::correlated_noise_o2mk2_suppliedrng (rngState[0 ], rngState[1 ], corr, urng);
119
+ rngHistory[3 - i] = rngCurrent;
120
+ allGood = allGood && rngHistory[3 - i] > -1 && rngHistory[3 - i] < 1 ;
121
+ }
122
+ its++;
106
123
}
107
124
}
108
125
@@ -137,6 +154,7 @@ template <typename SRProvider, int BLOCK_SIZE> struct SimpleLFO
137
154
amplitude = 1 ;
138
155
}
139
156
157
+ bool needsRandomRestart{false };
140
158
inline void attack (const int lshape)
141
159
{
142
160
phase = 0 ;
@@ -146,7 +164,8 @@ template <typename SRProvider, int BLOCK_SIZE> struct SimpleLFO
146
164
147
165
if (lshape == SH_NOISE || lshape == SMOOTH_NOISE)
148
166
{
149
- restartRandomSequence ();
167
+ needsRandomRestart = true ;
168
+ phase = 1.000001 ;
150
169
}
151
170
}
152
171
@@ -190,6 +209,11 @@ template <typename SRProvider, int BLOCK_SIZE> struct SimpleLFO
190
209
{
191
210
// The deform can push correlated noise out of bounds
192
211
auto ud = d * 0.8 ;
212
+ if (needsRandomRestart)
213
+ {
214
+ restartRandomSequence (ud);
215
+ needsRandomRestart = false ;
216
+ }
193
217
rngCurrent =
194
218
dsp::correlated_noise_o2mk2_suppliedrng (rngState[0 ], rngState[1 ], ud, urng);
195
219
0 commit comments