Code:
void setCoefficients(uint32_t stage, const int *coefficients);
void setCoefficients(uint32_t stage, const double *coefficients) {
int coef[5];
// 1073741824 bytes = 1 GB
// Google! Prob has something to do with memory allocation
// Ask MUS171 Professor
coef[0] = coefficients[0] * 1073741824.0;
coef[1] = coefficients[1] * 1073741824.0;
coef[2] = coefficients[2] * 1073741824.0;
coef[3] = coefficients[3] * 1073741824.0;
coef[4] = coefficients[4] * 1073741824.0;
setCoefficients(stage, coef);
}
// Compute common filter functions
// http://www.musicdsp.org/files/Audio-EQ-Cookbook.txt
void setLowpass(uint32_t stage, float frequency, float q = 0.7071) {
int coef[5];
double w0 = frequency * (2 * 3.141592654 / AUDIO_SAMPLE_RATE_EXACT);
double sinW0 = sin(w0);
double alpha = sinW0 / ((double)q * 2.0);
double cosW0 = cos(w0);
double scale = 1073741824.0 / (1.0 + alpha);
/* b0 */ coef[0] = ((1.0 - cosW0) / 2.0) * scale;
/* b1 */ coef[1] = (1.0 - cosW0) * scale;
/* b2 */ coef[2] = coef[0];
/* a1 */ coef[3] = (-2.0 * cosW0) * scale;
/* a2 */ coef[4] = (1.0 - alpha) * scale;
setCoefficients(stage, coef);
}
I understand that we are using bilinear transformation to obtain the coefficients. But I am not quite sure about the scaling factor here which is 1073741824.0. If someone could explain the reason that we include such number in the code, I would very much appreciate it. Thank you!!