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: 21 окт. 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_DYNA_PROCESSOR_H_ 23 #define PLUGINS_DYNA_PROCESSOR_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/DynamicProcessor.h> 33 34 namespace lsp 35 { 36 class dyna_processor_base: public plugin_t 37 { 38 protected: 39 enum c_mode_t 40 { 41 DYNA_MONO, 42 DYNA_STEREO, 43 DYNA_LR, 44 DYNA_MS 45 }; 46 47 enum sc_source_t 48 { 49 SCT_FEED_FORWARD, 50 SCT_FEED_BACK, 51 SCT_EXTERNAL 52 }; 53 54 enum sc_graph_t 55 { 56 G_IN, 57 G_SC, 58 G_ENV, 59 G_GAIN, 60 G_OUT, 61 62 G_TOTAL 63 }; 64 65 enum sc_meter_t 66 { 67 M_IN, 68 M_SC, 69 M_ENV, 70 M_GAIN, 71 M_CURVE, 72 M_OUT, 73 74 M_TOTAL 75 }; 76 77 enum sync_t 78 { 79 S_CURVE = 1 << 0, 80 S_MODEL = 1 << 1, 81 82 S_ALL = S_MODEL 83 }; 84 85 typedef struct channel_t 86 { 87 Bypass sBypass; // Bypass 88 Sidechain sSC; // Sidechain module 89 Equalizer sSCEq; // Sidechain equalizer 90 DynamicProcessor sProc; // Processor module 91 Delay sDelay; // Lookahead delay 92 Delay sCompDelay; // Compensation delay 93 Delay sDryDelay; // Dry delay 94 MeterGraph sGraph[G_TOTAL]; // Meter graph 95 96 float *vIn; // Input data 97 float *vOut; // Output data 98 float *vSc; // Sidechain data 99 float *vEnv; // Envelope data 100 float *vGain; // Gain reduction data 101 bool bScListen; // Listen sidechain 102 size_t nSync; // Synchronization flags 103 size_t nScType; // Sidechain mode 104 float fMakeup; // Makeup gain 105 float fFeedback; // Feedback 106 float fDryGain; // Dry gain 107 float fWetGain; // Wet gain 108 float fDotIn; // Dot input gain 109 float fDotOut; // Dot output gain 110 111 IPort *pIn; // Input port 112 IPort *pOut; // Output port 113 IPort *pSC; // Sidechain port 114 115 IPort *pGraph[G_TOTAL]; // History graphs 116 IPort *pMeter[M_TOTAL]; // Meters 117 118 IPort *pScType; // Sidechain location 119 IPort *pScMode; // Sidechain mode 120 IPort *pScLookahead; // Sidechain lookahead 121 IPort *pScListen; // Sidechain listen 122 IPort *pScSource; // Sidechain source 123 IPort *pScReactivity; // Sidechain reactivity 124 IPort *pScPreamp; // Sidechain pre-amplification 125 IPort *pScHpfMode; // Sidechain high-pass filter mode 126 IPort *pScHpfFreq; // Sidechain high-pass filter frequency 127 IPort *pScLpfMode; // Sidechain low-pass filter mode 128 IPort *pScLpfFreq; // Sidechain low-pass filter frequency 129 130 IPort *pDotOn[dyna_processor_base_metadata::DOTS]; // Dot enable 131 IPort *pThreshold[dyna_processor_base_metadata::DOTS]; // Threshold levels 132 IPort *pGain[dyna_processor_base_metadata::DOTS]; // Gain levels 133 IPort *pKnee[dyna_processor_base_metadata::DOTS]; // Knees levels 134 IPort *pAttackOn[dyna_processor_base_metadata::DOTS]; // Attack enable 135 IPort *pAttackLvl[dyna_processor_base_metadata::DOTS]; // Attack levels 136 IPort *pAttackTime[dyna_processor_base_metadata::RANGES]; // Attack time 137 IPort *pReleaseOn[dyna_processor_base_metadata::DOTS]; // Release enable 138 IPort *pReleaseLvl[dyna_processor_base_metadata::DOTS]; // Release levels 139 IPort *pReleaseTime[dyna_processor_base_metadata::RANGES]; // Release time 140 IPort *pLowRatio; // Low Ratio 141 IPort *pHighRatio; // High Ratio 142 IPort *pMakeup; // Overall Makeup gain 143 144 IPort *pDryGain; // Dry gain 145 IPort *pWetGain; // Wet gain 146 IPort *pCurve; // Curve graph 147 IPort *pModel; // Curve model 148 } channel_t; 149 150 protected: 151 size_t nMode; // Working mode 152 bool bSidechain; // External side chain 153 channel_t *vChannels; // Audio channels 154 float *vCurve; // Dynamic curve 155 float *vTime; // Time points buffer 156 bool bPause; // Pause button 157 bool bClear; // Clear button 158 bool bMSListen; // Mid/Side listen 159 float fInGain; // Input gain 160 bool bUISync; 161 float_buffer_t *pIDisplay; // Inline display buffer 162 163 IPort *pBypass; // Bypass port 164 IPort *pInGain; // Input gain 165 IPort *pOutGain; // Output gain 166 IPort *pPause; // Pause gain 167 IPort *pClear; // Cleanup gain 168 IPort *pMSListen; // Mid/Side listen 169 170 uint8_t *pData; // Allocated data 171 172 protected: 173 float process_feedback(channel_t *c, size_t i, size_t channels); 174 void process_non_feedback(channel_t *c, float **in, size_t samples); 175 176 public: 177 dyna_processor_base(const plugin_metadata_t &metadata, bool sc, size_t mode); 178 virtual ~dyna_processor_base(); 179 180 public: 181 virtual void init(IWrapper *wrapper); 182 virtual void destroy(); 183 184 virtual void update_settings(); 185 virtual void update_sample_rate(long sr); 186 virtual void ui_activated(); 187 188 virtual void process(size_t samples); 189 virtual bool inline_display(ICanvas *cv, size_t width, size_t height); 190 }; 191 192 class dyna_processor_mono: public dyna_processor_base, public dyna_processor_mono_metadata 193 { 194 public: 195 dyna_processor_mono(); 196 }; 197 198 class dyna_processor_stereo: public dyna_processor_base, public dyna_processor_stereo_metadata 199 { 200 public: 201 dyna_processor_stereo(); 202 }; 203 204 class dyna_processor_lr: public dyna_processor_base, public dyna_processor_lr_metadata 205 { 206 public: 207 dyna_processor_lr(); 208 }; 209 210 class dyna_processor_ms: public dyna_processor_base, public dyna_processor_ms_metadata 211 { 212 public: 213 dyna_processor_ms(); 214 }; 215 216 class sc_dyna_processor_mono: public dyna_processor_base, public sc_dyna_processor_mono_metadata 217 { 218 public: 219 sc_dyna_processor_mono(); 220 }; 221 222 class sc_dyna_processor_stereo: public dyna_processor_base, public sc_dyna_processor_stereo_metadata 223 { 224 public: 225 sc_dyna_processor_stereo(); 226 }; 227 228 class sc_dyna_processor_lr: public dyna_processor_base, public sc_dyna_processor_lr_metadata 229 { 230 public: 231 sc_dyna_processor_lr(); 232 }; 233 234 class sc_dyna_processor_ms: public dyna_processor_base, public sc_dyna_processor_ms_metadata 235 { 236 public: 237 sc_dyna_processor_ms(); 238 }; 239 240 } 241 242 #endif /* PLUGINS_DYNA_PROCESSOR_H_ */ 243