File: crossover.h

package info (click to toggle)
lsp-plugins 1.2.26-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 130,004 kB
  • sloc: cpp: 642,749; xml: 78,805; makefile: 14,229; php: 1,361; sh: 185
file content (190 lines) | stat: -rw-r--r-- 10,096 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Copyright (C) 2023 Linux Studio Plugins Project <https://lsp-plug.in/>
 *           (C) 2023 Vladimir Sadovnikov <sadko4u@gmail.com>
 *
 * This file is part of lsp-plugins-crossover
 * Created on: 3 авг. 2021 г.
 *
 * lsp-plugins-crossover is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * any later version.
 *
 * lsp-plugins-crossover is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with lsp-plugins-crossover. If not, see <https://www.gnu.org/licenses/>.
 */

#ifndef PRIVATE_PLUGINS_CROSSOVER_H_
#define PRIVATE_PLUGINS_CROSSOVER_H_

#include <lsp-plug.in/plug-fw/plug.h>
#include <lsp-plug.in/plug-fw/core/IDBuffer.h>
#include <lsp-plug.in/dsp-units/ctl/Bypass.h>
#include <lsp-plug.in/dsp-units/util/Analyzer.h>
#include <lsp-plug.in/dsp-units/util/Crossover.h>
#include <lsp-plug.in/dsp-units/util/Delay.h>
#include <lsp-plug.in/dsp-units/util/FFTCrossover.h>

#include <private/meta/crossover.h>

namespace lsp
{
    namespace plugins
    {
        /**
         * Crossover Plugin Series
         */
        class crossover: public plug::Module
        {
            public:
                enum c_mode_t
                {
                    XOVER_MONO,
                    XOVER_STEREO,
                    XOVER_LR,
                    XOVER_MS
                };

            protected:
                typedef struct xover_band_t
                {
                    dspu::Delay         sDelay;             // Band delay

                    float              *vOut;               // Output channel pointer
                    float              *vResult;            // Result buffer
                    float              *vTr;                // Transfer function
                    float              *vFc;                // Frequency chart

                    bool                bSolo;              // Soloing
                    bool                bMute;              // Muting
                    bool                bActive;            // Band activity flag
                    float               fGain;              // Gain
                    float               fOutLevel;          // Output signal level
                    bool                bSyncCurve;         // Sync frequency response

                    plug::IPort        *pSolo;              // Soloing
                    plug::IPort        *pMute;              // Muting
                    plug::IPort        *pPhase;             // Phase reversal
                    plug::IPort        *pGain;              // Gain
                    plug::IPort        *pDelay;             // Delay
                    plug::IPort        *pOutLevel;          // Output level of the band
                    plug::IPort        *pFreqEnd;           // Frequency range end
                    plug::IPort        *pOut;               // Output port
                    plug::IPort        *pAmpGraph;          // Amplitude graph
                } xover_band_t;

                typedef struct xover_split_t
                {
                    size_t              nBand;              // Associated band index
                    size_t              nSlope;             // Slope
                    float               fFreq;              // Split frequency

                    plug::IPort        *pSlope;             // Slope
                    plug::IPort        *pFreq;              // Split frequency
                } xover_split_t;

                typedef struct channel_t
                {
                    dspu::Bypass        sBypass;            // Bypass
                    dspu::Crossover     sXOver;             // Crossover module
                    dspu::FFTCrossover  sFFTXOver;          // Linear-phase crossover module

                    xover_split_t       vSplit[meta::crossover_metadata::BANDS_MAX-1];   // Split bands
                    xover_band_t        vBands[meta::crossover_metadata::BANDS_MAX];     // Crossover bands

                    float              *vIn;                // Input buffer
                    float              *vOut;               // Output buffer
                    float              *vInAnalyze;         // Input analysis
                    float              *vOutAnalyze;        // Output analysis
                    float              *vBuffer;            // Common data processing buffer
                    float              *vResult;            // Result buffer
                    float              *vTr;                // Transfer function
                    float              *vFc;                // Frequency chart

                    size_t              nAnInChannel;       // Analyzer channel used for input signal analysis
                    size_t              nAnOutChannel;      // Analyzer channel used for output signal analysis
                    bool                bSyncCurve;         // Sync frequency response curve
                    float               fInLevel;           // Input level meter
                    float               fOutLevel;          // Output level meter

                    plug::IPort        *pIn;                // Input
                    plug::IPort        *pOut;               // Output
                    plug::IPort        *pFftIn;             // Pre-processing FFT analysis data
                    plug::IPort        *pFftInSw;           // Pre-processing FFT analysis control port
                    plug::IPort        *pFftOut;            // Post-processing FFT analysis data
                    plug::IPort        *pFftOutSw;          // Post-processing FFT analysis controlport
                    plug::IPort        *pAmpGraph;          // Crossover amplitude graph
                    plug::IPort        *pInLvl;             // Input level meter
                    plug::IPort        *pOutLvl;            // Output level meter
                } channel_t;

            protected:
                dspu::Analyzer      sAnalyzer;              // Analyzer
                uint32_t            nMode;                  // Crossover mode
                uint32_t            nOpMode;                // Operating mode
                channel_t          *vChannels;              // Crossover channels
                float              *vAnalyze[4];            // Data analysis buffer
                float               fInGain;                // Input gain
                float               fOutGain;               // Output gain
                float               fZoom;                  // Zoom
                bool                bMSOut;                 // Mid/Side output
                bool                bSMApply;               // Apply solo/mute to bands

                uint8_t            *pData;                  // Aligned data pointer
                float              *vFreqs;                 // Analyzer FFT frequencies
                float              *vCurve;                 // Curve
                uint32_t           *vIndexes;               // Analyzer FFT indexes
                core::IDBuffer     *pIDisplay;              // Inline display buffer

                plug::IPort        *pBypass;                // Bypass port
                plug::IPort        *pOpMode;                // Operating mode
                plug::IPort        *pSMApply;               // Apply solo/mute to bands
                plug::IPort        *pInGain;                // Input gain port
                plug::IPort        *pOutGain;               // Output gain port
                plug::IPort        *pReactivity;            // Reactivity
                plug::IPort        *pShiftGain;             // Shift gain port
                plug::IPort        *pZoom;                  // Zoom port
                plug::IPort        *pMSOut;                 // Mid/Side output

            protected:
                static void                             process_band(void *object, void *subject, size_t band, const float *data, size_t sample, size_t count);
                static inline dspu::crossover_mode_t    crossover_mode(size_t slope);
                static inline size_t                    crossover_slope(size_t slope);
                static inline float                     fft_crossover_slope(size_t slope);
                static inline size_t                    select_fft_rank(size_t sample_rate);
                static int                              compare_splits(const void *a1, const void *a2, void *data);

            protected:
                void                do_destroy();

            public:
                explicit crossover(const meta::plugin_t *metadata, size_t mode);
                crossover(const crossover &) = delete;
                crossover(crossover &&) = delete;
                virtual ~crossover() override;

                crossover & operator = (const crossover &) = delete;
                crossover & operator = (crossover &&) = delete;

                virtual void        init(plug::IWrapper *wrapper, plug::IPort **ports) override;
                virtual void        destroy() override;

            public:
                virtual void        update_settings() override;
                virtual void        update_sample_rate(long sr) override;
                virtual void        ui_activated() override;

                virtual void        process(size_t samples) override;
                virtual bool        inline_display(plug::ICanvas *cv, size_t width, size_t height) override;

                virtual void        dump(dspu::IStateDumper *v) const override;
        };
    } /* namespace plugins */
} /* namespace lsp */

#endif /* PRIVATE_PLUGINS_CROSSOVER_H_ */