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: 28 сент. 2015 г.
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_PLUGINS_PHASE_DETECTOR_H_
23 #define CORE_PLUGINS_PHASE_DETECTOR_H_
24 
25 #include <core/plugin.h>
26 #include <metadata/plugins.h>
27 
28 namespace lsp
29 {
30     class phase_detector: public plugin_t, public phase_detector_metadata
31     {
32         protected:
33             typedef struct buffer_t
34             {
35                 float      *pData;
36                 size_t      nSize;
37             } buffer_t;
38 
39         protected:
40             float               fTimeInterval;
41             float               fReactivity;
42 
43             float              *vFunction;
44             float              *vAccumulated;
45             float              *vNormalized;
46 
47             size_t              nMaxVectorSize;
48             size_t              nVectorSize;
49             size_t              nFuncSize;
50             ssize_t             nBest;
51             ssize_t             nWorst;
52             ssize_t             nSelected;
53 
54             size_t              nGapSize;
55             size_t              nMaxGapSize;
56             size_t              nGapOffset;
57 
58             buffer_t            vA, vB;
59 
60             float               fTau;
61             float               fSelector;
62             bool                bBypass;
63 
64             float_buffer_t      *pIDisplay;      // Inline display buffer
65 
66         public:
67             phase_detector();
68             virtual ~phase_detector();
69 
70         protected:
71             size_t fillGap(const float *a, const float *b, size_t count);
72             void clearBuffers();
73             void printFunction(const char *s, const float *f);
74             bool setTimeInterval(float interval, bool force);
75             void setReactiveInterval(float interval);
76             void dropBuffers();
77 
78         public:
79             virtual void destroy();
80             virtual void update_settings();
81             virtual void update_sample_rate(long sr);
82             virtual void process(size_t samples);
83             virtual bool inline_display(ICanvas *cv, size_t width, size_t height);
84     };
85 
86 } /* namespace ddb */
87 
88 #endif /* CORE_PLUGINS_PHASE_DETECTOR_H_ */
89