Skip to content

Commit 993ec2f

Browse files
committed
AudioEffects issue#86
1 parent 0accd1a commit 993ec2f

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

src/AudioEffects/AudioEffects.h

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
3333
AudioEffects(AudioEffects &copy) {
3434
LOGI(LOG_METHOD);
3535
// create a copy of the source and all effects
36-
generator_obj = copy.generator_obj;
36+
p_generator = copy.p_generator;
3737
for (int j=0;j<copy.size();j++){
3838
effects.push_back(copy[j]->clone());
3939
}
@@ -56,7 +56,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
5656
/// Defines the input source for the raw guitar input
5757
void setInput(GeneratorT &in){
5858
LOGD(LOG_METHOD);
59-
generator_obj = in;
59+
p_generator = &in;
6060
// automatically activate this object
6161
AudioBaseInfo info;
6262
info.channels = 1;
@@ -79,10 +79,13 @@ class AudioEffects : public SoundGenerator<effect_t> {
7979

8080
/// provides the resulting sample
8181
effect_t readSample() override {
82-
effect_t sample = generator_obj.readSample();
83-
int size = effects.size();
84-
for (int j=0; j<size; j++){
85-
sample = effects[j]->process(sample);
82+
effect_t sample;
83+
if (p_generator!=nullptr){
84+
sample = p_generator->readSample();
85+
int size = effects.size();
86+
for (int j=0; j<size; j++){
87+
sample = effects[j]->process(sample);
88+
}
8689
}
8790
return sample;
8891
}
@@ -100,7 +103,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
100103

101104
/// Provides access to the sound generator
102105
GeneratorT &generator(){
103-
return generator_obj;
106+
return p_generator;
104107
}
105108

106109
/// gets an effect by index
@@ -124,7 +127,7 @@ class AudioEffects : public SoundGenerator<effect_t> {
124127

125128
protected:
126129
Vector<AudioEffect*> effects;
127-
GeneratorT generator_obj;
130+
GeneratorT *p_generator=nullptr;
128131
};
129132

130133

src/AudioEffects/SoundGenerator.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ class SineWaveGenerator : public SoundGenerator<T>{
200200
/// Defines the frequency - after the processing has been started
201201
void setFrequency(uint16_t frequency) override {
202202
LOGI("setFrequency: %d", frequency);
203+
LOGI( "active: %s", SoundGenerator<T>::active ? "true" : "false" );
203204
m_frequency = frequency;
204205
}
205206

tests/effects/effects.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ ADSRGain adsr(0.0001,0.0001, 0.9 , 0.0002);
1212
GeneratedSoundStream<int16_t> in(effects);
1313
StreamCopy copier(out, in);
1414
uint64_t timeout=0;
15-
int freq = N_C3;
15+
int freq = N_C4;
1616

1717

1818
void setup() {
1919
Serial.begin(115200);
20-
AudioLogger::instance().begin(Serial,AudioLogger::Info);
20+
AudioLogger::instance().begin(Serial,AudioLogger::Warning);
2121

2222
// setup effects
2323
effects.addEffect(adsr);
@@ -47,7 +47,7 @@ void loop() {
4747
// simulate key release
4848
if (millis()>timeout+1000){
4949
sine.setFrequency(freq);
50-
adsr.keyOn();
50+
adsr.keyOff();
5151
}
5252
// output audio
5353
copier.copy();

0 commit comments

Comments
 (0)