71 protected readonly
double _q;
92 protected static readonly
double DefaultQ = 1.0 / Math.Sqrt(2);
108 protected BiQuad(
int sampleRate,
double frequency,
double q,
double gainDb)
112 throw new ArgumentOutOfRangeException(
"sampleRate");
116 throw new ArgumentOutOfRangeException(
"frequency");
120 throw new ArgumentOutOfRangeException(
"q");
122 if (sampleRate < frequency * 2)
124 throw new ArgumentOutOfRangeException(
"sampleRate",
"The sample rate has to be greater than or equal to 2 * frequency.");
140 double o = input *
A0 +
Z1;
153 for (
int i = 0; i < input.Length; i++)
186 var norm = 1 / (1 + k /
_q + k * k);
190 B1 = 2 * (k * k - 1) * norm;
191 B2 = (1 - k /
_q + k * k) * norm;
216 var norm = 1 / (1 + k /
_q + k * k);
220 B1 = 2 * (k * k - 1) * norm;
221 B2 = (1 - k /
_q + k * k) * norm;
246 double norm = 1 / (1 + k /
_q + k * k);
250 B1 = 2 * (k * k - 1) * norm;
251 B2 = (1 - k /
_q + k * k) * norm;
276 double norm = 1 / (1 + k /
_q + k * k);
277 A0 = (1 + k * k) * norm;
278 A1 = 2 * (k * k - 1) * norm;
281 B2 = (1 - k /
_q + k * k) * norm;
297 : base(sampleRate, frequency,
DefaultQ, gainDB)
305 const double sqrt2 = 1.4142135623730951;
307 double v = Math.Pow(10, Math.Abs(
_gainDB) / 20.0);
311 norm = 1 / (1 + sqrt2 * k + k * k);
312 A0 = (1 + Math.Sqrt(2 * v) * k + v * k * k) * norm;
313 A1 = 2 * (v * k * k - 1) * norm;
314 A2 = (1 - Math.Sqrt(2 * v) * k + v * k * k) * norm;
315 B1 = 2 * (k * k - 1) * norm;
316 B2 = (1 - sqrt2 * k + k * k) * norm;
320 norm = 1 / (1 + Math.Sqrt(2 * v) * k + v * k * k);
321 A0 = (1 + sqrt2 * k + k * k) * norm;
322 A1 = 2 * (k * k - 1) * norm;
323 A2 = (1 - sqrt2 * k + k * k) * norm;
324 B1 = 2 * (v * k * k - 1) * norm;
325 B2 = (1 - Math.Sqrt(2 * v) * k + v * k * k) * norm;
342 : base(sampleRate, frequency,
DefaultQ, gainDB)
350 const double sqrt2 = 1.4142135623730951;
352 double v = Math.Pow(10, Math.Abs(
_gainDB) / 20.0);
356 norm = 1 / (1 + sqrt2 * k + k * k);
357 A0 = (v + Math.Sqrt(2 * v) * k + k * k) * norm;
358 A1 = 2 * (k * k - v) * norm;
359 A2 = (v - Math.Sqrt(2 * v) * k + k * k) * norm;
360 B1 = 2 * (k * k - 1) * norm;
361 B2 = (1 - sqrt2 * k + k * k) * norm;
365 norm = 1 / (v + Math.Sqrt(2 * v) * k + k * k);
366 A0 = (1 + sqrt2 * k + k * k) * norm;
367 A1 = 2 * (k * k - 1) * norm;
368 A2 = (1 - sqrt2 * k + k * k) * norm;
369 B1 = 2 * (k * k - v) * norm;
370 B2 = (v - Math.Sqrt(2 * v) * k + k * k) * norm;
387 public PeakFilter(
int sampleRate,
double frequency,
double bandWidth,
double peakGainDB)
388 : base(sampleRate, frequency, bandWidth, peakGainDB)
397 double v = Math.Pow(10, Math.Abs(
_gainDB) / 20.0);
403 norm = 1 / (1 + 1 / q * k + k * k);
404 A0 = (1 + v / q * k + k * k) * norm;
405 A1 = 2 * (k * k - 1) * norm;
406 A2 = (1 - v / q * k + k * k) * norm;
408 B2 = (1 - 1 / q * k + k * k) * norm;
412 norm = 1 / (1 + v / q * k + k * k);
413 A0 = (1 + 1 / q * k + k * k) * norm;
414 A1 = 2 * (k * k - 1) * norm;
415 A2 = (1 - 1 / q * k + k * k) * norm;
417 B2 = (1 - v / q * k + k * k) * norm;
Used to apply a bandpass-filter to a signal.
BandpassFilter(int sampleRate, double frequency)
Initializes a new instance of the BandpassFilter class.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.
Represents a biquad-filter.
const double DefaultGainDb
void Process(float[] input)
Processes multiple input samples.
readonly double _frequency
readonly double _q
The q value.
readonly double _gainDB
The gain value in dB.
float Process(float input)
Processes a single input sample and returns the result.
readonly int _sampleRate
Gets the sample rate.
BiQuad(int sampleRate, double frequency, double q, double gainDb)
Initializes a new instance of the BiQuad class.
static readonly double DefaultQ
abstract void CalculateBiQuadCoefficients()
Calculates all coefficients.
Used to apply a highshelf-filter to a signal.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.
HighShelfFilter(int sampleRate, double frequency, double gainDB)
Initializes a new instance of the HighShelfFilter class.
Used to apply a highpass-filter to a signal.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.
HighpassFilter(int sampleRate, double frequency)
Initializes a new instance of the HighpassFilter class.
Used to apply a lowshelf-filter to a signal.
LowShelfFilter(int sampleRate, double frequency, double gainDB)
Initializes a new instance of the LowShelfFilter class.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.
Used to apply a lowpass-filter to a signal.
LowpassFilter(int sampleRate, double frequency)
Initializes a new instance of the LowpassFilter class.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.
Used to apply a notch-filter to a signal.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.
NotchFilter(int sampleRate, double frequency)
Initializes a new instance of the NotchFilter class.
Used to apply an peak-filter to a signal.
PeakFilter(int sampleRate, double frequency, double bandWidth, double peakGainDB)
Initializes a new instance of the PeakFilter class.
override void CalculateBiQuadCoefficients()
Calculates all coefficients.