@@ -48,19 +48,27 @@ class AudioEffect {
48
48
class Boost : public AudioEffect {
49
49
public:
50
50
// / Boost Constructor: volume 0.1 - 1.0: decrease result; volume >0: increase result
51
- Boost (float &volume){
52
- p_effect_value = &volume;
51
+ Boost (float volume=1.0 ){
52
+ effect_value = volume;
53
+ }
54
+
55
+ float volume () {
56
+ return effect_value;
57
+ }
58
+
59
+ void setVolume (float volume){
60
+ effect_value = volume;
53
61
}
54
62
55
63
effect_t process (effect_t input){
56
64
if (!active ()) return input;
57
- int32_t result = (*p_effect_value) * input;
65
+ int32_t result = effect_value * input;
58
66
// clip to int16_t
59
67
return clip (result);
60
68
}
61
69
62
70
protected:
63
- float *p_effect_value ;
71
+ float effect_value ;
64
72
};
65
73
66
74
/* *
@@ -73,20 +81,36 @@ class Boost : public AudioEffect {
73
81
class Distortion : public AudioEffect {
74
82
public:
75
83
// / Distortion Constructor: e.g. use clipThreashold 4990 and maxInput=6500
76
- Distortion (int16_t & clipThreashold, int16_t maxInput=6500 ){
77
- p_clip_threashold = & clipThreashold;
84
+ Distortion (int16_t clipThreashold= 4990 , int16_t maxInput=6500 ){
85
+ p_clip_threashold = clipThreashold;
78
86
max_input = maxInput;
79
87
}
80
88
89
+ void setClipThreashold (int16_t th){
90
+ p_clip_threashold = th;
91
+ }
92
+
93
+ int16_t clipThreashold (){
94
+ return p_clip_threashold;
95
+ }
96
+
97
+ void setMaxInput (int16_t maxInput){
98
+ max_input = maxInput;
99
+ }
100
+
101
+ int16_t maxInput (){
102
+ return max_input;
103
+ }
104
+
81
105
effect_t process (effect_t input){
82
106
if (!active ()) return input;
83
107
// the input signal is 16bits (values from -32768 to +32768
84
108
// the value of input is clipped to the distortion_threshold value
85
- return clip (input,* p_clip_threashold, max_input);
109
+ return clip (input,p_clip_threashold, max_input);
86
110
}
87
111
88
112
protected:
89
- int16_t * p_clip_threashold;
113
+ int16_t p_clip_threashold;
90
114
int16_t max_input;
91
115
92
116
};
@@ -101,20 +125,36 @@ class Distortion : public AudioEffect {
101
125
class Fuzz : public AudioEffect {
102
126
public:
103
127
// / Fuzz Constructor: use e.g. effectValue=6.5; maxOut = 300
104
- Fuzz (float & fuzzEffectValue, uint16_t maxOut = 300 ){
105
- p_effect_value = & fuzzEffectValue;
128
+ Fuzz (float fuzzEffectValue, uint16_t maxOut = 300 ){
129
+ p_effect_value = fuzzEffectValue;
106
130
max_out = maxOut;
107
131
}
108
132
133
+ void setFuzzEffectValue (float v){
134
+ p_effect_value = v;
135
+ }
136
+
137
+ float fuzzEffectValue (){
138
+ return p_effect_value;
139
+ }
140
+
141
+ void setMaxOut (uint16_t v){
142
+ max_out = v;
143
+ }
144
+
145
+ uint16_t maxOut (){
146
+ return max_out;
147
+ }
148
+
109
149
effect_t process (effect_t input){
110
150
if (!active ()) return input;
111
- float v = * p_effect_value;
151
+ float v = p_effect_value;
112
152
int32_t result = clip (v * input) ;
113
153
return map (result * v, -32768 , +32767 ,-max_out, max_out);
114
154
}
115
155
116
156
protected:
117
- float * p_effect_value;
157
+ float p_effect_value;
118
158
uint16_t max_out;
119
159
120
160
};
@@ -128,18 +168,37 @@ class Fuzz : public AudioEffect {
128
168
class Tremolo : public AudioEffect {
129
169
public:
130
170
// / 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 ) {
171
+ Tremolo (int16_t duration_ms=2000 , uint8_t depthPercent=50 , uint32_t sampleRate=44100 ) {
172
+ this ->duration_ms = duration_ms;
173
+ this ->sampleRate = sampleRate;
174
+ this ->p_percent = depthPercent;
132
175
int32_t rate_count = sampleRate * duration_ms / 1000 ;
133
176
rate_count_half = rate_count / 2 ;
134
- p_percent = &depthPercent;
177
+ }
178
+
179
+ void setDuration (int16_t ms){
180
+ int32_t rate_count = sampleRate * ms / 1000 ;
181
+ rate_count_half = rate_count / 2 ;
182
+ }
183
+
184
+ int16_t duration (){
185
+ return duration_ms;
186
+ }
187
+
188
+ void setDepth (uint8_t percent){
189
+ p_percent = percent;
190
+ }
191
+
192
+ uint8_t depth () {
193
+ return p_percent;
135
194
}
136
195
137
196
effect_t process (effect_t input) {
138
197
if (!active ()) return input;
139
198
140
199
// 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 ;
200
+ float tremolo_depth = p_percent > 100 ? 1.0 : 0.01 * p_percent;
201
+ float signal_depth = (100.0 - p_percent) / 100.0 ;
143
202
144
203
float tremolo_factor = tremolo_depth / rate_count_half;
145
204
int32_t out = (signal_depth * input) + (tremolo_factor * count * input);
@@ -155,12 +214,13 @@ class Tremolo : public AudioEffect {
155
214
return clip (out);
156
215
}
157
216
158
-
159
217
protected:
218
+ int16_t duration_ms;
219
+ uint32_t sampleRate;
160
220
int32_t count = 0 ;
161
221
int16_t inc = 1 ;
162
222
int32_t rate_count_half; // number of samples for on raise and fall
163
- uint8_t * p_percent;
223
+ uint8_t p_percent;
164
224
165
225
};
166
226
@@ -172,10 +232,26 @@ class Tremolo : public AudioEffect {
172
232
class Delay : public AudioEffect {
173
233
public:
174
234
// / e.g. depthPercent=50, ms=1000, sampleRate=44100
175
- Delay (uint16_t & duration_ms, uint8_t & depthPercent, uint32_t sampleRate=44100 ) {
235
+ Delay (uint16_t duration_ms= 1000 , uint8_t depthPercent= 50 , uint32_t sampleRate=44100 ) {
176
236
this ->sampleRate = sampleRate;
177
- p_percent = &depthPercent;
178
- p_ms = &duration_ms;
237
+ p_percent = depthPercent;
238
+ p_ms = duration_ms;
239
+ }
240
+
241
+ void setDuration (int16_t ms){
242
+ p_ms = ms;
243
+ }
244
+
245
+ int16_t duration (){
246
+ return p_ms;
247
+ }
248
+
249
+ void setDepth (uint8_t percent){
250
+ p_percent = percent;
251
+ }
252
+
253
+ uint8_t depth () {
254
+ return p_percent;
179
255
}
180
256
181
257
effect_t process (effect_t input) {
@@ -187,25 +263,24 @@ class Delay : public AudioEffect {
187
263
// add actual input value
188
264
p_history->write (input);
189
265
// mix input with result
190
- return (value * (* p_percent) / 100 ) + (input * (100 -(* p_percent) )/100 );
266
+ return (value * p_percent / 100 ) + (input * (100 -p_percent)/100 );
191
267
}
192
268
193
269
protected:
194
270
RingBuffer<effect_t >* p_history=nullptr ;
195
- uint8_t * p_percent;
196
- uint16_t * p_ms;
271
+ uint8_t p_percent;
272
+ uint16_t p_ms;
197
273
uint16_t sampleCount=0 ;
198
274
uint32_t sampleRate;
199
275
200
276
void updateBufferSize (){
201
- uint16_t newSampleCount = sampleRate * (* p_ms) / 1000 ;
277
+ uint16_t newSampleCount = sampleRate * p_ms / 1000 ;
202
278
if (newSampleCount>sampleCount){
203
279
if (p_history!=nullptr ) delete p_history;
204
280
sampleCount = newSampleCount;
205
281
p_history = new RingBuffer<effect_t >(sampleCount);
206
282
}
207
283
}
208
-
209
284
};
210
285
211
286
}
0 commit comments