|
2 | 2 |
|
3 | 3 | #include "AudioConfig.h"
|
4 | 4 | #include "Arduino.h"
|
| 5 | +#include "AudioEffects/AudioEffect.h" |
5 | 6 | #ifdef ESP32
|
6 | 7 | # include "freertos/FreeRTOS.h"
|
7 | 8 | #endif
|
@@ -105,6 +106,153 @@ class STKStream : public GeneratedSoundStream<int16_t> {
|
105 | 106 |
|
106 | 107 | };
|
107 | 108 |
|
| 109 | +/** |
| 110 | + * @brief Use any effect from the STK framework: e.g. Chorus, Echo, FreeVerb, JCRev, |
| 111 | + * PitShift... https://github.com/pschatzmann/Arduino-STK |
| 112 | + * |
| 113 | + * @author Phil Schatzmann |
| 114 | + * @copyright GPLv3 |
| 115 | + */ |
| 116 | +class STKEffect : public AudioEffect { |
| 117 | +public: |
| 118 | + STKEffect(stk::Effect &stkEffect) { p_effect = &stkEffect; } |
| 119 | + |
| 120 | + virtual effect_t process(effect_t in) { |
| 121 | + // just convert between int16 and float |
| 122 | + float value = static_cast<float>(in) / 32767.0; |
| 123 | + return p_effect->tick(value) * 32767.0; |
| 124 | + } |
| 125 | + |
| 126 | +protected: |
| 127 | + stk::Effect *p_effect = nullptr; |
| 128 | +}; |
| 129 | + |
| 130 | +/** |
| 131 | + * @brief Chorus Effect |
| 132 | + * @author Phil Schatzmann |
| 133 | + * @copyright GPLv3 |
| 134 | + */ |
| 135 | +class STKChorus : public AudioEffect, public stk::Chorus { |
| 136 | +public: |
| 137 | + STKChorus(float baseDelay = 6000) : stk::Chorus(baseDelay) {} |
| 138 | + |
| 139 | + virtual effect_t process(effect_t in) { |
| 140 | + // just convert between int16 and float |
| 141 | + float value = static_cast<float>(in) / 32767.0; |
| 142 | + return tick(value) * 32767.0; |
| 143 | + } |
| 144 | +}; |
| 145 | + |
| 146 | +/** |
| 147 | + * @brief Echo Effect |
| 148 | + * @author Phil Schatzmann |
| 149 | + * @copyright GPLv3 |
| 150 | + */ |
| 151 | +class STKEcho : public AudioEffect, public stk::Echo { |
| 152 | +public: |
| 153 | + STKEcho(unsigned long maximumDelay = (unsigned long)Stk::sampleRate()) |
| 154 | + : stk::Echo(maximumDelay) {} |
| 155 | + |
| 156 | + virtual effect_t process(effect_t in) { |
| 157 | + // just convert between int16 and float |
| 158 | + float value = static_cast<float>(in) / 32767.0; |
| 159 | + return tick(value) * 32767.0; |
| 160 | + } |
| 161 | +}; |
| 162 | + |
| 163 | +/** |
| 164 | + * @brief Jezar at Dreampoint's FreeVerb, implemented in STK. |
| 165 | + * @author Phil Schatzmann |
| 166 | + * @copyright GPLv3 |
| 167 | + */ |
| 168 | +class STKFreeVerb : public AudioEffect, public stk::FreeVerb { |
| 169 | +public: |
| 170 | + STKFreeVerb() = default; |
| 171 | + virtual effect_t process(effect_t in) { |
| 172 | + // just convert between int16 and float |
| 173 | + float value = static_cast<float>(in) / 32767.0; |
| 174 | + return tick(value) * 32767.0; |
| 175 | + } |
| 176 | +}; |
| 177 | + |
| 178 | +/** |
| 179 | + * @brief John Chowning's reverberator class. |
| 180 | + * @author Phil Schatzmann |
| 181 | + * @copyright GPLv3 |
| 182 | + */ |
| 183 | +class STKChowningReverb : public AudioEffect, public stk::JCRev { |
| 184 | +public: |
| 185 | + STKChowningReverb() = default; |
| 186 | + |
| 187 | + virtual effect_t process(effect_t in) { |
| 188 | + // just convert between int16 and float |
| 189 | + float value = static_cast<float>(in) / 32767.0; |
| 190 | + return tick(value) * 32767.0; |
| 191 | + } |
| 192 | +}; |
| 193 | + |
| 194 | +/** |
| 195 | + * @brief CCRMA's NRev reverberator class. |
| 196 | + * @author Phil Schatzmann |
| 197 | + * @copyright GPLv3 |
| 198 | + */ |
| 199 | +class STKNReverb : public AudioEffect, public stk::NRev { |
| 200 | +public: |
| 201 | + STKNReverb(float t60 = 1.0) : NRev(t60) {} |
| 202 | + virtual effect_t process(effect_t in) { |
| 203 | + // just convert between int16 and float |
| 204 | + float value = static_cast<float>(in) / 32767.0; |
| 205 | + return tick(value) * 32767.0; |
| 206 | + } |
| 207 | +}; |
| 208 | + |
| 209 | +/** |
| 210 | + * @brief Perry's simple reverberator class |
| 211 | + * @author Phil Schatzmann |
| 212 | + * @copyright GPLv3 |
| 213 | + */ |
| 214 | +class STKPerryReverb : public AudioEffect, public stk::PRCRev { |
| 215 | +public: |
| 216 | + STKPerryReverb(float t60 = 1.0) : PRCRev(t60) {} |
| 217 | + virtual effect_t process(effect_t in) { |
| 218 | + // just convert between int16 and float |
| 219 | + float value = static_cast<float>(in) / 32767.0; |
| 220 | + return tick(value) * 32767.0; |
| 221 | + } |
| 222 | +}; |
| 223 | + |
| 224 | +/** |
| 225 | + * @brief Pitch shifter effect class based on the Lent algorithm |
| 226 | + * @author Phil Schatzmann |
| 227 | + * @copyright GPLv3 |
| 228 | + */ |
| 229 | +class STKLentPitShift : public AudioEffect, public stk::LentPitShift { |
| 230 | +public: |
| 231 | + STKLentPitShift(float periodRatio = 1.0, int tMax = 512) |
| 232 | + : stk::LentPitShift(periodRatio, tMax) {} |
| 233 | + |
| 234 | + virtual effect_t process(effect_t in) { |
| 235 | + // just convert between int16 and float |
| 236 | + float value = static_cast<float>(in) / 32767.0; |
| 237 | + return tick(value) * 32767.0; |
| 238 | + } |
| 239 | +}; |
| 240 | + |
| 241 | +/** |
| 242 | + * @brief Pitch shifter effect class based on the Lent algorithm |
| 243 | + * @author Phil Schatzmann |
| 244 | + * @copyright GPLv3 |
| 245 | + */ |
| 246 | +class STKPitShift : public AudioEffect, public stk::PitShift { |
| 247 | +public: |
| 248 | + STKPitShift() = default; |
| 249 | + virtual effect_t process(effect_t in) { |
| 250 | + // just convert between int16 and float |
| 251 | + float value = static_cast<float>(in) / 32767.0; |
| 252 | + return tick(value) * 32767.0; |
| 253 | + } |
| 254 | +}; |
| 255 | + |
108 | 256 |
|
109 | 257 | }
|
110 | 258 |
|
0 commit comments