Error_t RBJFilterSetCutoffD(RBJFilterD* filter, double cutoff) { filter->omega = HZ_TO_RAD(cutoff) / filter->sampleRate; RBJFilterUpdateD(filter); return NOERR; }
/* RBJFilterSetCutoff **************************************************/ Error_t RBJFilterSetCutoff(RBJFilter* filter, float cutoff) { filter->omega = HZ_TO_RAD(cutoff) / filter->sampleRate; RBJFilterUpdate(filter); return NOERR; }
RBJFilterD* RBJFilterInitD(Filter_t type, double cutoff, double sampleRate) { // Create the filter RBJFilterD* filter = (RBJFilterD*)malloc(sizeof(RBJFilterD)); if (filter) { // Initialization filter->type = type; filter->omega = HZ_TO_RAD(cutoff) / sampleRate; filter->Q = 1; filter->A = 1; filter->dbGain = 0; filter->sampleRate = sampleRate; // Initialize biquad double b[3] = {0, 0, 0}; double a[2] = {0, 0}; filter->biquad = BiquadFilterInitD(b, a); // Calculate coefficients RBJFilterUpdateD(filter); } return filter; }
/* RBJFilterInit **********************************************************/ RBJFilter* RBJFilterInit(Filter_t type, float cutoff, float sampleRate) { // Create the filter RBJFilter* filter = (RBJFilter*)malloc(sizeof(RBJFilter)); if (filter) { // Initialization filter->type = type; filter->omega = HZ_TO_RAD(cutoff) / sampleRate; //hzToRadians(cutoff, sampleRate); filter->Q = 1; filter->A = 1; filter->dbGain = 0; filter->sampleRate = sampleRate; // Initialize biquad float b[3] = {0, 0, 0}; float a[2] = {0, 0}; filter->biquad = BiquadFilterInit(b,a); // Calculate coefficients RBJFilterUpdate(filter); } return filter; }
Error_t RBJFilterSetParamsD(RBJFilterD* filter, Filter_t type, double cutoff, double Q) { filter->type = type; filter->omega = HZ_TO_RAD(cutoff) / filter->sampleRate; filter->Q = Q; RBJFilterUpdateD(filter); return NOERR; }
/* RBJFilterSetParams **************************************************/ Error_t RBJFilterSetParams(RBJFilter* filter, Filter_t type, float cutoff, float Q) { filter->type = type; filter->omega = HZ_TO_RAD(cutoff) / filter->sampleRate; filter->Q = Q; RBJFilterUpdate(filter); return NOERR; }
void ctss_calculate_biquad_coeff(CTSS_DSPNode *node, CTSS_BiquadType type, float freq, float dbGain, float bandwidth) { CTSS_BiquadState *state = node->state; float a0, a1, a2, b0, b1, b2; float A = powf(10.0f, dbGain / 40.0f); float omega = HZ_TO_RAD(freq); float sn = sinf(omega); float cs = cosf(omega); float alpha = sn * sinh(CT_LN2 / 2.0f * bandwidth * omega / sn); float beta = sqrtf(A + A); switch (type) { case LPF: default: b0 = (1.0f - cs) / 2.0f; b1 = 1.0f - cs; b2 = (1.0f - cs) / 2.0f; a0 = 1.0f + alpha; a1 = -2.0f * cs; a2 = 1.0f - alpha; break; case HPF: b0 = (1.0f + cs) / 2.0f; b1 = -(1.0f + cs); b2 = (1.0f + cs) / 2.0f; a0 = 1.0f + alpha; a1 = -2.0f * cs; a2 = 1.0f - alpha; break; case BPF: b0 = alpha; b1 = 0; b2 = -alpha; a0 = 1.0f + alpha; a1 = -2.0f * cs; a2 = 1.0f - alpha; break; case NOTCH: b0 = 1.0f; b1 = -2.0f * cs; b2 = 1.0f; a0 = 1.0f + alpha; a1 = -2.0f * cs; a2 = 1.0f - alpha; break; case PEQ: b0 = 1.0f + (alpha * A); b1 = -2.0f * cs; b2 = 1.0f - (alpha * A); a0 = 1.0f + (alpha / A); a1 = -2.0f * cs; a2 = 1.0f - (alpha / A); break; case LSH: b0 = A * ((A + 1.0f) - (A - 1.0f) * cs + beta * sn); b1 = 2.0f * A * ((A - 1.0f) - (A + 1.0f) * cs); b2 = A * ((A + 1.0f) - (A - 1.0f) * cs - beta * sn); a0 = (A + 1.0f) + (A - 1.0f) * cs + beta * sn; a1 = -2.0f * ((A - 1.0f) + (A + 1.0f) * cs); a2 = (A + 1.0f) + (A - 1.0f) * cs - beta * sn; break; case HSH: b0 = A * ((A + 1.0f) + (A - 1.0f) * cs + beta * sn); b1 = -2.0f * A * ((A - 1.0f) + (A + 1.0f) * cs); b2 = A * ((A + 1.0f) + (A - 1.0f) * cs - beta * sn); a0 = (A + 1.0f) - (A - 1.0f) * cs + beta * sn; a1 = 2.0f * ((A - 1.0f) - (A + 1.0f) * cs); a2 = (A + 1.0f) - (A - 1.0f) * cs - beta * sn; break; } a0 = 1.0f / a0; state->f[0] = b0 * a0; state->f[1] = b1 * a0; state->f[2] = b2 * a0; state->f[3] = a1 * a0; state->f[4] = a2 * a0; state->f[5] = state->f[6] = state->f[7] = state->f[8] = 0.0f; }