@@ -126,6 +126,10 @@ class Equalizer3Bands : public ModifyingStream {
126
126
// / @return true if initialization was successful
127
127
bool begin (ConfigEqualizer3Bands &config) {
128
128
p_cfg = &config;
129
+ return begin ();
130
+ }
131
+
132
+ bool begin (){
129
133
if (p_cfg->channels > max_state_count) {
130
134
if (state != nullptr ) delete[] state;
131
135
state = new EQSTATE[p_cfg->channels ];
@@ -143,9 +147,14 @@ class Equalizer3Bands : public ModifyingStream {
143
147
state[j].hf = 2 * sin ((float )PI * ((float )p_cfg->freq_high /
144
148
(float )p_cfg->sample_rate ));
145
149
}
150
+ is_active = true ;
146
151
return true ;
147
152
}
148
153
154
+ void end (){
155
+ is_active = false ;
156
+ }
157
+
149
158
// / Called automatically when audio format changes
150
159
// / @param info New audio format information
151
160
virtual void setAudioInfo (AudioInfo info) override {
@@ -188,6 +197,7 @@ class Equalizer3Bands : public ModifyingStream {
188
197
}
189
198
190
199
protected:
200
+ bool is_active = false ; // /< Indicates if the equalizer is active
191
201
ConfigEqualizer3Bands cfg; // /< Default configuration instance
192
202
ConfigEqualizer3Bands *p_cfg = &cfg; // /< Pointer to active configuration
193
203
const float vsa = (1.0 / 4294967295.0 ); // /< Very small amount for denormal fix
@@ -222,10 +232,11 @@ class Equalizer3Bands : public ModifyingStream {
222
232
// / @param data Pointer to audio data buffer (modified in-place)
223
233
// / @param len Length of data buffer in bytes
224
234
void filterSamples (const uint8_t *data, size_t len) {
225
- if (state == nullptr ){
226
- LOGE (" You need to call begin() before using the equalizer" );
227
- return ;
228
- }
235
+ // no filter if not active
236
+ if (!is_active) return ;
237
+
238
+
239
+ // process samples
229
240
switch (p_cfg->bits_per_sample ) {
230
241
case 16 : {
231
242
int16_t *p_dataT = (int16_t *)data;
@@ -378,9 +389,14 @@ class Equalizer3BandsPerChannel : public ModifyingStream {
378
389
state[j].lf = 2 * sin ((float )PI * ((float )freq_low[j] / (float )p_cfg->sample_rate ));
379
390
state[j].hf = 2 * sin ((float )PI * ((float )freq_high[j] / (float )p_cfg->sample_rate ));
380
391
}
392
+ is_active = true ;
381
393
return true ;
382
394
}
383
395
396
+ void end () override {
397
+ is_active = false ;
398
+ }
399
+
384
400
virtual void setAudioInfo (AudioInfo info) override {
385
401
p_cfg->sample_rate = info.sample_rate ;
386
402
p_cfg->channels = info.channels ;
@@ -483,6 +499,7 @@ class Equalizer3BandsPerChannel : public ModifyingStream {
483
499
}
484
500
485
501
protected:
502
+ bool is_active = false ;
486
503
ConfigEqualizer3Bands cfg; // /< Default configuration instance
487
504
ConfigEqualizer3Bands *p_cfg = &cfg; // /< Pointer to active configuration
488
505
const float vsa = (1.0 / 4294967295.0 ); // /< Very small amount for denormal fix
@@ -550,10 +567,7 @@ class Equalizer3BandsPerChannel : public ModifyingStream {
550
567
// / @param data Pointer to audio data buffer
551
568
// / @param len Length of the data buffer in bytes
552
569
void filterSamples (const uint8_t *data, size_t len) {
553
- if (state == nullptr ){
554
- LOGE (" You need to call begin() before using the equalizer" );
555
- return ;
556
- }
570
+ if (!is_active) return ;
557
571
switch (p_cfg->bits_per_sample ) {
558
572
case 16 : {
559
573
int16_t *p_dataT = (int16_t *)data;
0 commit comments