From 5d9d16e182d254beeb41c76fc27a303294436cbe Mon Sep 17 00:00:00 2001 From: Holger Wirtz Date: Thu, 16 Sep 2021 11:18:03 +0200 Subject: [PATCH] Fixed EQ. --- MicroDexed.ino | 15 ++++++--------- UI.hpp | 16 ++++++++-------- control_sgtl5000plus.cpp | 32 +++++++++++++++++--------------- control_sgtl5000plus.h | 17 +++++++++-------- 4 files changed, 40 insertions(+), 40 deletions(-) diff --git a/MicroDexed.ino b/MicroDexed.ino index 98787b2..a20b028 100644 --- a/MicroDexed.ino +++ b/MicroDexed.ino @@ -2317,17 +2317,20 @@ void set_fx_params(void) #endif #ifdef SGTL5000_AUDIO_ENHANCE - sgtl5000.setEQGain(1, mapfloat(configuration.fx.eq_1, EQ_1_MIN, EQ_1_MAX, -9.9, 9.9)); + sgtl5000.setEQFc(1, float(configuration.fx.eq_1)); sgtl5000.setEQGain(2, mapfloat(configuration.fx.eq_2, EQ_2_MIN, EQ_2_MAX, -9.9, 9.9)); sgtl5000.setEQGain(3, mapfloat(configuration.fx.eq_3, EQ_3_MIN, EQ_3_MAX, -9.9, 9.9)); sgtl5000.setEQGain(4, mapfloat(configuration.fx.eq_4, EQ_4_MIN, EQ_4_MAX, -9.9, 9.9)); sgtl5000.setEQGain(5, mapfloat(configuration.fx.eq_5, EQ_5_MIN, EQ_5_MAX, -9.9, 9.9)); sgtl5000.setEQGain(6, mapfloat(configuration.fx.eq_6, EQ_6_MIN, EQ_6_MAX, -9.9, 9.9)); - sgtl5000.setEQGain(7, mapfloat(configuration.fx.eq_7, EQ_7_MIN, EQ_7_MAX, -9.9, 9.9)); -#ifdef DEBUG + sgtl5000.setEQFc(7, float(configuration.fx.eq_7)); for (uint8_t band = 1; band <= 7; band++) + { + sgtl5000.commitFilter(band); +#ifdef DEBUG sgtl5000.show_params(band); #endif + } #endif init_MIDI_send_CC(); @@ -2396,12 +2399,6 @@ float midi_volume_transform(uint8_t midi_amp) float volume_transform(float amp) { -#ifdef DEBUG - Serial.print(F("amp=")); - Serial.print(amp, DEC); - Serial.print(F(" transformed_amp=")); - Serial.println(powf(amp, 4), 3); -#endif return powf(amp, 4); } diff --git a/UI.hpp b/UI.hpp index ca3f0b2..0c97bff 100644 --- a/UI.hpp +++ b/UI.hpp @@ -8641,7 +8641,7 @@ void UI_func_eq_1(uint8_t param) } } lcd_display_meter_int("EQ Low-Cut [Hz]", configuration.fx.eq_1, 1.0, 0.0, EQ_1_MIN, EQ_1_MAX, 3, false, false, true); - sgtl5000.setEQFc(1, configuration.fx.eq_1); + sgtl5000.setEQFc(1, float(configuration.fx.eq_1)); sgtl5000.setEQGain(1, 6.0); sgtl5000.commitFilter(1); #ifdef DEBUG @@ -8689,7 +8689,7 @@ void UI_func_eq_2(uint8_t param) configuration.fx.eq_2 = constrain(configuration.fx.eq_2 - ENCODER[ENC_R].speed(), EQ_2_MIN, EQ_2_MAX); } } - lcd_display_meter_float("EQ 120Hz", configuration.fx.eq_2, 0.1, 0.0, EQ_2_MIN, EQ_2_MAX, 1, 1, false, true, true); + lcd_display_meter_float("EQ 120Hz [dB]", configuration.fx.eq_2, 0.1, 0.0, EQ_2_MIN, EQ_2_MAX, 1, 1, false, true, true); sgtl5000.setEQGain(2, mapfloat(configuration.fx.eq_2, EQ_2_MIN, EQ_2_MAX, -9.9, 9.9)); sgtl5000.commitFilter(2); #ifdef DEBUG @@ -8737,7 +8737,7 @@ void UI_func_eq_3(uint8_t param) configuration.fx.eq_3 = constrain(configuration.fx.eq_3 - ENCODER[ENC_R].speed(), EQ_3_MIN, EQ_3_MAX); } } - lcd_display_meter_float("EQ 220Hz", configuration.fx.eq_3, 0.1, 0.0, EQ_3_MIN, EQ_3_MAX, 1, 1, false, true, true); + lcd_display_meter_float("EQ 220Hz [dB]", configuration.fx.eq_3, 0.1, 0.0, EQ_3_MIN, EQ_3_MAX, 1, 1, false, true, true); sgtl5000.setEQGain(3, mapfloat(configuration.fx.eq_3, EQ_3_MIN, EQ_3_MAX, -9.9, 9.9)); sgtl5000.commitFilter(3); #ifdef DEBUG @@ -8785,7 +8785,7 @@ void UI_func_eq_4(uint8_t param) configuration.fx.eq_4 = constrain(configuration.fx.eq_4 - ENCODER[ENC_R].speed(), EQ_4_MIN, EQ_4_MAX); } } - lcd_display_meter_float("EQ 1000Hz", configuration.fx.eq_4, 0.1, 0.0, EQ_4_MIN, EQ_4_MAX, 1, 1, false, true, true); + lcd_display_meter_float("EQ 1000Hz [dB]", configuration.fx.eq_4, 0.1, 0.0, EQ_4_MIN, EQ_4_MAX, 1, 1, false, true, true); sgtl5000.setEQGain(4, mapfloat(configuration.fx.eq_4, EQ_4_MIN, EQ_4_MAX, -9.9, 9.9)); sgtl5000.commitFilter(4); #ifdef DEBUG @@ -8833,7 +8833,7 @@ void UI_func_eq_5(uint8_t param) configuration.fx.eq_5 = constrain(configuration.fx.eq_5 - ENCODER[ENC_R].speed(), EQ_5_MIN, EQ_5_MAX); } } - lcd_display_meter_float("EQ 2000Hz", configuration.fx.eq_5, 0.1, 0.0, EQ_5_MIN, EQ_5_MAX, 1, 1, false, true, true); + lcd_display_meter_float("EQ 2000Hz [dB]", configuration.fx.eq_5, 0.1, 0.0, EQ_5_MIN, EQ_5_MAX, 1, 1, false, true, true); sgtl5000.setEQGain(5, mapfloat(configuration.fx.eq_5, EQ_5_MIN, EQ_5_MAX, -9.9, 9.9)); sgtl5000.commitFilter(5); #ifdef DEBUG @@ -8881,11 +8881,11 @@ void UI_func_eq_6(uint8_t param) configuration.fx.eq_6 = constrain(configuration.fx.eq_6 - ENCODER[ENC_R].speed(), EQ_6_MIN, EQ_6_MAX); } } - lcd_display_meter_float("EQ 7000Hz", configuration.fx.eq_6, 0.1, 0.0, EQ_6_MIN, EQ_6_MAX, 1, 1, false, true, true); + lcd_display_meter_float("EQ 7000Hz [dB]", configuration.fx.eq_6, 0.1, 0.0, EQ_6_MIN, EQ_6_MAX, 1, 1, false, true, true); sgtl5000.setEQGain(6, mapfloat(configuration.fx.eq_6, EQ_6_MIN, EQ_6_MAX, -9.9, 9.9)); sgtl5000.commitFilter(6); #ifdef DEBUG - sgtl5000.show_params(1); + sgtl5000.show_params(6); #endif } @@ -8930,7 +8930,7 @@ void UI_func_eq_7(uint8_t param) } } lcd_display_meter_float("EQ High-Cut[kHz]", configuration.fx.eq_7, 1.0, 0.0, EQ_7_MIN, EQ_7_MAX, 3, 1, false, false, true); - sgtl5000.setEQFc(7, configuration.fx.eq_7); + sgtl5000.setEQFc(7, float(configuration.fx.eq_7) * 1000.0); sgtl5000.commitFilter(7); #ifdef DEBUG sgtl5000.show_params(7); diff --git a/control_sgtl5000plus.cpp b/control_sgtl5000plus.cpp index e2df989..2d6aaa1 100644 --- a/control_sgtl5000plus.cpp +++ b/control_sgtl5000plus.cpp @@ -38,9 +38,11 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) Q = new float[num_bands]; peakGainDB = new float[num_bands]; + _enabled = true; + setEQType(1, EQ_TYPE_0); setEQFc(1, EQ_CENTER_FRQ_0); - setEQQ(1, EQ_Q_0); + setEQBandwidth(1, EQ_BW_0); setEQGain(1, 0.0); commitFilter(1); @@ -48,7 +50,7 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) { setEQType(2, EQ_TYPE_1); setEQFc(2, EQ_CENTER_FRQ_1); - setEQQ(2, EQ_Q_1); + setEQBandwidth(2, EQ_BW_1); setEQGain(2, 0.0); commitFilter(2); } @@ -57,7 +59,7 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) { setEQType(3, EQ_TYPE_2); setEQFc(3, EQ_CENTER_FRQ_2); - setEQQ(3, EQ_Q_2); + setEQBandwidth(3, EQ_BW_2); setEQGain(3, 0.0); commitFilter(3); } @@ -66,7 +68,7 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) { setEQType(4, EQ_TYPE_3); setEQFc(4, EQ_CENTER_FRQ_3); - setEQQ(4, EQ_Q_3); + setEQBandwidth(4, EQ_BW_3); setEQGain(4, 0.0); commitFilter(4); } @@ -75,7 +77,7 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) { setEQType(5, EQ_TYPE_4); setEQFc(5, EQ_CENTER_FRQ_4); - setEQQ(5, EQ_Q_4); + setEQBandwidth(5, EQ_BW_4); setEQGain(5, 0.0); commitFilter(5); } @@ -84,7 +86,7 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) { setEQType(6, EQ_TYPE_5); setEQFc(6, EQ_CENTER_FRQ_5); - setEQQ(6, EQ_Q_5); + setEQBandwidth(6, EQ_BW_5); setEQGain(6, 0.0); commitFilter(6); } @@ -93,17 +95,15 @@ void AudioControlSGTL5000Plus::init_parametric_eq(uint8_t n) { setEQType(7, EQ_TYPE_6); setEQFc(7, EQ_CENTER_FRQ_6); - setEQQ(7, EQ_Q_6); + setEQBandwidth(7, EQ_BW_6); setEQGain(7, 0.0); commitFilter(7); } - - _enabled = true; } void AudioControlSGTL5000Plus::setEQType(uint8_t band, uint8_t ft) { - if (filter_type && _enabled == true) + if (filter_type && _enabled != false) { band = constrain(band, 1, num_bands); filter_type[band - 1] = ft; @@ -112,7 +112,7 @@ void AudioControlSGTL5000Plus::setEQType(uint8_t band, uint8_t ft) void AudioControlSGTL5000Plus::setEQFc(uint8_t band, float frq) { - if (Fc && _enabled == true) + if (Fc && _enabled != false) { band = constrain(band, 1, num_bands); Fc[band - 1] = frq; @@ -121,7 +121,7 @@ void AudioControlSGTL5000Plus::setEQFc(uint8_t band, float frq) void AudioControlSGTL5000Plus::setEQQ(uint8_t band, float q) { - if (Q && _enabled == true) + if (Q && _enabled != false) { band = constrain(band, 1, num_bands); Q[band - 1] = q; @@ -132,7 +132,7 @@ void AudioControlSGTL5000Plus::setEQQ(uint8_t band, float q) // http://jdm12.ch/Audio/EQ_BPF-Q-bandwidth.asp void AudioControlSGTL5000Plus::setEQBandwidth(uint8_t band, float bw) { - if (Q && Fc && _enabled == true) + if (Q && Fc && _enabled != false) { band = constrain(band, 1, num_bands); Q[band - 1] = sqrt(pow(2, bw)) / (pow(2, bw) - 1); @@ -141,7 +141,7 @@ void AudioControlSGTL5000Plus::setEQBandwidth(uint8_t band, float bw) void AudioControlSGTL5000Plus::setEQGain(uint8_t band, float gain) { - if (peakGainDB && _enabled == true) + if (peakGainDB && _enabled != false) { band = constrain(band, 1, num_bands); peakGainDB[band - 1] = gain; @@ -169,7 +169,9 @@ void AudioControlSGTL5000Plus::show_params(uint8_t band) } else { - Serial.print(F("Band: ")); + band = constrain(band, 1, num_bands); + + Serial.print(F("[SGTL5000 EQ] Band: ")); Serial.print(band, DEC); Serial.print(F(" Type:")); Serial.print(filter_type[band - 1], DEC); diff --git a/control_sgtl5000plus.h b/control_sgtl5000plus.h index 672e037..8fb759a 100644 --- a/control_sgtl5000plus.h +++ b/control_sgtl5000plus.h @@ -30,37 +30,38 @@ #define EQ_TYPE_0 FILTER_HIPASS #define EQ_CENTER_FRQ_0 15.0 -#define EQ_Q_0 0.666667 +#define EQ_BW_0 2 #define EQ_TYPE_1 FILTER_LOSHELF #define EQ_CENTER_FRQ_1 120.0 -#define EQ_Q_1 0.126984 +#define EQ_BW_1 2 #define EQ_TYPE_2 FILTER_PARAEQ #define EQ_CENTER_FRQ_2 220.0 -#define EQ_Q_2 0.126984 +#define EQ_BW_2 2 #define EQ_TYPE_3 FILTER_PARAEQ #define EQ_CENTER_FRQ_3 1000.0 -#define EQ_Q_3 0.126984 +#define EQ_BW_3 2 #define EQ_TYPE_4 FILTER_PARAEQ #define EQ_CENTER_FRQ_4 2000.0 -#define EQ_Q_4 0.126984 +#define EQ_BW_4 2 #define EQ_TYPE_5 FILTER_HISHELF #define EQ_CENTER_FRQ_5 7000.0 -#define EQ_Q_5 0.126984 +#define EQ_BW_5 2 #define EQ_TYPE_6 FILTER_LOPASS #define EQ_CENTER_FRQ_6 18000.0 -#define EQ_Q_6 0.666667 +#define EQ_BW_6 2 class AudioControlSGTL5000Plus : public AudioControlSGTL5000 { public: - AudioControlSGTL5000Plus() { + AudioControlSGTL5000Plus(uint8_t n = 7) { _enabled = false; + num_bands = constrain(n, 1, 7); }; void setEQType(uint8_t band, uint8_t ft); void setEQFc(uint8_t band, float frq);