using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; /* @author Geir K. Nilsen (geir.kjetil.nilsen@gmail.com) 2017 */ namespace ParametricEqualizer { public class Section { private Filter filter; private double G0; private double G; private double GB; private double f0; private double Bf; private double fs; private double[][] coeffs; public Section(double f0, double Bf, double GB, double G0, double G, double fs) { this.f0 = f0; this.Bf = Bf; this.GB = GB; this.G0 = G0; this.G = G; this.fs = fs; this.coeffs = new double[2][]; this.coeffs[0] = new double[3]; this.coeffs[1] = new double[3]; double beta = Math.Tan(Bf / 2.0 * Math.PI / (fs / 2.0)) * Math.Sqrt(Math.Abs(Math.Pow(Math.Pow(10, GB / 20.0), 2.0) - Math.Pow(Math.Pow(10.0, G0 / 20.0), 2.0))) / Math.Sqrt(Math.Abs(Math.Pow(Math.Pow(10.0, G / 20.0), 2.0) - Math.Pow(Math.Pow(10.0, GB/20.0), 2.0))); coeffs[0][0] = (Math.Pow(10.0, G0 / 20.0) + Math.Pow(10.0, G/20.0) * beta) / (1 + beta); coeffs[0][1] = (-2 * Math.Pow(10.0, G0/20.0) * Math.Cos(f0 * Math.PI / (fs / 2.0))) / (1 + beta); coeffs[0][2] = (Math.Pow(10.0, G0/20) - Math.Pow(10.0, G/20.0) * beta) / (1 + beta); coeffs[1][0] = 1.0; coeffs[1][1] = -2 * Math.Cos(f0 * Math.PI / (fs / 2.0)) / (1 + beta); coeffs[1][2] = (1 - beta) / (1 + beta); filter = new Filter(coeffs[1].ToList(), coeffs[0].ToList()); } public List run(List x, out List y) { filter.apply(x, out y); return y; } } }