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: 30 янв. 2017 г.
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_SLAPDELAY_H_
23 #define PLUGINS_SLAPDELAY_H_
24 
25 #include <metadata/plugins.h>
26 
27 #include <core/plugin.h>
28 #include <core/util/Bypass.h>
29 #include <core/util/ShiftBuffer.h>
30 #include <core/filters/Equalizer.h>
31 
32 namespace lsp
33 {
34     class slap_delay_base: public plugin_t
35     {
36         protected:
37             enum proc_mode_t
38             {
39                 M_OFF,
40                 M_TIME,
41                 M_DISTANCE
42             };
43 
44             typedef struct mono_processor_t
45             {
46                 Equalizer   sEqualizer;
47 
48                 float       fGain[2];       // Amount of gain for left and right input channels
49             } mono_processor_t;
50 
51             typedef struct processor_t
52             {
53                 mono_processor_t        vDelay[2];
54 
55                 size_t                  nDelay;     // Delay
56                 size_t                  nNewDelay;  // New delay
57                 size_t                  nMode;      // Operating mode
58 
59                 IPort                  *pMode;      // Operating mode port
60                 IPort                  *pEq;        // Equalizer
61                 IPort                  *pTime;      // Delay in time units
62                 IPort                  *pDistance;  // Delay in distance units
63                 IPort                  *pFrac;      // Fraction
64                 IPort                  *pDenom;     // Denominator
65                 IPort                  *pPan[2];    // Pan of left and right input channels
66                 IPort                  *pGain;      // Gain of the delay line
67                 IPort                  *pLowCut;    // Low-cut flag
68                 IPort                  *pLowFreq;   // Low-cut frequency
69                 IPort                  *pHighCut;   // High-cut flag
70                 IPort                  *pHighFreq;  // Low-cut frequency
71                 IPort                  *pSolo;      // Solo control
72                 IPort                  *pMute;      // Mute control
73                 IPort                  *pPhase;     // Phase control
74                 IPort                  *pFreqGain[slap_delay_base_metadata::EQ_BANDS];      // Gain for each band of the Equalizer
75             } processor_t;
76 
77             typedef struct channel_t
78             {
79                 Bypass                  sBypass;    // Bypass
80                 float                   fGain[2];   // Panning gain
81                 float                  *vRender;    // Rendering buffer
82                 float                  *vOut;       // Output buffer
83                 IPort                  *pOut;       // Output port
84             } channel_t;
85 
86             typedef struct input_t
87             {
88                 ShiftBuffer             sBuffer;    // Shift buffer of input data
89                 float                  *vIn;        // Input data
90                 IPort                  *pIn;        // Input port
91                 IPort                  *pPan;       // Panning
92             } input_t;
93 
94         protected:
95             size_t          nInputs;        // Mono/Stereo mode flag
96             input_t        *vInputs;        // Inputs
97 
98             processor_t     vProcessors[slap_delay_base_metadata::MAX_PROCESSORS];    // Processors
99             channel_t       vChannels[2];
100 
101             float          *vTemp;          // Temporary buffer for processing
102             bool            bMono;          // Mono output flag
103 
104             IPort          *pBypass;        // Bypass
105             IPort          *pTemp;          // Temperature
106             IPort          *pDry;           // Dry signal amount
107             IPort          *pWet;           // Wet signal amount
108             IPort          *pDryMute;       // Dry mute
109             IPort          *pWetMute;       // Wet mute
110             IPort          *pOutGain;       // Output gain
111             IPort          *pMono;          // Mono output
112             IPort          *pPred;          // Pre-delay
113             IPort          *pStretch;       // Time stretch
114             IPort          *pTempo;         // Tempo
115             IPort          *pSync;          // Sync tempo
116             IPort          *pRamping;       // Ramping mode
117 
118             uint8_t        *vData;          // Allocated data
119 
120         public:
121             slap_delay_base(const plugin_metadata_t &mdata, bool stereo_in);
122             virtual ~slap_delay_base();
123 
124         public:
125             virtual void init(IWrapper *wrapper);
126             virtual void destroy();
127 
128             virtual bool set_position(const position_t *pos);
129             virtual void update_settings();
130             virtual void update_sample_rate(long sr);
131 
132             virtual void process(size_t samples);
133     };
134 
135     class slap_delay_mono: public slap_delay_base, public slap_delay_mono_metadata
136     {
137         public:
138             slap_delay_mono();
139             virtual ~slap_delay_mono();
140     };
141 
142     class slap_delay_stereo: public slap_delay_base, public slap_delay_stereo_metadata
143     {
144         public:
145             slap_delay_stereo();
146             virtual ~slap_delay_stereo();
147     };
148 
149 } /* namespace lsp */
150 
151 #endif /* PLUGINS_SLAPDELAY_H_ */
152