Skip to content

Commit 632e725

Browse files
committed
cleanup
1 parent 4e558cf commit 632e725

File tree

1 file changed

+18
-18
lines changed

1 file changed

+18
-18
lines changed

src/AudioEffects/AudioEffect.h

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -127,19 +127,20 @@ class Fuzz : public AudioEffect {
127127

128128
class Tremolo : public AudioEffect {
129129
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;
133133
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;
138135
}
139136

140137
effect_t process(effect_t input) {
141138
if (!active()) return input;
142139

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+
143144
float tremolo_factor = tremolo_depth / rate_count_half;
144145
int32_t out = (signal_depth * input) + (tremolo_factor * count * input);
145146

@@ -159,9 +160,7 @@ class Tremolo : public AudioEffect {
159160
int32_t count = 0;
160161
int16_t inc = 1;
161162
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;
165164

166165
};
167166

@@ -172,16 +171,17 @@ class Tremolo : public AudioEffect {
172171
*/
173172
class Delay : public AudioEffect {
174173
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) {
177176
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;
182180
}
183181

184182
effect_t process(effect_t input) {
183+
if (!active()) return input;
184+
185185
updateBufferSize();
186186
// get value from buffer
187187
int32_t value = (p_history->available()<sampleCount) ? input : p_history->read();
@@ -195,13 +195,13 @@ class Delay : public AudioEffect {
195195
RingBuffer<effect_t>* p_history=nullptr;
196196
uint8_t* p_percent;
197197
uint16_t *p_ms;
198-
uint16_t sampleCount;
198+
uint16_t sampleCount=0;
199199
uint32_t sampleRate;
200200

201201
void updateBufferSize(){
202202
uint16_t newSampleCount = sampleRate * (*p_ms) / 1000;
203203
if (newSampleCount>sampleCount){
204-
delete p_history;
204+
if (p_history!=nullptr) delete p_history;
205205
sampleCount = newSampleCount;
206206
p_history = new RingBuffer<effect_t>(sampleCount);
207207
}

0 commit comments

Comments
 (0)