Hi,
I am trying to use the EQ from the SGTL5000 audio shield as a 7-band parametric eq. But I have trouble with the eqFilter() function (or calcBiquad()). calcBiquad() seems to have not much documentation, so one of my problem might be using a wrong parameter range. Here is my code:
Header of a new class inherits from AudioControlSGTL5000:
... and the class implementation:
Here is a piece of code which uses this class:
But I am unsure what is the range and unit for Q and peakGainDB? Also my program crashes when running eqFilter(band, filter)
Has anyone an idea what I am doing wrong?
If it is important: The program runs on a T_4.1.
TIA, Holger
I am trying to use the EQ from the SGTL5000 audio shield as a 7-band parametric eq. But I have trouble with the eqFilter() function (or calcBiquad()). calcBiquad() seems to have not much documentation, so one of my problem might be using a wrong parameter range. Here is my code:
Header of a new class inherits from AudioControlSGTL5000:
Code:
class AudioControlSGTL5000Plus : public AudioControlSGTL5000
{
public:
AudioControlSGTL5000Plus(uint8_t n = 7) {
num_bands = constrain(n, 1, 7);
init_parametric_eq();
};
void setEQType(uint8_t band, uint8_t ft);
void setEQFc(uint8_t band, float frq);
void setEQQ(uint8_t band, float q);
void setEQGain(uint8_t band, float gain);
void commitFilter(uint8_t band);
private:
void init_parametric_eq(void);
uint8_t num_bands;
uint8_t* filter_type;
float* Fc;
float* Q;
float* peakGainDB;
};
#define EQ_TYPE_0 FILTER_PARAEQ
#define EQ_CENTER_FRQ_0 50.0
#define EQ_Q_0 1.0
#define EQ_TYPE_1 FILTER_PARAEQ
#define EQ_CENTER_FRQ_1 120.0
#define EQ_Q_1 1.0
#define EQ_TYPE_2 FILTER_PARAEQ
#define EQ_CENTER_FRQ_2 220.0
#define EQ_Q_2 1.0
#define EQ_TYPE_3 FILTER_PARAEQ
#define EQ_CENTER_FRQ_3 1000.0
#define EQ_Q_3 1.0
#define EQ_TYPE_4 FILTER_PARAEQ
#define EQ_CENTER_FRQ_4 2000.0
#define EQ_Q_4 1.0
#define EQ_TYPE_5 FILTER_PARAEQ
#define EQ_CENTER_FRQ_5 7000.0
#define EQ_Q_5 1.0
#define EQ_TYPE_6 FILTER_PARAEQ
#define EQ_CENTER_FRQ_6 10000.0
#define EQ_Q_6 1.0
... and the class implementation:
Code:
void AudioControlSGTL5000Plus::init_parametric_eq(void)
{
//eqSelect(PARAMETRIC_EQUALIZER);
//eqFilterCount(num_bands);
filter_type = new uint8_t[num_bands];
Fc = new float[num_bands];
Q = new float[num_bands];
peakGainDB = new float[num_bands];
setEQType(1, EQ_TYPE_0);
setEQFc(1, EQ_CENTER_FRQ_0);
setEQQ(1, EQ_Q_0);
setEQGain(1, 0.0);
if (num_bands > 1)
{
setEQType(2, EQ_TYPE_1);
setEQFc(2, EQ_CENTER_FRQ_1);
setEQQ(2, EQ_Q_1);
setEQGain(2, 0.0);
commitFilter(7);
}
if (num_bands > 2)
{
setEQType(3, EQ_TYPE_2);
setEQFc(3, EQ_CENTER_FRQ_2);
setEQQ(3, EQ_Q_2);
setEQGain(3, 0.0);
commitFilter(7);
}
if (num_bands > 3)
{
setEQType(4, EQ_TYPE_3);
setEQFc(4, EQ_CENTER_FRQ_3);
setEQQ(4, EQ_Q_3);
setEQGain(4, 0.0);
commitFilter(7);
}
if (num_bands > 4)
{
setEQType(5, EQ_TYPE_4);
setEQFc(5, EQ_CENTER_FRQ_4);
setEQQ(5, EQ_Q_4);
setEQGain(5, 0.0);
commitFilter(7);
}
if (num_bands > 5)
{
setEQType(6, EQ_TYPE_5);
setEQFc(6, EQ_CENTER_FRQ_5);
setEQQ(6, EQ_Q_5);
setEQGain(6, 0.0);
commitFilter(7);
}
if (num_bands > 6)
{
setEQType(7, EQ_TYPE_6);
setEQFc(7, EQ_CENTER_FRQ_6);
setEQQ(7, EQ_Q_6);
setEQGain(7, 0.0);
commitFilter(7);
}
}
void AudioControlSGTL5000Plus::setEQType(uint8_t band, uint8_t ft)
{
if (filter_type)
{
band = constrain(band, 1, num_bands);
filter_type[band - 1] = ft;
}
}
void AudioControlSGTL5000Plus::setEQFc(uint8_t band, float frq)
{
if (Fc)
{
band = constrain(band, 1, num_bands);
Fc[band - 1] = frq;
}
}
void AudioControlSGTL5000Plus::setEQQ(uint8_t band, float q)
{
if (Q)
{
band = constrain(band, 1, num_bands);
Q[band - 1] = q;
}
}
void AudioControlSGTL5000Plus::setEQGain(uint8_t band, float gain)
{
if (peakGainDB)
{
band = constrain(band, 1, num_bands);
peakGainDB[band - 1] = gain;
}
}
void AudioControlSGTL5000Plus::commitFilter(uint8_t band)
{
int filter[5] = {0, 0, 0, 0, 0};
band = constrain(band, 1, num_bands);
calcBiquad(filter_type[band - 1], Fc[band - 1], peakGainDB[band - 1], Q[band - 1], 524288, AUDIO_SAMPLE_RATE, filter);
eqFilter(band, filter);
}
Here is a piece of code which uses this class:
Code:
...
AudioControlSGTL5000Plus sgtl5000(7);
...
sgtl5000.setEQFc(1, 1000.0);
sgtl5000.setEQGain(1, 3.0);
sgtl5000.setEQQ(1,0 6.0);
sgtl5000.commitFilter(1);
...
But I am unsure what is the range and unit for Q and peakGainDB? Also my program crashes when running eqFilter(band, filter)
Has anyone an idea what I am doing wrong?
If it is important: The program runs on a T_4.1.
TIA, Holger