/// <summary> /// Gets a linear phase convolution filter that results in this EQ when applied. /// </summary> /// <param name="eq">Source <see cref="Equalizer"/></param> /// <param name="sampleRate">Sample rate of the target system the convolution filter could be used on</param> /// <param name="length">Length of the convolution filter in samples, must be a power of 2</param> /// <param name="gain">Signal voltage multiplier</param> /// <param name="initial">Custom initial spectrum to apply the EQ on - phases will be corrected, this is not convolved, /// and has to be twice the size of <paramref name="length"/></param> public static float[] GetLinearConvolution(this Equalizer eq, int sampleRate, int length = 1024, float gain = 1, Complex[] initial = null) { Complex[] filter = new Complex[length]; if (initial == null) { for (int i = 0; i < length; ++i) { filter[i].Real = i % 2 == 0 ? gain : -gain; // FFT of DiracDelta(x - length/2) } } else { for (int i = 0; i < length; ++i) { filter[i].Real = initial[i].Magnitude * (i % 2 == 0 ? gain : -gain); } } eq.Apply(filter, sampleRate); filter.InPlaceIFFT(); return(Measurements.GetRealPart(filter)); }
/// <summary> /// Generates peaking EQ filter sets that try to match <see cref="Equalizer"/> curves. /// </summary> public PeakingEqualizer(Equalizer source) => this.source = source;