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
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:
129
130 Distortion(const Distortion& copy) = default;
131
133
135
137
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:
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
226class Tremolo : public AudioEffect {
227 public:
229 enum Shape { Triangle, Sine };
230
233 Tremolo(int16_t duration_ms = 2000, uint8_t depthPercent = 50,
234 uint32_t sampleRate = 44100) {
235 this->sample_rate = sampleRate;
236 this->p_percent = depthPercent > 100 ? 100 : depthPercent;
238 gain = gainAt(phase);
239 }
240
241 Tremolo(const Tremolo& copy) = default;
242
245 duration_ms = ms;
246 rate_hz = ms > 0 ? 1000.0f / ms : 0.0f;
247 recalculate();
248 }
249
251
253 void setRate(float hz) {
254 rate_hz = hz > 0.0f ? hz : 0.0f;
255 duration_ms = rate_hz > 0.0f ? (int16_t)(1000.0f / rate_hz + 0.5f) : 0;
256 recalculate();
257 }
258
259 float rate() { return rate_hz; }
260
262 void setDepth(uint8_t percent) {
263 p_percent = percent > 100 ? 100 : percent;
264 recalculate();
265 }
266
267 uint8_t depth() { return p_percent; }
268
271 this->p_shape = shape;
272 recalculate();
273 }
274
275 Shape shape() { return p_shape; }
276
279 void setPhase(float degrees) {
280 float p = degrees / 360.0f;
281 phase = p - floorf(p);
282 recalculate();
283 gain = gainAt(phase); // jump to the new position
284 }
285
287 void setSampleRate(uint32_t sampleRate) {
288 sample_rate = sampleRate;
289 recalculate();
290 }
291
293 if (!active()) return input;
294 if (remaining == 0) nextSegment();
295 remaining--;
296 // gain in Q16 (65536 = 1.0): input * Q15 fits into 32 bits
297 int32_t out = ((int32_t)input * (gain >> 1)) >> 15;
298 gain += gain_step;
299 return (effect_t)out;
300 }
301
302 Tremolo* clone() { return new Tremolo(*this); }
303
304 protected:
305 static constexpr int SEGMENT = 32; // samples between the gain calculations
307 float rate_hz = 0.0f;
311 float phase = 0.0f; // position in the period 0..1
312 float segment_inc = 0.0f; // phase increment per segment
313 int32_t gain = 65536; // Q16
314 int32_t gain_step = 0; // Q16 per sample
315 int remaining = 0; // samples until the next segment
316
318 int32_t gainAt(float pos) {
319 float w; // 0 .. 1, starts at 0 (minimum)
320 if (p_shape == Sine) {
321 w = 0.5f - 0.5f * cosf(6.2831853f * pos);
322 } else {
323 w = pos < 0.5f ? 2.0f * pos : 2.0f - 2.0f * pos;
324 }
325 float depth = 0.01f * p_percent;
326 return (int32_t)((1.0f - depth + depth * w) * 65536.0f);
327 }
328
331 void nextSegment() {
332 if (segment_inc > 0.0f) {
334 if (phase >= 1.0f) phase -= 1.0f;
335 }
336 int32_t target = gainAt(phase);
337 gain_step = (target - gain) / SEGMENT;
339 }
340
343 void recalculate() {
345 gain_step = 0;
346 remaining = 0;
347 }
348};
349
358class Delay : public AudioEffect {
359 public:
361 Delay(uint16_t duration_ms = 1000, float depth = 0.5,
362 float feedbackAmount = 1.0, uint32_t sampleRate = 44100) {
364 setFeedback(feedbackAmount);
366 setDuration(duration_ms);
367 }
368
369 Delay(const Delay& copy) {
371 setFeedback(copy.feedback);
372 setDepth(copy.depth);
373 setDuration(copy.duration);
374 };
375
377 duration = dur;
379 }
380
382
383 void setDepth(float value) {
384 depth = value;
385 if (depth > 1.0f) depth = 1.0f;
386 if (depth < 0.0f) depth = 0.0f;
387#if PREFER_FIXEDPOINT
388 depth_q = q1_14_t(depth);
389 inv_depth_q = q1_14_t(1.0f) - depth_q;
390#endif
391 }
392
393 float getDepth() { return depth; }
394
395 void setFeedback(float feed) {
396 feedback = feed;
397 if (feedback > 1.0f) feedback = 1.0f;
398 if (feedback < 0.0f) feedback = 0.0f;
399#if PREFER_FIXEDPOINT
400 feedback_q = q1_14_t(feedback);
401#endif
402 }
403
404 float getFeedback() { return feedback; }
405
406 void setSampleRate(int32_t sample) {
407 sampleRate = sample;
409 }
410
411 float getSampleRate() { return sampleRate; }
412
414 if (!active()) return input;
415
416 // Read last audio sample in each delay line
417 effect_t delayed_value = buffer[delay_line_index];
418
419#if PREFER_FIXEDPOINT
420 // Mix the above with current audio and write the results back to output
421 int32_t out = inv_depth_q.scale(input) + depth_q.scale(delayed_value);
422
423 // Update each delay line
424 // write = input + feedback * delayed_value (typical delay feedback);
425 // scale() already rounds to nearest -- integer-only, no FPU needed
426 int32_t write_int = (int32_t)input + feedback_q.scale(delayed_value);
427#else
428 // Mix the above with current audio and write the results back to output
429 int32_t out = ((1.0f - depth) * input) + (depth * delayed_value);
430
431 // Update each delay line
432 // write = input + feedback * delayed_value (typical delay feedback)
433 float write_val = (float)input + feedback * (float)delayed_value;
434 // round to nearest integer to avoid truncation bias
435 int32_t write_int = (int32_t)roundf(write_val);
436#endif
437 // clip to allowed range and store
438 buffer[delay_line_index] = clip(write_int);
439
440 // Finally, update the delay line index
443 }
444 return clip(out);
445 }
446
447 Delay* clone() { return new Delay(*this); }
448
449 protected:
451 float feedback = 0.0f, duration = 0.0f, sampleRate = 0.0f, depth = 0.0f;
454#if PREFER_FIXEDPOINT
455 q1_14_t feedback_q{0.0f}, depth_q{0.0f}, inv_depth_q{1.0f};
456#endif
457
459 if (sampleRate > 0 && duration > 0) {
460 size_t newSampleCount = sampleRate * duration / 1000;
461 if (newSampleCount != delay_len_samples) {
462 delay_len_samples = newSampleCount;
464 memset(buffer.data(), 0, delay_len_samples * sizeof(effect_t));
465 LOGD("sample_count: %u", (unsigned)delay_len_samples);
466 }
467 }
468 }
469};
470
486class ADSRGain : public AudioEffect {
487 public:
488 ADSRGain(float attack = 0.001, float decay = 0.001, float sustainLevel = 0.5,
489 float release = 0.005, float boostFactor = 1.0) {
490 setFactor(boostFactor);
491 adsr = new ADSR(attack, decay, sustainLevel, release);
492 }
493
494 ADSRGain(const ADSRGain& ref) {
495 adsr = new ADSR(*(ref.adsr));
496 setFactor(ref.factor);
497 copyParent((AudioEffect*)&ref);
498 };
499
500 virtual ~ADSRGain() { delete adsr; }
501
502 void setAttackRate(float a) { adsr->setAttackRate(a); }
503
504 float attackRate() { return adsr->attackRate(); }
505
506 void setDecayRate(float d) { adsr->setDecayRate(d); }
507
508 float decayRate() { return adsr->decayRate(); }
509
510 void setSustainLevel(float s) { adsr->setSustainLevel(s); }
511
512 float sustainLevel() { return adsr->sustainLevel(); }
513
514 void setReleaseRate(float r) { adsr->setReleaseRate(r); }
515
516 float releaseRate() { return adsr->releaseRate(); }
517
518 void keyOn(float tgt = 0) { adsr->keyOn(tgt); }
519
520 void keyOff() { adsr->keyOff(); }
521
523 if (!active()) return input;
524#if PREFER_FIXEDPOINT
525 q1_14_t gain = factor_q * adsr->tickFixed();
526 return gain.scale(input);
527#else
528 effect_t result = factor * adsr->tick() * input;
529 return result;
530#endif
531 }
532
533 bool isActive() { return adsr->isActive(); }
534
535 ADSRGain* clone() { return new ADSRGain(*this); }
536
537 protected:
539 float factor;
540#if PREFER_FIXEDPOINT
541 q1_14_t factor_q{1.0f};
542#endif
543
544 void setFactor(float f) {
545 factor = f;
546#if PREFER_FIXEDPOINT
547 factor_q = q1_14_t(f);
548#endif
549 }
550};
551
558class PitchShift : public AudioEffect {
559 public:
562 PitchShift(float shift_value = 1.0, int buffer_size = 1000) {
563 effect_value = shift_value;
564 size = buffer_size;
565 buffer.resize(buffer_size);
566 buffer.setIncrement(shift_value);
567 }
568
569 PitchShift(const PitchShift& ref) {
570 size = ref.size;
574 };
575
576 float value() { return effect_value; }
577
578 void setValue(float value) {
581 }
582
584 if (!active()) return input;
585 buffer.write(input);
586 effect_t result;
587 buffer.read(result);
588 return result;
589 }
590
591 PitchShift* clone() { return new PitchShift(*this); }
592
593 protected:
596 int size;
597};
598
607class Compressor : public AudioEffect {
608 public:
610 Compressor(const Compressor& copy) = default;
611
613 Compressor(uint32_t sampleRate = 44100, uint16_t attackMs = 30,
614 uint16_t releaseMs = 20, uint16_t holdMs = 10,
615 uint8_t thresholdPercent = 10, float compressionRatio = 0.5) {
616 // assuming 1 sample = 1/96kHz = ~10us
617 // Attack -> 30 ms -> 3000
618 // Release -> 20 ms -> 2000
619 // Hold -> 10ms -> 1000
620 sample_rate = sampleRate;
621 attack_count = sample_rate * attackMs / 1000;
622 release_count = sample_rate * releaseMs / 1000;
623 hold_count = sample_rate * holdMs / 1000;
624
625 setThresholdPercent(thresholdPercent);
626 // compression ratio: 6:1 -> -6dB = 0.5
627 gainreduce = compressionRatio;
628 // initial gain = 1.0 -> no compression
629 gain = 1.0f;
630 recalculate();
631 }
632
634 void setAttack(uint16_t attackMs) {
635 attack_count = sample_rate * attackMs / 1000;
636 recalculate();
637 }
638
640 void setRelease(uint16_t releaseMs) {
641 release_count = sample_rate * releaseMs / 1000;
642 recalculate();
643 }
644
646 void setHold(uint16_t holdMs) {
647 hold_count = sample_rate * holdMs / 1000;
648 recalculate();
649 }
650
652 void setThresholdPercent(uint8_t thresholdPercent) {
653 // exact integer fraction of full-scale -- no float needed regardless of
654 // platform (threshold -20dB below limit -> 10% of 2^15)
655 threshold = (int32_t)NumberConverter::maxValueT<effect_t>() *
656 thresholdPercent / 100;
657 }
658
660 void setCompressionRatio(float compressionRatio) {
661 if (compressionRatio < 1.0f) {
662 gainreduce = compressionRatio;
663 }
664 recalculate();
665 }
666
669 if (!active()) return input;
670 return compress(input);
671 }
672
673 Compressor* clone() { return new Compressor(*this); }
674
675 protected:
678
680 int32_t threshold; // exact fraction of full-scale -- pure integer
682#if PREFER_FIXEDPOINT
683 // Q1.14's ~6.1e-5 resolution on gain_step_attack/release (added every
684 // sample for attack_count/release_count samples) accumulates a bounded
685 // gain error of a few percent under fast/extreme attack-release cycling
686 // -- acceptable for this musical effect, and far cheaper than a per-sample
687 // float multiply-add chain on an FPU-less MCU.
689 gain{1.0f};
690#else
692#endif
693
694 void recalculate() {
695 // done once per parameter change, not per sample -- float here is fine
696 // even under PREFER_FIXEDPOINT (see VolumeStream::setVolume() for the
697 // same pattern)
698 float step_a = (1.0f - (float)gainreduce) / attack_count;
699 float step_r = (1.0f - (float)gainreduce) / release_count;
700#if PREFER_FIXEDPOINT
701 gain_step_attack = q1_14_t(step_a);
702 gain_step_release = q1_14_t(step_r);
703#else
704 gain_step_attack = step_a;
705 gain_step_release = step_r;
706#endif
707 }
708
710 int32_t mag = inSample < 0 ? -(int32_t)inSample : (int32_t)inSample;
711 if (mag > threshold) {
712 if (gain >= gainreduce) {
713 if (state == S_NoOperation) {
714 state = S_Attack;
716 } else if (state == S_Release) {
717 state = S_Attack;
719 }
720 }
722 }
723
724 if (mag < threshold && gain <= 1.0f) {
725 if (timeout == 0 && state == S_GainReduction) {
728 }
729 }
730
731 switch (state) {
732 case S_Attack:
733 if (timeout > 0 && gain > gainreduce) {
735 timeout--;
736 } else {
739 }
740 break;
741
742 case S_GainReduction:
743 if (timeout > 0)
744 timeout--;
745 else {
748 }
749 break;
750
751 case S_Release:
752 if (timeout > 0 && gain < 1.0f) {
753 timeout--;
755 } else {
757 }
758 break;
759
760 case S_NoOperation:
761 if (gain < 1.0f) gain = 1.0f;
762 break;
763
764 default:
765 break;
766 }
767
768#if PREFER_FIXEDPOINT
769 return gain.scale(inSample);
770#else
771 return (effect_t)(gain * inSample);
772#endif
773 }
774};
775
776} // 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:486
void setDecayRate(float d)
Definition AudioEffect.h:506
float decayRate()
Definition AudioEffect.h:508
void keyOn(float tgt=0)
Definition AudioEffect.h:518
float factor
Definition AudioEffect.h:539
ADSRGain(float attack=0.001, float decay=0.001, float sustainLevel=0.5, float release=0.005, float boostFactor=1.0)
Definition AudioEffect.h:488
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:522
void setSustainLevel(float s)
Definition AudioEffect.h:510
float attackRate()
Definition AudioEffect.h:504
virtual ~ADSRGain()
Definition AudioEffect.h:500
ADSRGain(const ADSRGain &ref)
Definition AudioEffect.h:494
void setFactor(float f)
Definition AudioEffect.h:544
bool isActive()
Definition AudioEffect.h:533
void setReleaseRate(float r)
Definition AudioEffect.h:514
void setAttackRate(float a)
Definition AudioEffect.h:502
float releaseRate()
Definition AudioEffect.h:516
ADSRGain * clone()
Definition AudioEffect.h:535
float sustainLevel()
Definition AudioEffect.h:512
void keyOff()
Definition AudioEffect.h:520
ADSR * adsr
Definition AudioEffect.h:538
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:607
int32_t hold_count
Definition AudioEffect.h:679
int32_t timeout
Definition AudioEffect.h:679
void setAttack(uint16_t attackMs)
Defines the attack duration in ms.
Definition AudioEffect.h:634
float gainreduce
Definition AudioEffect.h:691
uint32_t sample_rate
Definition AudioEffect.h:681
effect_t process(effect_t input)
Processes the sample.
Definition AudioEffect.h:668
Compressor * clone()
Definition AudioEffect.h:673
enum CompStates state
Definition AudioEffect.h:677
CompStates
Definition AudioEffect.h:676
@ S_Attack
Definition AudioEffect.h:676
@ S_Release
Definition AudioEffect.h:676
@ S_NoOperation
Definition AudioEffect.h:676
@ S_GainReduction
Definition AudioEffect.h:676
void recalculate()
Definition AudioEffect.h:694
float gain_step_attack
Definition AudioEffect.h:691
void setRelease(uint16_t releaseMs)
Defines the release duration in ms.
Definition AudioEffect.h:640
float gain_step_release
Definition AudioEffect.h:691
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:613
void setHold(uint16_t holdMs)
Defines the hold duration in ms.
Definition AudioEffect.h:646
int32_t attack_count
Definition AudioEffect.h:679
Compressor(const Compressor &copy)=default
Copy Constructor.
void setCompressionRatio(float compressionRatio)
Defines the compression ratio from 0 to 1.
Definition AudioEffect.h:660
int32_t threshold
Definition AudioEffect.h:680
float gain
Definition AudioEffect.h:691
void setThresholdPercent(uint8_t thresholdPercent)
Defines the threshod in %.
Definition AudioEffect.h:652
effect_t compress(effect_t inSample)
Definition AudioEffect.h:709
int32_t release_count
Definition AudioEffect.h:679
Delay/Echo AudioEffect. See https://wiki.analog.com/resources/tools-software/sharc-audio-module/barem...
Definition AudioEffect.h:358
Vector< effect_t > buffer
Definition AudioEffect.h:450
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:413
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:361
Delay * clone()
Definition AudioEffect.h:447
void setFeedback(float feed)
Definition AudioEffect.h:395
void setDuration(int16_t dur)
Definition AudioEffect.h:376
void updateBufferSize()
Definition AudioEffect.h:458
float duration
Definition AudioEffect.h:451
float getFeedback()
Definition AudioEffect.h:404
float getDepth()
Definition AudioEffect.h:393
float depth
Definition AudioEffect.h:451
size_t delay_line_index
Definition AudioEffect.h:453
void setSampleRate(int32_t sample)
Definition AudioEffect.h:406
Delay(const Delay &copy)
Definition AudioEffect.h:369
int16_t getDuration()
Definition AudioEffect.h:381
void setDepth(float value)
Definition AudioEffect.h:383
float feedback
Definition AudioEffect.h:451
float sampleRate
Definition AudioEffect.h:451
float getSampleRate()
Definition AudioEffect.h:411
size_t delay_len_samples
Definition AudioEffect.h:452
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:558
PitchShift * clone()
Definition AudioEffect.h:591
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:583
int size
Definition AudioEffect.h:596
PitchShift(float shift_value=1.0, int buffer_size=1000)
Definition AudioEffect.h:562
PitchShift(const PitchShift &ref)
Definition AudioEffect.h:569
void setValue(float value)
Definition AudioEffect.h:578
VariableSpeedRingBuffer< int16_t > buffer
Definition AudioEffect.h:594
float value()
Definition AudioEffect.h:576
float effect_value
Definition AudioEffect.h:595
Tremolo AudioEffect: periodic change of the volume (amplitude modulation) between (100 - depth)% and ...
Definition AudioEffect.h:226
void setDepth(uint8_t percent)
Depth in percent: the volume changes between (100 - depth)% and 100%.
Definition AudioEffect.h:262
int16_t duration_ms
Definition AudioEffect.h:306
float phase
Definition AudioEffect.h:311
uint32_t sample_rate
Definition AudioEffect.h:308
int32_t gainAt(float pos)
Gain (Q16) at a position in the period: (1 - depth) .. 1.
Definition AudioEffect.h:318
effect_t process(effect_t input)
calculates the effect output from the input
Definition AudioEffect.h:292
void setShape(Shape shape)
Waveform: Triangle (default) or Sine.
Definition AudioEffect.h:270
void setPhase(float degrees)
Definition AudioEffect.h:279
void recalculate()
Definition AudioEffect.h:343
int32_t gain
Definition AudioEffect.h:313
uint8_t p_percent
Definition AudioEffect.h:309
Shape
Waveform of the modulation.
Definition AudioEffect.h:229
@ Sine
Definition AudioEffect.h:229
@ Triangle
Definition AudioEffect.h:229
void setDuration(int16_t ms)
Period of the modulation in ms (<= 0: no modulation)
Definition AudioEffect.h:244
float rate()
Definition AudioEffect.h:259
Tremolo(int16_t duration_ms=2000, uint8_t depthPercent=50, uint32_t sampleRate=44100)
Definition AudioEffect.h:233
static constexpr int SEGMENT
Definition AudioEffect.h:305
int remaining
Definition AudioEffect.h:315
void setRate(float hz)
Speed of the modulation in Hz (e.g. 5.5 for an electric piano)
Definition AudioEffect.h:253
float segment_inc
Definition AudioEffect.h:312
uint8_t depth()
Definition AudioEffect.h:267
int32_t gain_step
Definition AudioEffect.h:314
void setSampleRate(uint32_t sampleRate)
Sample rate of the processed audio.
Definition AudioEffect.h:287
float rate_hz
Definition AudioEffect.h:307
Tremolo * clone()
Definition AudioEffect.h:302
Shape shape()
Definition AudioEffect.h:275
Shape p_shape
Definition AudioEffect.h:310
Tremolo(const Tremolo &copy)=default
void nextSegment()
Definition AudioEffect.h:331
int16_t duration()
Definition AudioEffect.h:250
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
Supports the setting and getting of the volume.
Definition AudioTypes.h:193
virtual float volume()
provides the actual volume in the range of 0.0f to 1.0f
Definition AudioTypes.h:196
virtual bool setVolume(float volume)
define the actual volume in the range of 0.0f to 1.0f
Definition AudioTypes.h:198
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