iPlug2 - C++ Audio Plug-in Framework
Loading...
Searching...
No Matches
DCBlocker.h
1/*
2 ==============================================================================
3
4 This file is part of the iPlug 2 library. Copyright (C) the iPlug 2 developers.
5
6 See LICENSE.txt for more info.
7
8 ==============================================================================
9*/
10#pragma once
11
12#include "denormal.h"
13#include "IPlugConstants.h"
14
15BEGIN_IPLUG_NAMESPACE
16
17template<typename T, int NC = 1>
19{
20private:
21 // one pole IIR
22 // y[n] = x[n] + a[n] * y[n-1]
23 class rpole {
24 T y_m1 = 0;
25 public:
26 inline T process(T x, T a) {
27 const T y = y_m1 = x + a * y_m1;
28 denormal_fix(&y_m1);
29 return y;
30 }
31 };
32
33 // one zero FIR
34 // y[n] = x[n] - b[n] * x[n-1]
35 class rzero {
36 T x_m1 = 0;
37 public:
38 inline T process(T x, T b) {
39 const T y = x - b * x_m1;
40 x_m1 = x;
41 denormal_fix(&x_m1);
42 return y;
43 }
44 };
45
46 rpole mPole[NC];
47 rzero mZero[NC];
48
49public:
50
51 void ProcessBlock(T** inputs, T** outputs, int nChans, int nFrames)
52 {
53 assert(nChans <= NC);
54
55 for (auto s=0; s<nFrames; s++)
56 {
57 for (auto c = 0; c < nChans; c++)
58 {
59 const auto x = inputs[c][s];
60 outputs[c][s] = mPole[c].process(mZero[c].process(x, T(1.0)), T(0.995));
61 }
62 }
63 }
64
65} WDL_FIXALIGN;
66
67END_IPLUG_NAMESPACE
IPlug Constant definitions, Types, magic numbers.