@@ -282,51 +282,64 @@ 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 , float feedbackAmount=0.3 , uint32_t sampleRate=44100 ) {
286
- this ->sampleRate = sampleRate;
287
- p_feedback = feedbackAmount;
288
- p_percent = depthPercent;
289
- p_ms = duration_ms;
285
+ Delay (uint16_t duration_ms=1000 , float depthPercent=0.3 , float feedbackAmount=0.3 , uint32_t sampleRate=44100 ) {
286
+ delayLine = new DelayLine (duration_ms,depthPercent,feedbackAmount,sampleRate);
290
287
}
291
288
292
- Delay (const Delay ©) = default ;
289
+ Delay (const Delay &ref) {
290
+ delayLine = new DelayLine (*(ref.delayLine ));
291
+ copyParent ((AudioEffect *)&ref);
292
+ };
293
293
294
- void setDuration ( int16_t ms ){
295
- p_ms = ms ;
294
+ virtual ~Delay ( ){
295
+ delete delayLine ;
296
296
}
297
297
298
- int16_t duration ( ){
299
- return p_ms ;
298
+ void setDuration ( int16_t m ){
299
+ delayLine-> setDuration (m) ;
300
300
}
301
301
302
- void setDepth ( float percent ){
303
- p_percent = percent ;
302
+ int16_t getDuration ( ){
303
+ return delayLine-> getDuration () ;
304
304
}
305
305
306
- uint8_t depth () {
307
- return p_percent ;
306
+ void setDepth ( float p) {
307
+ delayLine-> setDepth (p) ;
308
308
}
309
309
310
- void setFeedback ( float feedback) {
311
- p_feedback = feedback ;
310
+ float getDepth () {
311
+ return delayLine-> getDepth () ;
312
312
}
313
313
314
- uint8_t feedback () {
315
- return p_feedback;
314
+ void setFeedback (float f){
315
+ delayLine->setFeedback (f);
316
+ }
317
+
318
+ float getFeedback () {
319
+ return delayLine->getFeedback ();
320
+ }
321
+
322
+ void setSampleRate (int32_t s){
323
+ delayLine->setSampleRate (s);
324
+ }
325
+
326
+ float getSampleRate () {
327
+ return delayLine->getSampleRate ();
316
328
}
317
329
318
330
effect_t process (effect_t input) {
319
331
if (!active ()) return input;
320
332
333
+ delayLine->tick ();
321
334
updateBufferSize ();
322
335
// get value from buffer
323
336
int32_t value = (p_history->available ()<sampleCount) ? input : p_history->read ();
324
337
// add feedback decay
325
- int32_t delayValue = (value*p_feedback );
338
+ int32_t delayValue = (value*delayLine-> getFeedback () );
326
339
// add input and delay to the buffer
327
340
p_history->write (input+delayValue);
328
341
// mix input with result
329
- return (delayValue * p_percent) + (input * (1.0 - p_percent ));
342
+ return (delayValue * delayLine-> getDepth ()) + (input * (1.0 - delayLine-> getDepth () ));
330
343
}
331
344
332
345
Delay *clone () {
@@ -335,14 +348,11 @@ class Delay : public AudioEffect {
335
348
336
349
protected:
337
350
RingBuffer<effect_t >* p_history=nullptr ;
338
- float p_percent;
339
- float p_feedback;
340
- uint16_t p_ms;
351
+ DelayLine *delayLine;
341
352
uint16_t sampleCount=0 ;
342
- uint32_t sampleRate;
343
353
344
354
void updateBufferSize (){
345
- uint16_t newSampleCount = sampleRate * p_ms / 1000 ;
355
+ uint16_t newSampleCount = delayLine-> getSampleRate () * delayLine-> getDuration () / 1000 ;
346
356
if (newSampleCount!=sampleCount){
347
357
if (p_history!=nullptr ) delete p_history;
348
358
sampleCount = newSampleCount;
0 commit comments