@@ -282,8 +282,9 @@ class Tremolo : public AudioEffect {
282
282
class Delay : public AudioEffect {
283
283
public:
284
284
// / e.g. depthPercent=50, ms=1000, sampleRate=44100
285
- Delay (uint16_t duration_ms=1000 , float depthPercent=50 , uint32_t sampleRate=44100 ) {
285
+ Delay (uint16_t duration_ms=1000 , float depthPercent=50 , float feedbackAmount= 0.3 , uint32_t sampleRate=44100 ) {
286
286
this ->sampleRate = sampleRate;
287
+ p_feedback = feedbackAmount;
287
288
p_percent = depthPercent;
288
289
p_ms = duration_ms;
289
290
}
@@ -306,16 +307,26 @@ class Delay : public AudioEffect {
306
307
return p_percent;
307
308
}
308
309
310
+ void setFeedback (float feedback){
311
+ p_feedback = feedback;
312
+ }
313
+
314
+ uint8_t feedback () {
315
+ return p_feedback;
316
+ }
317
+
309
318
effect_t process (effect_t input) {
310
319
if (!active ()) return input;
311
320
312
321
updateBufferSize ();
313
322
// get value from buffer
314
323
int32_t value = (p_history->available ()<sampleCount) ? input : p_history->read ();
315
- // add actual input value
316
- p_history->write (input);
324
+ // add feedback decay
325
+ int32_t delayValue = (value*p_feedback);
326
+ // add input and delay to the buffer
327
+ p_history->write (input+delayValue);
317
328
// mix input with result
318
- return (value * p_percent) + (input * (1.0 - p_percent));
329
+ return (delayValue * p_percent) + (input * (1.0 - p_percent));
319
330
}
320
331
321
332
Delay *clone () {
@@ -325,6 +336,7 @@ class Delay : public AudioEffect {
325
336
protected:
326
337
RingBuffer<effect_t >* p_history=nullptr ;
327
338
float p_percent;
339
+ float p_feedback;
328
340
uint16_t p_ms;
329
341
uint16_t sampleCount=0 ;
330
342
uint32_t sampleRate;
0 commit comments