/// <summary> /// Calculates IIR. /// </summary> /// <param name="sample">sample rate</param> /// <param name="pBiquad">BiquadCoefficients pointer</param> public void BiQuad(ref Int16 sample, BiquadCoefficients *pBiquad) { // compute result double result = pBiquad->a0 * sample + pBiquad->a1 * pBiquad->x1 + pBiquad->a2 * pBiquad->x2 - pBiquad->a3 * pBiquad->y1 - pBiquad->a4 * pBiquad->y2; // shift x1 to x2, sample to x1 pBiquad->x2 = pBiquad->x1; pBiquad->x1 = sample; // shift y1 to y2, result to y1 pBiquad->y2 = pBiquad->y1; pBiquad->y1 = result; sample = (Int16)result; }
/// <summary> /// Calculate amplitude change in BiquadCoefficients. /// </summary> private unsafe void _RecalculateBiquadBand(ref BiquadCoefficients *b, double dbGain, double frequency) { // reduce the gain thresholds on energetic signals to reduce distortion.. if (!Settings.isEightBitSample) { dbGain *= .1f; } BiquadCoefficients *tmp = Bands.BiQuadFilter(FiltersType.PEQ, dbGain, frequency, Settings.SamplesPerSecond, 1); b->a0 = tmp->a0; b->a1 = tmp->a1; b->a2 = tmp->a2; b->a3 = tmp->a3; b->a4 = tmp->a4; Bands.FreeMem(tmp); tmp = null; }
/// <summary> /// /// </summary> /// <param name="b"></param> public void FreeMem(BiquadCoefficients *b) { Free(b); }
/// <summary>Release heap memory</summary> /// <param name="pmem">memory address</param> private void Free(BiquadCoefficients *b) { HeapFree(GetProcessHeap(), 0, b); }
private static extern bool HeapFree(IntPtr hHeap, uint dwFlags, BiquadCoefficients *lpMem);