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: 4 нояб. 2016 г.
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 PLUGINS_EXPANDER_H_
23 #define PLUGINS_EXPANDER_H_
24 
25 #include <metadata/plugins.h>
26 
27 #include <core/plugin.h>
28 #include <core/util/Bypass.h>
29 #include <core/util/Sidechain.h>
30 #include <core/util/MeterGraph.h>
31 #include <core/util/Delay.h>
32 #include <core/dynamics/Expander.h>
33 
34 namespace lsp
35 {
36     class expander_base: public plugin_t
37     {
38         protected:
39             enum c_mode_t
40             {
41                 EM_MONO,
42                 EM_STEREO,
43                 EM_LR,
44                 EM_MS
45             };
46 
47             enum sc_source_t
48             {
49                 SCT_INTERNAL,
50                 SCT_EXTERNAL
51             };
52 
53             enum sc_graph_t
54             {
55                 G_IN,
56                 G_SC,
57                 G_ENV,
58                 G_GAIN,
59                 G_OUT,
60 
61                 G_TOTAL
62             };
63 
64             enum sc_meter_t
65             {
66                 M_IN,
67                 M_SC,
68                 M_ENV,
69                 M_GAIN,
70                 M_CURVE,
71                 M_OUT,
72 
73                 M_TOTAL
74             };
75 
76             enum sync_t
77             {
78                 S_CURVE     = 1 << 0,
79 
80                 S_ALL       = S_CURVE
81             };
82 
83             typedef struct channel_t
84             {
85                 Bypass          sBypass;            // Bypass
86                 Sidechain       sSC;                // Sidechain module
87                 Equalizer       sSCEq;              // Sidechain equalizer
88                 Expander        sExp;               // Expansion module
89                 Delay           sDelay;             // Lookahead delay
90                 Delay           sCompDelay;         // Compensation delay
91                 Delay           sDryDelay;          // Dry delay
92                 MeterGraph      sGraph[G_TOTAL];    // Input meter graph
93 
94                 float          *vIn;                // Input data
95                 float          *vOut;               // Output data
96                 float          *vSc;                // Sidechain data
97                 float          *vEnv;               // Envelope data
98                 float          *vGain;              // Gain reduction data
99                 bool            bScListen;          // Listen sidechain
100                 size_t          nSync;              // Synchronization flags
101                 size_t          nScType;            // Sidechain mode
102                 float           fMakeup;            // Makeup gain
103                 float           fDryGain;           // Dry gain
104                 float           fWetGain;           // Wet gain
105                 float           fDotIn;             // Dot input gain
106                 float           fDotOut;            // Dot output gain
107 
108                 IPort          *pIn;                // Input port
109                 IPort          *pOut;               // Output port
110                 IPort          *pSC;                // Sidechain port
111 
112                 IPort          *pGraph[G_TOTAL];    // History graphs
113                 IPort          *pMeter[M_TOTAL];    // Meters
114 
115                 IPort          *pScType;            // Sidechain location
116                 IPort          *pScMode;            // Sidechain mode
117                 IPort          *pScLookahead;       // Sidechain lookahead
118                 IPort          *pScListen;          // Sidechain listen
119                 IPort          *pScSource;          // Sidechain source
120                 IPort          *pScReactivity;      // Sidechain reactivity
121                 IPort          *pScPreamp;          // Sidechain pre-amplification
122                 IPort          *pScHpfMode;         // Sidechain high-pass filter mode
123                 IPort          *pScHpfFreq;         // Sidechain high-pass filter frequency
124                 IPort          *pScLpfMode;         // Sidechain low-pass filter mode
125                 IPort          *pScLpfFreq;         // Sidechain low-pass filter frequency
126 
127                 IPort          *pMode;              // Mode
128                 IPort          *pAttackLvl;         // Attack level
129                 IPort          *pReleaseLvl;        // Release level
130                 IPort          *pAttackTime;        // Attack time
131                 IPort          *pReleaseTime;       // Release time
132                 IPort          *pRatio;             // Ratio
133                 IPort          *pKnee;              // Knee
134                 IPort          *pMakeup;            // Makeup
135 
136                 IPort          *pDryGain;           // Dry gain
137                 IPort          *pWetGain;           // Wet gain
138                 IPort          *pCurve;             // Curve graph
139                 IPort          *pReleaseOut;        // Output release level
140             } channel_t;
141 
142         protected:
143             size_t          nMode;          // Expander mode
144             bool            bSidechain;     // External side chain
145             channel_t      *vChannels;      // Expander channels
146             float          *vCurve;         // Expander curve
147             float          *vTime;          // Time points buffer
148             bool            bPause;         // Pause button
149             bool            bClear;         // Clear button
150             bool            bMSListen;      // Mid/Side listen
151             float           fInGain;        // Input gain
152             bool            bUISync;        // UI Sync
153             float_buffer_t *pIDisplay;      // Inline display buffer
154 
155             IPort          *pBypass;        // Bypass port
156             IPort          *pInGain;        // Input gain
157             IPort          *pOutGain;       // Output gain
158             IPort          *pPause;         // Pause gain
159             IPort          *pClear;         // Cleanup gain
160             IPort          *pMSListen;      // Mid/Side listen
161 
162             uint8_t        *pData;          // Expander data
163 
164         public:
165             expander_base(const plugin_metadata_t &metadata, bool sc, size_t mode);
166             virtual ~expander_base();
167 
168         public:
169             virtual void init(IWrapper *wrapper);
170             virtual void destroy();
171 
172             virtual void update_settings();
173             virtual void update_sample_rate(long sr);
174             virtual void ui_activated();
175 
176             virtual void process(size_t samples);
177             virtual bool inline_display(ICanvas *cv, size_t width, size_t height);
178     };
179 
180     class expander_mono: public expander_base, public expander_mono_metadata
181     {
182         public:
183             expander_mono();
184     };
185 
186     class expander_stereo: public expander_base, public expander_stereo_metadata
187     {
188         public:
189             expander_stereo();
190     };
191 
192     class expander_lr: public expander_base, public expander_lr_metadata
193     {
194         public:
195             expander_lr();
196     };
197 
198     class expander_ms: public expander_base, public expander_ms_metadata
199     {
200         public:
201             expander_ms();
202     };
203 
204     class sc_expander_mono: public expander_base, public sc_expander_mono_metadata
205     {
206         public:
207             sc_expander_mono();
208     };
209 
210     class sc_expander_stereo: public expander_base, public sc_expander_stereo_metadata
211     {
212         public:
213             sc_expander_stereo();
214     };
215 
216     class sc_expander_lr: public expander_base, public sc_expander_lr_metadata
217     {
218         public:
219             sc_expander_lr();
220     };
221 
222     class sc_expander_ms: public expander_base, public sc_expander_ms_metadata
223     {
224         public:
225             sc_expander_ms();
226     };
227 
228 }
229 
230 #endif /* PLUGINS_EXPANDER_H_ */
231