1 /*
2  * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3  *           (C) 2020 Vladimir Sadovnikov <sadko4u@gmail.com>
4  *
5  * This file is part of lsp-plugins
6  * Created on: 1 февр. 2018 г.
7  *
8  * lsp-plugins is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU Lesser General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * any later version.
12  *
13  * lsp-plugins is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License
19  * along with lsp-plugins. If not, see <https://www.gnu.org/licenses/>.
20  */
21 
22 #ifndef CORE_FILTERS_COMMON_H_
23 #define CORE_FILTERS_COMMON_H_
24 
25 #include <core/types.h>
26 
27 namespace lsp
28 {
29     enum filter_type_t
30     {
31         // Disabled filter
32         FLT_NONE,
33 
34         FLT_BT_AMPLIFIER,
35         FLT_MT_AMPLIFIER,
36 
37         // RLC filters
38         FLT_BT_RLC_LOPASS,
39         FLT_MT_RLC_LOPASS,
40         FLT_BT_RLC_HIPASS,
41         FLT_MT_RLC_HIPASS,
42         FLT_BT_RLC_LOSHELF,
43         FLT_MT_RLC_LOSHELF,
44         FLT_BT_RLC_HISHELF,
45         FLT_MT_RLC_HISHELF,
46         FLT_BT_RLC_BELL,
47         FLT_MT_RLC_BELL,
48         FLT_BT_RLC_RESONANCE,
49         FLT_MT_RLC_RESONANCE,
50         FLT_BT_RLC_NOTCH,
51         FLT_MT_RLC_NOTCH,
52         FLT_BT_RLC_ALLPASS,
53         FLT_MT_RLC_ALLPASS,
54         FLT_BT_RLC_ALLPASS2,
55         FLT_MT_RLC_ALLPASS2,
56         FLT_BT_RLC_LADDERPASS,
57         FLT_MT_RLC_LADDERPASS,
58         FLT_BT_RLC_LADDERREJ,
59         FLT_MT_RLC_LADDERREJ,
60         FLT_BT_RLC_BANDPASS,
61         FLT_MT_RLC_BANDPASS,
62         FLT_BT_RLC_ENVELOPE,
63         FLT_MT_RLC_ENVELOPE,
64 
65         // Butterworth-Chebyshev filters
66         FLT_BT_BWC_LOPASS,
67         FLT_MT_BWC_LOPASS,
68         FLT_BT_BWC_HIPASS,
69         FLT_MT_BWC_HIPASS,
70         FLT_BT_BWC_LOSHELF,
71         FLT_MT_BWC_LOSHELF,
72         FLT_BT_BWC_HISHELF,
73         FLT_MT_BWC_HISHELF,
74         FLT_BT_BWC_BELL,
75         FLT_MT_BWC_BELL,
76         FLT_BT_BWC_LADDERPASS,
77         FLT_MT_BWC_LADDERPASS,
78         FLT_BT_BWC_LADDERREJ,
79         FLT_MT_BWC_LADDERREJ,
80         FLT_BT_BWC_BANDPASS,
81         FLT_MT_BWC_BANDPASS,
82         FLT_BT_BWC_ALLPASS,
83         FLT_MT_BWC_ALLPASS,
84 
85         // Linkwitz–Riley filters
86         FLT_BT_LRX_LOPASS,
87         FLT_MT_LRX_LOPASS,
88         FLT_BT_LRX_HIPASS,
89         FLT_MT_LRX_HIPASS,
90         FLT_BT_LRX_LOSHELF,
91         FLT_MT_LRX_LOSHELF,
92         FLT_BT_LRX_HISHELF,
93         FLT_MT_LRX_HISHELF,
94         FLT_BT_LRX_BELL,
95         FLT_MT_LRX_BELL,
96         FLT_BT_LRX_LADDERPASS,
97         FLT_MT_LRX_LADDERPASS,
98         FLT_BT_LRX_LADDERREJ,
99         FLT_MT_LRX_LADDERREJ,
100         FLT_BT_LRX_BANDPASS,
101         FLT_MT_LRX_BANDPASS,
102         FLT_BT_LRX_ALLPASS,
103         FLT_MT_LRX_ALLPASS,
104 
105         // APO (textbook) Style digital biquad filters (DR stands for direct design: coefficient served directly in digital domain)
106         FLT_DR_APO_LOPASS,
107         FLT_DR_APO_HIPASS,
108         FLT_DR_APO_BANDPASS,
109         FLT_DR_APO_NOTCH,
110         FLT_DR_APO_ALLPASS,
111         FLT_DR_APO_ALLPASS2,
112         FLT_DR_APO_PEAKING,
113         FLT_DR_APO_LOSHELF,
114         FLT_DR_APO_HISHELF,
115         FLT_DR_APO_LADDERPASS,
116         FLT_DR_APO_LADDERREJ,
117     };
118 
119     typedef struct filter_params_t
120     {
121         size_t      nType;      // Filter class
122         float       fFreq;      // Frequency
123         float       fFreq2;     // Second frequency (for bandpass/allpass2 filter)
124         float       fGain;      // Gain
125         size_t      nSlope;     // Filter slope
126         float       fQuality;   // Quality factor
127     } filter_params_t;
128 
129     const size_t FILTER_BUFFER_MAX          = 0x1000;
130     const size_t FILTER_RANK_MIN            = 8;
131     const size_t FILTER_RANK_MAX            = 12;
132     const size_t FILTER_CONVOLUTION_MAX     = (1 << FILTER_RANK_MAX);
133     const size_t FILTER_CHAINS_MAX          = 0x20;
134 }
135 
136 #endif /* INCLUDE_CORE_FILTERS_COMMON_H_ */
137