arduino-audio-tools
Loading...
Searching...
No Matches
AudioEffect.h
Go to the documentation of this file.
1#pragma once
2#include <math.h>
3#include <stdint.h>
4
5#include "AudioLogger.h"
6#include "AudioParameters.h"
10#include "PitchShift.h"
11
12namespace audio_tools {
13
14// we use int16_t for our effects
15typedef int16_t effect_t;
16
25 public:
26 AudioEffect() = default;
27 virtual ~AudioEffect() = default;
28
30 virtual effect_t process(effect_t in) = 0;
31
33 virtual void setActive(bool value) { active_flag = value; }
34
36 virtual bool active() { return active_flag; }
37
38 virtual AudioEffect* clone() = 0;
39
41 int id() { return id_value; }
42
44 void setId(int id) { this->id_value = id; }
45
46 protected:
47 bool active_flag = true;
48 int id_value = -1;
49
50 void copyParent(AudioEffect* copy) {
51 id_value = copy->id_value;
53 }
54
56 int16_t clip(int32_t in, int16_t clipLimit = 32767,
57 int16_t resultLimit = 32767) {
58 int32_t result = in;
59 if (result > clipLimit) {
60 result = resultLimit;
61 }
62 if (result < -clipLimit) {
63 result = -resultLimit;
64 }
65 return result;
66 }
67};
68
77class Boost : public AudioEffect, public VolumeSupport {
78 public:
81 Boost(float volume = 1.0) { setVolume(volume); }
82
83 Boost(const Boost& copy) = default;
84
88 bool setVolume(float volume) override {
89 bool result = VolumeSupport::setVolume(volume);
90#if PREFER_FIXEDPOINT
91 factor_q = q1_14_t(volume);
92#endif
93 return result;
94 }
95
97 if (!active()) return input;
98#if PREFER_FIXEDPOINT
99 return factor_q.scale(input);
100#else
101 int32_t result = volume() * input;
102 // clip to int16_t
103 return clip(result);
104#endif
105 }
106
107 Boost* clone() { return new Boost(*this); }
108
109 protected:
110#if PREFER_FIXEDPOINT
111 q1_14_t factor_q{1.0f};
112#endif
113};
114
122class Distortion : public AudioEffect {
123 public:
125 Distortion(int16_t clipThreashold = 4990, int16_t maxInput = 6500) {
128 }
129
130 Distortion(const Distortion& copy) = default;
131
132 void setClipThreashold(int16_t th) { p_clip_threashold = th; }
133
134 int16_t clipThreashold() { return p_clip_threashold; }
135
137
138 int16_t maxInput() { return max_input; }
139
141 if (!active()) return input;
142 // the input signal is 16bits (values from -32768 to +32768
143 // the value of input is clipped to the distortion_threshold value
144 return clip(input, p_clip_threashold, max_input);
145 }
146
147 Distortion* clone() { return new Distortion(*this); }
148
149 protected:
151 int16_t max_input;
152};
153
161class Fuzz : public AudioEffect {
162 public:
164 Fuzz(float fuzzEffectValue = 6.5, uint16_t maxOut = 300) {
166 max_out = maxOut;
167 }
168
169 Fuzz(const Fuzz& copy) = default;
170
171 void setFuzzEffectValue(float v) {
172 p_effect_value = v;
173 // Q8.8: p_effect_value can exceed q1_14_t's +-2.0 range (default 6.5),
174 // so a plain 8-fractional-bit integer scale is used instead -- still
175 // integer-only in process(), just with a wider (+-128) integer range.
176 v_fixed = (int32_t)(v * 256.0f + (v >= 0 ? 0.5f : -0.5f));
177 }
178
179 float fuzzEffectValue() { return p_effect_value; }
180
181 void setMaxOut(uint16_t v) { max_out = v; }
182
183 uint16_t maxOut() { return max_out; }
184
186 if (!active()) return input;
187#if PREFER_FIXEDPOINT
188 int32_t result = clip((v_fixed * input) >> 8);
189 int32_t result2 = (result * v_fixed) >> 8;
190 return map(result2, -32768, +32767, -max_out, max_out);
191#else
192 float v = p_effect_value;
193 int32_t result = clip(v * input);
194 return map(result * v, -32768, +32767, -max_out, max_out);
195#endif
196 }
197
198 Fuzz* clone() { return new Fuzz(*this); }
199
200 protected:
202 int32_t v_fixed; // Q8.8 fixed-point mirror of p_effect_value
203 uint16_t max_out;
204};
205
213class Tremolo : public AudioEffect {
214 public:
217 Tremolo(int16_t duration_ms = 2000, uint8_t depthPercent = 50,
218 uint32_t sampleRate = 44100) {
219 this->duration_ms = duration_ms;
220 this->sampleRate = sampleRate;
221 this->p_percent = depthPercent;
222 int32_t rate_count = sampleRate * duration_ms / 1000;
223 rate_count_half = rate_count / 2;
224 recalculate();
225 }
226
227 Tremolo(const Tremolo& copy) = default;
228
229 void setDuration(int16_t ms) {
230 this->duration_ms = ms;
231 int32_t rate_count = sampleRate * ms / 1000;
232 rate_count_half = rate_count / 2;
233 // tremolo_factor (float path) depends on rate_count_half too
234 recalculate();
235 }
236
237 int16_t duration() { return duration_ms; }
238
239 void setDepth(uint8_t percent) {
240 p_percent = percent;
241 recalculate();
242 }
243
244 uint8_t depth() { return p_percent; }
245
247 if (!active()) return input;
248 // guards the division below; also matches the float path's original
249 // (silent, non-crashing) behavior for this misconfiguration
250 if (rate_count_half <= 0) return input;
251
252#if PREFER_FIXEDPOINT
253 // triangle-wave position weight (count/rate_count_half) applied to the
254 // depth-scaled sample, all integer -- no per-sample float division
255 int32_t out =
256 signal_depth_q.scale(input) +
257 (int32_t)(((int64_t)tremolo_depth_q.scale(input) * count) /
259#else
260 int32_t out = (int32_t)(signal_depth * input) +
261 (int32_t)(tremolo_factor * count * input);
262#endif
263
264 // saw tooth shaped counter
265 count += inc;
266 if (count >= rate_count_half) {
267 inc = -1;
268 } else if (count <= 0) {
269 inc = +1;
270 }
271
272 return clip(out);
273 }
274
275 Tremolo* clone() { return new Tremolo(*this); }
276
277 protected:
278 int16_t duration_ms;
279 uint32_t sampleRate;
280 int32_t count = 0;
281 int16_t inc = 1;
282 int32_t rate_count_half; // number of samples for on raise and fall
283 uint8_t p_percent;
284#if PREFER_FIXEDPOINT
285 q1_14_t signal_depth_q{1.0f};
286 q1_14_t tremolo_depth_q{0.0f};
287#else
288 float signal_depth = 1.0f;
289 float tremolo_depth = 0.0f;
290 float tremolo_factor = 0.0f;
291#endif
292
293 // p_percent only changes on setDepth(), so the depth split is computed
294 // once here instead of every process() call
295 void recalculate() {
296 float td = p_percent > 100 ? 1.0f : 0.01f * p_percent;
297 float sd = (100.0f - p_percent) / 100.0f;
298#if PREFER_FIXEDPOINT
299 tremolo_depth_q = q1_14_t(td);
300 signal_depth_q = q1_14_t(sd);
301#else
302 tremolo_depth = td;
303 signal_depth = sd;
305#endif
306 }
307};
308
317class Delay : public AudioEffect {
318 public:
320 Delay(uint16_t duration_ms = 1000, float depth = 0.5,
321 float feedbackAmount = 1.0, uint32_t sampleRate = 44100) {
323 setFeedback(feedbackAmount);
325 setDuration(duration_ms);
326 }
327
328 Delay(const Delay& copy) {
330 setFeedback(copy.feedback);
331 setDepth(copy.depth);
332 setDuration(copy.duration);
333 };
334
335 void setDuration(int16_t dur) {
336 duration = dur;
338 }
339
340 int16_t getDuration() { return duration; }
341
342 void setDepth(float value) {
343 depth = value;
344 if (depth > 1.0f) depth = 1.0f;
345 if (depth < 0.0f) depth = 0.0f;
346#if PREFER_FIXEDPOINT
347 depth_q = q1_14_t(depth);
348 inv_depth_q = q1_14_t(1.0f) - depth_q;
349#endif
350 }
351
352 float getDepth() { return depth; }
353
354 void setFeedback(float feed) {
355 feedback = feed;
356 if (feedback > 1.0f) feedback = 1.0f;
357 if (feedback < 0.0f) feedback = 0.0f;
358#if PREFER_FIXEDPOINT
359 feedback_q = q1_14_t(feedback);
360#endif
361 }
362
363 float getFeedback() { return feedback; }
364
365 void setSampleRate(int32_t sample) {
366 sampleRate = sample;
368 }
369
370 float getSampleRate() { return sampleRate; }
371
373 if (!active()) return input;
374
375 // Read last audio sample in each delay line
376 effect_t delayed_value = buffer[delay_line_index];
377
378#if PREFER_FIXEDPOINT
379 // Mix the above with current audio and write the results back to output
380 int32_t out = inv_depth_q.scale(input) + depth_q.scale(delayed_value);
381
382 // Update each delay line
383 // write = input + feedback * delayed_value (typical delay feedback);
384 // scale() already rounds to nearest -- integer-only, no FPU needed
385 int32_t write_int = (int32_t)input + feedback_q.scale(delayed_value);
386#else
387 // Mix the above with current audio and write the results back to output
388 int32_t out = ((1.0f - depth) * input) + (depth * delayed_value);
389
390 // Update each delay line
391 // write = input + feedback * delayed_value (typical delay feedback)
392 float write_val = (float)input + feedback * (float)delayed_value;
393 // round to nearest integer to avoid truncation bias
394 int32_t write_int = (int32_t)roundf(write_val);
395#endif
396 // clip to allowed range and store
397 buffer[delay_line_index] = clip(write_int);
398
399 // Finally, update the delay line index
402 }
403 return clip(out);
404 }
405
406 Delay* clone() { return new Delay(*this); }
407
408 protected:
410 float feedback = 0.0f, duration = 0.0f, sampleRate = 0.0f, depth = 0.0f;
413#if PREFER_FIXEDPOINT
414 q1_14_t feedback_q{0.0f}, depth_q{0.0f}, inv_depth_q{1.0f};
415#endif
416
418 if (sampleRate > 0 && duration > 0) {
419 size_t newSampleCount = sampleRate * duration / 1000;
420 if (newSampleCount != delay_len_samples) {
421 delay_len_samples = newSampleCount;
423 memset(buffer.data(), 0, delay_len_samples * sizeof(effect_t));
424 LOGD("sample_count: %u", (unsigned)delay_len_samples);
425 }
426 }
427 }
428};
429
445class ADSRGain : public AudioEffect {
446 public:
447 ADSRGain(float attack = 0.001, float decay = 0.001, float sustainLevel = 0.5,
448 float release = 0.005, float boostFactor = 1.0) {
449 setFactor(boostFactor);
450 adsr = new ADSR(attack, decay, sustainLevel, release);
451 }
452
453 ADSRGain(const ADSRGain& ref) {
454 adsr = new ADSR(*(ref.adsr));
455 setFactor(ref.factor);
456 copyParent((AudioEffect*)&ref);
457 };
458
459 virtual ~ADSRGain() { delete adsr; }
460
461 void setAttackRate(float a) { adsr->setAttackRate(a); }
462
463 float attackRate() { return adsr->attackRate(); }
464
465 void setDecayRate(float d) { adsr->setDecayRate(d); }
466
467 float decayRate() { return adsr->decayRate(); }
468
469 void setSustainLevel(float s) { adsr->setSustainLevel(s); }
470
471 float sustainLevel() { return adsr->sustainLevel(); }
472
473 void setReleaseRate(float r) { adsr->setReleaseRate(r); }
474
475 float releaseRate() { return adsr->releaseRate(); }
476
477 void keyOn(float tgt = 0) { adsr->keyOn(tgt); }
478
479 void keyOff() { adsr->keyOff(); }
480
482 if (!active()) return input;
483#if PREFER_FIXEDPOINT
484 q1_14_t gain = factor_q * adsr->tickFixed();
485 return gain.scale(input);
486#else
487 effect_t result = factor * adsr->tick() * input;
488 return result;
489#endif
490 }
491
492 bool isActive() { return adsr->isActive(); }
493
494 ADSRGain* clone() { return new ADSRGain(*this); }
495
496 protected:
498 float factor;
499#if PREFER_FIXEDPOINT
500 q1_14_t factor_q{1.0f};
501#endif
502
503 void setFactor(float f) {
504 factor = f;
505#if PREFER_FIXEDPOINT
506 factor_q = q1_14_t(f);
507#endif
508 }
509};
510
517class PitchShift : public AudioEffect {
518 public:
521 PitchShift(float shift_value = 1.0, int buffer_size = 1000) {
522 effect_value = shift_value;
523 size = buffer_size;
524 buffer.resize(buffer_size);
525 buffer.setIncrement(shift_value);
526 }
527
528 PitchShift(const PitchShift& ref) {
529 size = ref.size;
533 };
534
535 float value() { return effect_value; }
536
537 void setValue(float value) {
540 }
541
543 if (!active()) return input;
544 buffer.write(input);
545 effect_t result;
546 buffer.read(result);
547 return result;
548 }
549
550 PitchShift* clone() { return new PitchShift(*this); }
551
552 protected:
555 int size;
556};
557
566class Compressor : public AudioEffect {
567 public:
569 Compressor(const Compressor& copy) = default;
570
572 Compressor(uint32_t sampleRate = 44100, uint16_t attackMs = 30,
573 uint16_t releaseMs = 20, uint16_t holdMs = 10,
574 uint8_t thresholdPercent = 10, float compressionRatio = 0.5) {
575 // assuming 1 sample = 1/96kHz = ~10us
576 // Attack -> 30 ms -> 3000
577 // Release -> 20 ms -> 2000
578 // Hold -> 10ms -> 1000
579 sample_rate = sampleRate;
580 attack_count = sample_rate * attackMs / 1000;
581 release_count = sample_rate * releaseMs / 1000;
582 hold_count = sample_rate * holdMs / 1000;
583
584 setThresholdPercent(thresholdPercent);
585 // compression ratio: 6:1 -> -6dB = 0.5
586 gainreduce = compressionRatio;
587 // initial gain = 1.0 -> no compression
588 gain = 1.0f;
589 recalculate();
590 }
591
593 void setAttack(uint16_t attackMs) {
594 attack_count = sample_rate * attackMs / 1000;
595 recalculate();
596 }
597
599 void setRelease(uint16_t releaseMs) {
600 release_count = sample_rate * releaseMs / 1000;
601 recalculate();
602 }
603
605 void setHold(uint16_t holdMs) {
606 hold_count = sample_rate * holdMs / 1000;
607 recalculate();
608 }
609
611 void setThresholdPercent(uint8_t thresholdPercent) {
612 // exact integer fraction of full-scale -- no float needed regardless of
613 // platform (threshold -20dB below limit -> 10% of 2^15)
614 threshold = (int32_t)NumberConverter::maxValueT<effect_t>() *
615 thresholdPercent / 100;
616 }
617
619 void setCompressionRatio(float compressionRatio) {
620 if (compressionRatio < 1.0f) {
621 gainreduce = compressionRatio;
622 }
623 recalculate();
624 }
625
628 if (!active()) return input;
629 return compress(input);
630 }
631
632 Compressor* clone() { return new Compressor(*this); }
633
634 protected:
637
639 int32_t threshold; // exact fraction of full-scale -- pure integer
640 uint32_t sample_rate;
641#if PREFER_FIXEDPOINT
642 // Q1.14's ~6.1e-5 resolution on gain_step_attack/release (added every
643 // sample for attack_count/release_count samples) accumulates a bounded
644 // gain error of a few percent under fast/extreme attack-release cycling
645 // -- acceptable for this musical effect, and far cheaper than a per-sample
646 // float multiply-add chain on an FPU-less MCU.
648 gain{1.0f};
649#else
651#endif
652
653 void recalculate() {
654 // done once per parameter change, not per sample -- float here is fine
655 // even under PREFER_FIXEDPOINT (see VolumeStream::setVolume() for the
656 // same pattern)
657 float step_a = (1.0f - (float)gainreduce) / attack_count;
658 float step_r = (1.0f - (float)gainreduce) / release_count;
659#if PREFER_FIXEDPOINT
660 gain_step_attack = q1_14_t(step_a);
661 gain_step_release = q1_14_t(step_r);
662#else
663 gain_step_attack = step_a;
664 gain_step_release = step_r;
665#endif
666 }
667
669 int32_t mag = inSample < 0 ? -(int32_t)inSample : (int32_t)inSample;
670 if (mag > threshold) {
671 if (gain >= gainreduce) {
672 if (state == S_NoOperation) {
673 state = S_Attack;
675 } else if (state == S_Release) {
676 state = S_Attack;
678 }
679 }
681 }
682
683 if (mag < threshold && gain <= 1.0f) {
684 if (timeout == 0 && state == S_GainReduction) {
687 }
688 }
689
690 switch (state) {
691 case S_Attack:
692 if (timeout > 0 && gain > gainreduce) {
694 timeout--;
695 } else {
698 }
699 break;
700
701 case S_GainReduction:
702 if (timeout > 0)
703 timeout--;
704 else {
707 }
708 break;
709
710 case S_Release:
711 if (timeout > 0 && gain < 1.0f) {
712 timeout--;
714 } else {
716 }
717 break;
718
719 case S_NoOperation:
720 if (gain < 1.0f) gain = 1.0f;
721 break;
722
723 default:
724 break;
725 }
726
727#if PREFER_FIXEDPOINT
728 return gain.scale(inSample);
729#else
730 return (effect_t)(gain * inSample);
731#endif
732 }
733};
734
735} // namespace audio_tools
long map(long x, long in_min, long in_max, long out_min, long out_max)
Maps input to output values.
Definition Arduino.h:182
#define LOGD(...)
Definition AudioLoggerIDF.h:27
Real-time pitch shifting audio effect implementation.
ADSR Envelope: Attack, Decay, Sustain and Release. Attack is the time taken for initial run-up oeffec...
Definition AudioEffect.h:445
void setDecayRate(float d)
Definition AudioEffect.h:465
float decayRate()
Definition AudioEffect.h:467
void keyOn(float tgt=0)
Definition AudioEffect.h:477
float factor
Definition AudioEffect.h:498
ADSRGain(float attack=0.001, float decay=0.001, float sustainLevel=0.5, float release=0.005, float boostFactor=1.0)
Definition AudioEffect.h:447
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:481
void setSustainLevel(float s)
Definition AudioEffect.h:469
float attackRate()
Definition AudioEffect.h:463
virtual ~ADSRGain()
Definition AudioEffect.h:459
ADSRGain(const ADSRGain &ref)
Definition AudioEffect.h:453
void setFactor(float f)
Definition AudioEffect.h:503
bool isActive()
Definition AudioEffect.h:492
void setReleaseRate(float r)
Definition AudioEffect.h:473
void setAttackRate(float a)
Definition AudioEffect.h:461
float releaseRate()
Definition AudioEffect.h:475
ADSRGain * clone()
Definition AudioEffect.h:494
float sustainLevel()
Definition AudioEffect.h:471
void keyOff()
Definition AudioEffect.h:479
ADSR * adsr
Definition AudioEffect.h:497
Generates ADSR values between 0.0 and 1.0.
Definition AudioParameters.h:53
void setDecayRate(float d)
Definition AudioParameters.h:76
float decayRate()
Definition AudioParameters.h:83
void keyOn(float tgt=0)
Definition AudioParameters.h:109
void setSustainLevel(float s)
Definition AudioParameters.h:87
float attackRate()
Definition AudioParameters.h:72
bool isActive()
Definition AudioParameters.h:131
void setReleaseRate(float r)
Definition AudioParameters.h:98
void setAttackRate(float a)
Definition AudioParameters.h:65
float releaseRate()
Definition AudioParameters.h:105
float sustainLevel()
Definition AudioParameters.h:94
void keyOff()
Definition AudioParameters.h:120
virtual float tick()
Definition AudioParameters.h:20
Abstract Base class for Sound Effects.
Definition AudioEffect.h:24
virtual AudioEffect * clone()=0
virtual bool active()
determines if the effect is active
Definition AudioEffect.h:36
virtual void setActive(bool value)
sets the effect active/inactive
Definition AudioEffect.h:33
void setId(int id)
Allows to identify an effect.
Definition AudioEffect.h:44
int id()
Allows to identify an effect.
Definition AudioEffect.h:41
virtual effect_t process(effect_t in)=0
calculates the effect output from the input
int id_value
Definition AudioEffect.h:48
bool active_flag
Definition AudioEffect.h:47
void copyParent(AudioEffect *copy)
Definition AudioEffect.h:50
virtual ~AudioEffect()=default
int16_t clip(int32_t in, int16_t clipLimit=32767, int16_t resultLimit=32767)
generic clipping method
Definition AudioEffect.h:56
Boost AudioEffect.
Definition AudioEffect.h:77
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:96
Boost * clone()
Definition AudioEffect.h:107
bool setVolume(float volume) override
Definition AudioEffect.h:88
Boost(const Boost &copy)=default
Boost(float volume=1.0)
Definition AudioEffect.h:81
Compressor inspired by https://github.com/YetAnotherElectronicsChannel/STM32_DSP_COMPRESSOR/blob/mast...
Definition AudioEffect.h:566
int32_t hold_count
Definition AudioEffect.h:638
int32_t timeout
Definition AudioEffect.h:638
void setAttack(uint16_t attackMs)
Defines the attack duration in ms.
Definition AudioEffect.h:593
float gainreduce
Definition AudioEffect.h:650
uint32_t sample_rate
Definition AudioEffect.h:640
effect_t process(effect_t input)
Processes the sample.
Definition AudioEffect.h:627
Compressor * clone()
Definition AudioEffect.h:632
enum CompStates state
Definition AudioEffect.h:636
CompStates
Definition AudioEffect.h:635
@ S_Attack
Definition AudioEffect.h:635
@ S_Release
Definition AudioEffect.h:635
@ S_NoOperation
Definition AudioEffect.h:635
@ S_GainReduction
Definition AudioEffect.h:635
void recalculate()
Definition AudioEffect.h:653
float gain_step_attack
Definition AudioEffect.h:650
void setRelease(uint16_t releaseMs)
Defines the release duration in ms.
Definition AudioEffect.h:599
float gain_step_release
Definition AudioEffect.h:650
Compressor(uint32_t sampleRate=44100, uint16_t attackMs=30, uint16_t releaseMs=20, uint16_t holdMs=10, uint8_t thresholdPercent=10, float compressionRatio=0.5)
Default Constructor.
Definition AudioEffect.h:572
void setHold(uint16_t holdMs)
Defines the hold duration in ms.
Definition AudioEffect.h:605
int32_t attack_count
Definition AudioEffect.h:638
Compressor(const Compressor &copy)=default
Copy Constructor.
void setCompressionRatio(float compressionRatio)
Defines the compression ratio from 0 to 1.
Definition AudioEffect.h:619
int32_t threshold
Definition AudioEffect.h:639
float gain
Definition AudioEffect.h:650
void setThresholdPercent(uint8_t thresholdPercent)
Defines the threshod in %.
Definition AudioEffect.h:611
effect_t compress(effect_t inSample)
Definition AudioEffect.h:668
int32_t release_count
Definition AudioEffect.h:638
Delay/Echo AudioEffect. See https://wiki.analog.com/resources/tools-software/sharc-audio-module/barem...
Definition AudioEffect.h:317
Vector< effect_t > buffer
Definition AudioEffect.h:409
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:372
Delay(uint16_t duration_ms=1000, float depth=0.5, float feedbackAmount=1.0, uint32_t sampleRate=44100)
e.g. depth=0.5, ms=1000, sampleRate=44100
Definition AudioEffect.h:320
Delay * clone()
Definition AudioEffect.h:406
void setFeedback(float feed)
Definition AudioEffect.h:354
void setDuration(int16_t dur)
Definition AudioEffect.h:335
void updateBufferSize()
Definition AudioEffect.h:417
float duration
Definition AudioEffect.h:410
float getFeedback()
Definition AudioEffect.h:363
float getDepth()
Definition AudioEffect.h:352
float depth
Definition AudioEffect.h:410
size_t delay_line_index
Definition AudioEffect.h:412
void setSampleRate(int32_t sample)
Definition AudioEffect.h:365
Delay(const Delay &copy)
Definition AudioEffect.h:328
int16_t getDuration()
Definition AudioEffect.h:340
void setDepth(float value)
Definition AudioEffect.h:342
float feedback
Definition AudioEffect.h:410
float sampleRate
Definition AudioEffect.h:410
float getSampleRate()
Definition AudioEffect.h:370
size_t delay_len_samples
Definition AudioEffect.h:411
Distortion AudioEffect.
Definition AudioEffect.h:122
Distortion(const Distortion &copy)=default
void setClipThreashold(int16_t th)
Definition AudioEffect.h:132
void setMaxInput(int16_t maxInput)
Definition AudioEffect.h:136
int16_t p_clip_threashold
Definition AudioEffect.h:150
Distortion(int16_t clipThreashold=4990, int16_t maxInput=6500)
Distortion Constructor: e.g. use clipThreashold 4990 and maxInput=6500.
Definition AudioEffect.h:125
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:140
int16_t maxInput()
Definition AudioEffect.h:138
int16_t max_input
Definition AudioEffect.h:151
int16_t clipThreashold()
Definition AudioEffect.h:134
Distortion * clone()
Definition AudioEffect.h:147
Fuzz AudioEffect.
Definition AudioEffect.h:161
void setFuzzEffectValue(float v)
Definition AudioEffect.h:171
float p_effect_value
Definition AudioEffect.h:201
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:185
Fuzz(float fuzzEffectValue=6.5, uint16_t maxOut=300)
Fuzz Constructor: use e.g. effectValue=6.5; maxOut = 300.
Definition AudioEffect.h:164
Fuzz * clone()
Definition AudioEffect.h:198
void setMaxOut(uint16_t v)
Definition AudioEffect.h:181
uint16_t max_out
Definition AudioEffect.h:203
uint16_t maxOut()
Definition AudioEffect.h:183
Fuzz(const Fuzz &copy)=default
float fuzzEffectValue()
Definition AudioEffect.h:179
int32_t v_fixed
Definition AudioEffect.h:202
Shifts the pitch by the indicated step size: e.g. 2 doubles the pitch.
Definition AudioEffect.h:517
PitchShift * clone()
Definition AudioEffect.h:550
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:542
int size
Definition AudioEffect.h:555
PitchShift(float shift_value=1.0, int buffer_size=1000)
Definition AudioEffect.h:521
PitchShift(const PitchShift &ref)
Definition AudioEffect.h:528
void setValue(float value)
Definition AudioEffect.h:537
VariableSpeedRingBuffer< int16_t > buffer
Definition AudioEffect.h:553
float value()
Definition AudioEffect.h:535
float effect_value
Definition AudioEffect.h:554
Tremolo AudioEffect.
Definition AudioEffect.h:213
void setDepth(uint8_t percent)
Definition AudioEffect.h:239
int16_t duration_ms
Definition AudioEffect.h:278
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:246
float tremolo_factor
Definition AudioEffect.h:290
void recalculate()
Definition AudioEffect.h:295
int32_t count
Definition AudioEffect.h:280
uint8_t p_percent
Definition AudioEffect.h:283
void setDuration(int16_t ms)
Definition AudioEffect.h:229
Tremolo(int16_t duration_ms=2000, uint8_t depthPercent=50, uint32_t sampleRate=44100)
Definition AudioEffect.h:217
uint32_t sampleRate
Definition AudioEffect.h:279
int32_t rate_count_half
Definition AudioEffect.h:282
uint8_t depth()
Definition AudioEffect.h:244
float tremolo_depth
Definition AudioEffect.h:289
float signal_depth
Definition AudioEffect.h:288
Tremolo * clone()
Definition AudioEffect.h:275
Tremolo(const Tremolo &copy)=default
int16_t inc
Definition AudioEffect.h:281
int16_t duration()
Definition AudioEffect.h:237
Optimized buffer implementation for pitch shifting with interpolation.
Definition PitchShift.h:412
void setIncrement(float increment)
Set the reading speed increment for pitch shifting.
Definition PitchShift.h:428
bool write(T sample)
write add an entry to the buffer
Definition PitchShift.h:462
bool read(T &result)
reads a single value
Definition PitchShift.h:442
bool resize(size_t size)
Resize buffer and set initial read position to prevent immediate overrun.
Definition PitchShift.h:435
Vector implementation which provides the most important methods as defined by std::vector....
Definition Vector.h:21
bool resize(size_t newSize, T value)
Definition Vector.h:266
T * data()
Definition Vector.h:316
Supports the setting and getting of the volume.
Definition AudioTypes.h:187
virtual float volume()
provides the actual volume in the range of 0.0f to 1.0f
Definition AudioTypes.h:190
virtual bool setVolume(float volume)
define the actual volume in the range of 0.0f to 1.0f
Definition AudioTypes.h:192
Fixed-point Q1.14 number: a plain 16-bit signed integer holding 1 integer bit and 14 fractional bits ...
Definition q1_14_t.h:16
int16_t scale(int16_t sample) const
scales a 16-bit PCM sample by this Q1.14 factor
Definition q1_14_t.h:83
Generic Implementation of sound input and output for desktop environments using portaudio.
Definition LMSEchoCancellationStream.h:6
int16_t effect_t
Definition AudioEffect.h:15