Skip to content

Commit 47ae612

Browse files
committed
STKEffects and flush cleanup
1 parent 050ccaf commit 47ae612

File tree

6 files changed

+151
-175
lines changed

6 files changed

+151
-175
lines changed

src/AudioConfig.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -447,9 +447,5 @@ typedef uint32_t eps32_i2s_sample_rate_type;
447447

448448
#ifdef IS_DESKTOP
449449
#define USE_URL_ARDUINO
450-
#define FLUSH_OVERRIDE override
451450
#endif
452451

453-
#ifndef FLUSH_OVERRIDE
454-
#define FLUSH_OVERRIDE
455-
#endif

src/AudioEffects/AudioEffects.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66
#ifdef USE_EFFECTS_SUITE
77
#include "AudioEffects/AudioEffectsSuite.h"
88
#endif
9-
#ifdef USE_STK
10-
#include "AudioEffects/STKEffects.h"
11-
#endif
129

1310
namespace audio_tools {
1411

src/AudioEffects/STKEffects.h

Lines changed: 0 additions & 166 deletions
This file was deleted.

src/AudioLibs/AudioSTK.h

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include "AudioConfig.h"
44
#include "Arduino.h"
5+
#include "AudioEffects/AudioEffect.h"
56
#ifdef ESP32
67
# include "freertos/FreeRTOS.h"
78
#endif
@@ -105,6 +106,153 @@ class STKStream : public GeneratedSoundStream<int16_t> {
105106

106107
};
107108

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+
108256

109257
}
110258

src/AudioTools/AudioOutput.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class AudioPrint : public Print, public AudioBaseInfoDependent, public AudioBase
3232
return 0;
3333
}
3434

35-
void flush() FLUSH_OVERRIDE {
35+
void flush() {
3636
write((const uint8_t*)tmp, tmpPos-1);
3737
tmpPos=0;
3838
}

src/AudioTools/AudioStreams.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,8 @@ class AudioStream : public Stream, public AudioBaseInfoDependent, public AudioBa
6666
return info;
6767
}
6868

69+
virtual void flush() {}
70+
6971
protected:
7072
AudioBaseInfoDependent *p_notify=nullptr;
7173
AudioBaseInfo info;
@@ -92,7 +94,6 @@ class AudioStreamX : public AudioStream {
9294

9395
virtual int read() override { return not_supported(-1); }
9496
virtual int peek() override { return not_supported(-1); }
95-
virtual void flush() FLUSH_OVERRIDE {}
9697
};
9798

9899
/**

0 commit comments

Comments
 (0)