4 #include "AudioConfig.h"
5 #include "AudioTools/CoreAudio/AudioOutput.h"
6 #include "AudioTools/CoreAudio/AudioStreams.h"
38 float gain_medium = 1.0;
39 float gain_high = 1.0;
65 if (state !=
nullptr)
delete[] state;
79 ConfigEquilizer3Bands &defaultConfig() {
return config(); }
81 bool begin(ConfigEquilizer3Bands &config) {
83 if (p_cfg->
channels > max_state_count) {
84 if (state !=
nullptr)
delete[] state;
85 state =
new EQSTATE[p_cfg->
channels];
90 for (
int j = 0; j < max_state_count; j++) {
91 memset(&state[j], 0,
sizeof(EQSTATE));
96 sin((
float)PI * ((
float)p_cfg->freq_low / (
float)p_cfg->
sample_rate));
97 state[j].hf = 2 * sin((
float)PI * ((
float)p_cfg->freq_high /
110 size_t write(
const uint8_t *data,
size_t len)
override {
111 filterSamples(data, len);
112 return p_print->write(data, len);
115 int availableForWrite()
override {
return p_print->availableForWrite(); }
120 if (p_stream !=
nullptr) {
121 result = p_stream->readBytes(data, len);
122 filterSamples(data, len);
127 int available()
override {
128 return p_stream !=
nullptr ? p_stream->available() : 0;
132 ConfigEquilizer3Bands cfg;
133 ConfigEquilizer3Bands *p_cfg = &cfg;
134 const float vsa = (1.0 / 4294967295.0);
135 Print *p_print =
nullptr;
136 Stream *p_stream =
nullptr;
139 int max_state_count = 0;
163 void filterSamples(
const uint8_t *data,
size_t len) {
164 switch (p_cfg->bits_per_sample) {
166 int16_t *p_dataT = (int16_t *)data;
167 size_t sample_count = len /
sizeof(int16_t);
168 for (
size_t j = 0; j < sample_count; j += p_cfg->channels) {
169 for (
int ch = 0; ch < p_cfg->channels; ch++) {
175 int24_t *p_dataT = (int24_t *)data;
176 size_t sample_count = len /
sizeof(int24_t);
177 for (
size_t j = 0; j < sample_count; j += p_cfg->channels) {
178 for (
int ch = 0; ch < p_cfg->channels; ch++) {
184 int32_t *p_dataT = (int32_t *)data;
185 size_t sample_count = len /
sizeof(int32_t);
186 for (
size_t j = 0; j < sample_count; j += p_cfg->channels) {
187 for (
int ch = 0; ch < p_cfg->channels; ch++) {
194 LOGE(
"Only 16 bits supported: %d", p_cfg->bits_per_sample);
201 float sample(EQSTATE &es,
float sample) {
205 es.f1p0 += (es.lf * (sample - es.f1p0)) + vsa;
206 es.f1p1 += (es.lf * (es.f1p0 - es.f1p1));
207 es.f1p2 += (es.lf * (es.f1p1 - es.f1p2));
208 es.f1p3 += (es.lf * (es.f1p2 - es.f1p3));
213 es.f2p0 += (es.hf * (sample - es.f2p0)) + vsa;
214 es.f2p1 += (es.hf * (es.f2p0 - es.f2p1));
215 es.f2p2 += (es.hf * (es.f2p1 - es.f2p2));
216 es.f2p3 += (es.hf * (es.f2p2 - es.f2p3));
218 h = es.sdm3 - es.f2p3;
220 m = es.sdm3 - (h + l);
222 l *= p_cfg->gain_low;
223 m *= p_cfg->gain_medium;
224 h *= p_cfg->gain_high;