I am writing a program to control VolumIO based off another members work here on a Raspberry Pi.
Difference is, I am hooking an IS31AP2111 Power Amplifier IC into the Pi. it has its own I2S receiver that is compatible with all 3 protocols. Still not sure about the Master Clock yet.
anyways, it has a built in parametric EQ that is setup with biquad coefficients. I found some Javascript code that will generate the coefficients, but I am not sure how to convert the math into something that B4X can handle.
Here is the code for JS: (only posting code relevant to what I want to do:
The code conversion seems streight forward for the Select case statement becuase it is almost a copy and paste. Problem is the value for K and value for V is a Math.Pow and Math.Tan which I have no idea what that does or how to convert to b4X.
any ideas?
Difference is, I am hooking an IS31AP2111 Power Amplifier IC into the Pi. it has its own I2S receiver that is compatible with all 3 protocols. Still not sure about the Master Clock yet.
anyways, it has a built in parametric EQ that is setup with biquad coefficients. I found some Javascript code that will generate the coefficients, but I am not sure how to convert the math into something that B4X can handle.
Here is the code for JS: (only posting code relevant to what I want to do:
B4X:
function calcBiquad(type, Fc, Fs, Q, peakGain, plotType) {
var a0,a1,a2,b1,b2,norm;
var ymin, ymax, minVal, maxVal;
var V = Math.pow(10, Math.abs(peakGain) / 20);
var K = Math.tan(Math.PI * Fc / Fs);
switch (type) {
case "peak":
if (peakGain >= 0) {
norm = 1 / (1 + 1/Q * K + K * K);
a0 = (1 + V/Q * K + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = (1 - V/Q * K + K * K) * norm;
b1 = a1;
b2 = (1 - 1/Q * K + K * K) * norm;
}
else {
norm = 1 / (1 + V/Q * K + K * K);
a0 = (1 + 1/Q * K + K * K) * norm;
a1 = 2 * (K * K - 1) * norm;
a2 = (1 - 1/Q * K + K * K) * norm;
b1 = a1;
b2 = (1 - V/Q * K + K * K) * norm;
}
break;
}
// list coefficients
var coefsList = "a0 = " + a0 + "\n";
coefsList += "a1 = " + a1 + "\n";
coefsList += "a2 = " + a2 + "\n";
coefsList += "b1 = " + b1 + "\n";
coefsList += "b2 = " + b2;
var taNode = document.getElementById("biquad_coefsList");
// remove existing child txt node
while (taNode.firstChild)
taNode.removeChild(taNode.firstChild);
var listNode = document.createTextNode(coefsList);
taNode.appendChild(listNode);
}
The code conversion seems streight forward for the Select case statement becuase it is almost a copy and paste. Problem is the value for K and value for V is a Math.Pow and Math.Tan which I have no idea what that does or how to convert to b4X.
any ideas?