static void setup_peak_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band) { g_return_if_fail (GST_AUDIO_FILTER (equ)->format.rate); { gdouble gain, omega, bw; gdouble alpha, alpha1, alpha2, b0; gain = arg_to_scale (band->gain); omega = calculate_omega (band->freq, GST_AUDIO_FILTER (equ)->format.rate); bw = calculate_bw (band, GST_AUDIO_FILTER (equ)->format.rate); if (bw == 0.0) goto out; alpha = tan (bw / 2.0); alpha1 = alpha * gain; alpha2 = alpha / gain; b0 = (1.0 + alpha2); band->a0 = (1.0 + alpha1) / b0; band->a1 = (-2.0 * cos (omega)) / b0; band->a2 = (1.0 - alpha1) / b0; band->b1 = (2.0 * cos (omega)) / b0; band->b2 = -(1.0 - alpha2) / b0; out: GST_INFO ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g", band->gain, band->width, band->freq, band->a0, band->a1, band->a2, band->b1, band->b2); } }
void AVFEqualizerBand::RecalculateParams() { double rate = mEQ->GetSampleRate(); mBypass = (rate == 0.0); if (mBypass) { // can't calculate until we have a sample rate return; } // recalculate coefficients based on new parameters double bw = calculate_bandwidth(m_Bandwidth, rate); if (bw <= 0.0) { // no bandwidth, no filter... mBypass = true; return; } double absGain = pow(10, m_Gain / 40); // convert dB to scale double omega = calculate_omega(mFrequency, rate); switch (mFilterType) { case Peak: SetupPeakFilter(omega, bw, absGain); break; case LowShelf: SetupLowShelfFilter(omega, bw, absGain); break; case HighShelf: SetupHighShelfFilter(omega, bw, absGain); break; } }
static void setup_high_shelf_filter (GstIirEqualizer * equ, GstIirEqualizerBand * band) { gint rate = GST_AUDIO_FILTER_RATE (equ); g_return_if_fail (rate); { gdouble gain, omega, bw; gdouble alpha, delta, b0; gdouble egp, egm; gain = arg_to_scale (band->gain); omega = calculate_omega (band->freq, rate); bw = calculate_bw (band, rate); if (bw == 0.0) goto out; egm = gain - 1.0; egp = gain + 1.0; alpha = tan (bw / 2.0); delta = 2.0 * sqrt (gain) * alpha; b0 = egp - egm * cos (omega) + delta; band->a0 = ((egp + egm * cos (omega) + delta) * gain) / b0; band->a1 = ((egm + egp * cos (omega)) * -2.0 * gain) / b0; band->a2 = ((egp + egm * cos (omega) - delta) * gain) / b0; band->b1 = ((egm - egp * cos (omega)) * -2.0) / b0; band->b2 = -((egp - egm * cos (omega) - delta)) / b0; out: GST_INFO ("gain = %5.1f, width= %7.2f, freq = %7.2f, a0 = %7.5g, a1 = %7.5g, a2=%7.5g b1 = %7.5g, b2 = %7.5g", band->gain, band->width, band->freq, band->a0, band->a1, band->a2, band->b1, band->b2); } }