no longer need ffmpeg patch0 which was for Termux
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / parametric / parametric.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2011 Adam Williams <broadcast at earthling dot net>
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  *
20  */
21
22 #ifndef PARAMETRIC_H
23 #define PARAMETRIC_H
24
25
26 #include "bchash.inc"
27 #include "fourier.h"
28 #include "guicast.h"
29 #include "mutex.h"
30 #include "pluginaclient.h"
31 #include "vframe.inc"
32
33
34 // This parametric EQ multiplies the data by a gaussian curve in frequency domain.
35 // It causes significant delay but is useful.
36
37
38 #define BANDS 3
39 #define MAXMAGNITUDE 15
40 #define MAX_WINDOW 262144
41
42
43
44 class ParametricConfig;
45 class ParametricThread;
46 class ParametricFreq;
47 class ParametricQuality;
48 class ParametricMagnitude;
49 class ParametricBandGUI;
50 class ParametricWindow;
51 class ParametricFFT;
52 class ParametricEQ;
53
54
55
56
57 class ParametricBand
58 {
59 public:
60         ParametricBand();
61
62         int equivalent(ParametricBand &that);
63         void copy_from(ParametricBand &that);
64         void interpolate(ParametricBand &prev,
65                 ParametricBand &next,
66                 double prev_scale,
67                 double next_scale);
68
69         enum
70         {
71                 NONE,
72                 LOWPASS,
73                 HIGHPASS,
74                 BANDPASS
75         };
76
77         int freq;
78         float quality;
79         float magnitude;
80         int mode;
81 };
82
83
84 class ParametricConfig
85 {
86 public:
87         ParametricConfig();
88
89         int equivalent(ParametricConfig &that);
90         void copy_from(ParametricConfig &that);
91         void interpolate(ParametricConfig &prev,
92                 ParametricConfig &next,
93                 int64_t prev_frame,
94                 int64_t next_frame,
95                 int64_t current_frame);
96
97         ParametricBand band[BANDS];
98         float wetness;
99         int window_size;
100 };
101
102
103
104
105
106 class ParametricFreq : public BC_QPot
107 {
108 public:
109         ParametricFreq(ParametricEQ *plugin, int x, int y, int band);
110
111         int handle_event();
112
113         int band;
114         ParametricEQ *plugin;
115 };
116
117
118 class ParametricQuality : public BC_FPot
119 {
120 public:
121         ParametricQuality(ParametricEQ *plugin, int x, int y, int band);
122
123         int handle_event();
124
125         int band;
126         ParametricEQ *plugin;
127 };
128
129
130 class ParametricMagnitude : public BC_FPot
131 {
132 public:
133         ParametricMagnitude(ParametricEQ *plugin, int x, int y, int band);
134
135         int handle_event();
136
137         int band;
138         ParametricEQ *plugin;
139 };
140
141
142
143
144 class ParametricMode : public BC_PopupMenu
145 {
146 public:
147         ParametricMode(ParametricEQ *plugin, int x, int y, int band);
148
149         void create_objects();
150         int handle_event();
151         static int text_to_mode(char *text);
152         static const char* mode_to_text(int mode);
153
154         int band;
155         ParametricEQ *plugin;
156 };
157
158
159
160
161
162 class ParametricBandGUI
163 {
164 public:
165         ParametricBandGUI(ParametricEQ *plugin,
166                 ParametricWindow *window,
167                 int x,
168                 int y,
169                 int band);
170         ~ParametricBandGUI();
171
172         void create_objects();
173         void update_gui();
174
175         int band;
176         int x, y;
177         ParametricEQ *plugin;
178         ParametricWindow *window;
179         ParametricFreq *freq;
180         ParametricQuality *quality;
181         ParametricMagnitude *magnitude;
182         ParametricMode *mode;
183 };
184
185
186 class ParametricSize : public BC_PopupMenu
187 {
188 public:
189         ParametricSize(ParametricWindow *window, ParametricEQ *plugin, int x, int y);
190
191         int handle_event();
192         void create_objects();         // add initial items
193         void update(int size);
194
195         ParametricWindow *window;
196         ParametricEQ *plugin;
197 };
198
199
200
201
202 class ParametricWetness : public BC_FPot
203 {
204 public:
205         ParametricWetness(ParametricEQ *plugin, int x, int y);
206         int handle_event();
207         ParametricEQ *plugin;
208 };
209
210
211 class ParametricWindow : public PluginClientWindow
212 {
213 public:
214         ParametricWindow(ParametricEQ *plugin);
215         ~ParametricWindow();
216
217         void create_objects();
218         void update_gui();
219         void update_canvas();
220
221         BC_SubWindow *canvas;
222         ParametricEQ *plugin;
223         ParametricBandGUI* bands[BANDS];
224         ParametricWetness *wetness;
225         ParametricSize *size;
226 };
227
228
229 class ParametricGUIFrame : public PluginClientFrame
230 {
231 public:
232         ParametricGUIFrame(int window_size, int sample_rate);
233         virtual ~ParametricGUIFrame();
234         double *data;
235         int data_size;
236 // Maximum of window in frequency domain
237         double freq_max;
238 // Maximum of window in time domain
239         double time_max;
240         int window_size;
241 };
242
243
244 class ParametricFFT : public CrossfadeFFT
245 {
246 public:
247         ParametricFFT(ParametricEQ *plugin);
248         ~ParametricFFT();
249
250         int signal_process();
251         int post_process();
252         int read_samples(int64_t output_sample,
253                 int samples,
254                 Samples *buffer);
255
256         ParametricEQ *plugin;
257 // Current GUI frame being filled
258         ParametricGUIFrame *frame;
259 };
260
261
262 class ParametricEQ : public PluginAClient
263 {
264 public:
265         ParametricEQ(PluginServer *server);
266         ~ParametricEQ();
267
268         int is_realtime();
269         void read_data(KeyFrame *keyframe);
270         void save_data(KeyFrame *keyframe);
271         int process_buffer(int64_t size,
272                 Samples *buffer,
273                 int64_t start_position,
274                 int sample_rate);
275
276         void reset();
277         void reconfigure();
278         void update_gui();
279
280         double calculate_envelope();
281         double gauss(double sigma, double a, double x);
282
283         double *envelope;
284         int need_reconfigure;
285         PLUGIN_CLASS_MEMBERS(ParametricConfig)
286         ParametricFFT *fft;
287 // For refreshing the canvas
288         ParametricGUIFrame *last_frame;
289 };
290
291
292
293 #endif