1
1
#pragma once
2
- #include < stdint.h>
2
+ #include < stdint.h>
3
3
#include " AudioTools/AudioLogger.h"
4
4
#include " AudioEffects/AudioParameters.h"
5
5
@@ -18,7 +18,7 @@ class AudioEffect {
18
18
public:
19
19
AudioEffect () = default ;
20
20
virtual ~AudioEffect () = default ;
21
-
21
+
22
22
// / calculates the effect output from the input
23
23
virtual effect_t process (effect_t in) = 0;
24
24
@@ -68,12 +68,12 @@ class AudioEffect {
68
68
* @brief Boost AudioEffect
69
69
* @author Phil Schatzmann
70
70
* @copyright GPLv3
71
- *
71
+ *
72
72
*/
73
73
74
74
class Boost : public AudioEffect {
75
75
public:
76
- // / Boost Constructor: volume 0.1 - 1.0: decrease result; volume >0: increase result
76
+ // / Boost Constructor: volume 0.1 - 1.0: decrease result; volume >0: increase result
77
77
Boost (float volume=1.0 ){
78
78
effect_value = volume;
79
79
}
@@ -91,7 +91,7 @@ class Boost : public AudioEffect {
91
91
effect_t process (effect_t input){
92
92
if (!active ()) return input;
93
93
int32_t result = effect_value * input;
94
- // clip to int16_t
94
+ // clip to int16_t
95
95
return clip (result);
96
96
}
97
97
@@ -105,7 +105,7 @@ class Boost : public AudioEffect {
105
105
106
106
/* *
107
107
* @brief Distortion AudioEffect
108
- *
108
+ *
109
109
* @author Phil Schatzmann
110
110
* @copyright GPLv3
111
111
*/
@@ -115,7 +115,7 @@ class Distortion : public AudioEffect {
115
115
// / Distortion Constructor: e.g. use clipThreashold 4990 and maxInput=6500
116
116
Distortion (int16_t clipThreashold=4990 , int16_t maxInput=6500 ){
117
117
p_clip_threashold = clipThreashold;
118
- max_input = maxInput;
118
+ max_input = maxInput;
119
119
}
120
120
121
121
Distortion (const Distortion ©) = default ;
@@ -134,12 +134,12 @@ class Distortion : public AudioEffect {
134
134
135
135
int16_t maxInput (){
136
136
return max_input;
137
- }
137
+ }
138
138
139
139
effect_t process (effect_t input){
140
140
if (!active ()) return input;
141
141
// the input signal is 16bits (values from -32768 to +32768
142
- // the value of input is clipped to the distortion_threshold value
142
+ // the value of input is clipped to the distortion_threshold value
143
143
return clip (input,p_clip_threashold, max_input);
144
144
}
145
145
@@ -155,7 +155,7 @@ class Distortion : public AudioEffect {
155
155
156
156
/* *
157
157
* @brief Fuzz AudioEffect
158
- *
158
+ *
159
159
* @author Phil Schatzmann
160
160
* @copyright GPLv3
161
161
*/
@@ -247,7 +247,7 @@ class Tremolo : public AudioEffect {
247
247
float signal_depth = (100.0 - p_percent) / 100.0 ;
248
248
249
249
float tremolo_factor = tremolo_depth / rate_count_half;
250
- int32_t out = (signal_depth * input) + (tremolo_factor * count * input);
250
+ int32_t out = (signal_depth * input) + (tremolo_factor * count * input);
251
251
252
252
// saw tooth shaped counter
253
253
count+=inc;
@@ -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 , uint8_t 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
}
@@ -298,24 +299,34 @@ class Delay : public AudioEffect {
298
299
return p_ms;
299
300
}
300
301
301
- void setDepth (uint8_t percent){
302
+ void setDepth (float percent){
302
303
p_percent = percent;
303
304
}
304
305
305
306
uint8_t depth () {
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 / 100 ) + (input * (100 - p_percent)/ 100 );
329
+ return (delayValue * p_percent) + (input * (1.0 - p_percent));
319
330
}
320
331
321
332
Delay *clone () {
@@ -324,7 +335,8 @@ class Delay : public AudioEffect {
324
335
325
336
protected:
326
337
RingBuffer<effect_t >* p_history=nullptr ;
327
- uint8_t p_percent;
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;
@@ -391,7 +403,7 @@ class ADSRGain : public AudioEffect {
391
403
float sustainLevel (){
392
404
return adsr->sustainLevel ();
393
405
}
394
-
406
+
395
407
void setReleaseRate (float r){
396
408
adsr->setReleaseRate (r);
397
409
}
0 commit comments