@@ -127,19 +127,20 @@ class Fuzz : public AudioEffect {
127
127
128
128
class Tremolo : public AudioEffect {
129
129
public:
130
- // / Tremolo constructor - use e.g. duration_ms=2000; depth=0.5 ; sampleRate=44100
131
- Tremolo (int16_t &duration_ms, float &depth, uint16_t sampleRate=44100 ) {
132
- int32_t rate_count = static_cast < int32_t >(duration_ms) * sampleRate / 1000 ;
130
+ // / Tremolo constructor - use e.g. duration_ms=2000; depthPercent=50 ; sampleRate=44100
131
+ Tremolo (int16_t &duration_ms, uint8_t & depthPercent, uint32_t sampleRate=44100 ) {
132
+ int32_t rate_count = sampleRate * duration_ms / 1000 ;
133
133
rate_count_half = rate_count / 2 ;
134
-
135
- // limit value to max 1.0
136
- tremolo_depth = depth>1.0 ? 1.0 : depth;
137
- signal_depth = 1.0 - depth;
134
+ p_percent = &depthPercent;
138
135
}
139
136
140
137
effect_t process (effect_t input) {
141
138
if (!active ()) return input;
142
139
140
+ // limit value to max 100% and calculate factors
141
+ float tremolo_depth = (*p_percent) > 100 ? 1.0 : 0.01 * (*p_percent);
142
+ float signal_depth = (100.0 - (*p_percent)) / 100.0 ;
143
+
143
144
float tremolo_factor = tremolo_depth / rate_count_half;
144
145
int32_t out = (signal_depth * input) + (tremolo_factor * count * input);
145
146
@@ -159,9 +160,7 @@ class Tremolo : public AudioEffect {
159
160
int32_t count = 0 ;
160
161
int16_t inc = 1 ;
161
162
int32_t rate_count_half; // number of samples for on raise and fall
162
- float tremolo_depth;
163
- float signal_depth;
164
- float tremolo_factor ;
163
+ uint8_t * p_percent;
165
164
166
165
};
167
166
@@ -172,16 +171,17 @@ class Tremolo : public AudioEffect {
172
171
*/
173
172
class Delay : public AudioEffect {
174
173
public:
175
- // / e.g. percent =50, ms=1000, sampleRate=44100
176
- Delay (uint8_t & percent, uint16_t &ms, uint32_t sampleRate=44100 ) {
174
+ // / e.g. depthPercent =50, ms=1000, sampleRate=44100
175
+ Delay (uint16_t &duration_ms, uint8_t & depthPercent, uint32_t sampleRate=44100 ) {
177
176
this ->sampleRate = sampleRate;
178
- p_percent = &percent;
179
- p_ms = &ms;
180
- sampleCount = sampleRate * ms / 1000 ;
181
- p_history = new RingBuffer<effect_t >(sampleCount);
177
+ this ->sampleCount = sampleRate * duration_ms / 1000 ;
178
+ p_percent = &depthPercent;
179
+ p_ms = &duration_ms;
182
180
}
183
181
184
182
effect_t process (effect_t input) {
183
+ if (!active ()) return input;
184
+
185
185
updateBufferSize ();
186
186
// get value from buffer
187
187
int32_t value = (p_history->available ()<sampleCount) ? input : p_history->read ();
@@ -195,13 +195,13 @@ class Delay : public AudioEffect {
195
195
RingBuffer<effect_t >* p_history=nullptr ;
196
196
uint8_t * p_percent;
197
197
uint16_t *p_ms;
198
- uint16_t sampleCount;
198
+ uint16_t sampleCount= 0 ;
199
199
uint32_t sampleRate;
200
200
201
201
void updateBufferSize (){
202
202
uint16_t newSampleCount = sampleRate * (*p_ms) / 1000 ;
203
203
if (newSampleCount>sampleCount){
204
- delete p_history;
204
+ if (p_history!= nullptr ) delete p_history;
205
205
sampleCount = newSampleCount;
206
206
p_history = new RingBuffer<effect_t >(sampleCount);
207
207
}
0 commit comments