remove whitespace at eol
[goodguy/history.git] / cinelerra-5.1 / plugins / denoise / denoise.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008 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 DENOISE_H
23 #define DENOISE_H
24
25
26
27 #include "bchash.inc"
28 #include "guicast.h"
29 #include "mutex.h"
30 #include "pluginaclient.h"
31 #include "vframe.inc"
32
33 class DenoiseEffect;
34 typedef enum { DECOMP, RECON } wavetype;
35
36 class DenoiseLevel : public BC_FPot
37 {
38 public:
39         DenoiseLevel(DenoiseEffect *plugin, int x, int y);
40         int handle_event();
41         DenoiseEffect *plugin;
42 };
43
44 class DenoiseWindow : public PluginClientWindow
45 {
46 public:
47         DenoiseWindow(DenoiseEffect *plugin);
48         void create_objects();
49         void update();
50         DenoiseLevel *scale;
51         DenoiseEffect *plugin;
52 };
53
54
55 class DenoiseConfig
56 {
57 public:
58         DenoiseConfig();
59         void copy_from(DenoiseConfig &that);
60         int equivalent(DenoiseConfig &that);
61         void interpolate(DenoiseConfig &prev,
62                 DenoiseConfig &next,
63                 int64_t prev_frame,
64                 int64_t next_frame,
65                 int64_t current_frame);
66         double level;
67 };
68
69 class Tree
70 {
71 public:
72         Tree(int input_length, int levels);
73         ~Tree();
74
75         int input_length;
76         int levels;
77         double **values;
78 };
79
80 class WaveletCoeffs
81 {
82 public:
83         WaveletCoeffs(double alpha, double beta);
84         ~WaveletCoeffs();
85
86         double values[6];
87         int length;
88 };
89
90 class WaveletFilters
91 {
92 public:
93         WaveletFilters(WaveletCoeffs *wave_coeffs, wavetype transform);
94         ~WaveletFilters();
95
96         double g[6], h[6];
97         int length;
98 };
99
100 class DenoiseEffect : public PluginAClient
101 {
102 public:
103         DenoiseEffect(PluginServer *server);
104         ~DenoiseEffect();
105
106         int is_realtime();
107         void read_data(KeyFrame *keyframe);
108         void save_data(KeyFrame *keyframe);
109         int process_realtime(int64_t size, Samples *input_ptr, Samples *output_ptr);
110
111
112
113
114         void reset();
115         void update_gui();
116         void delete_dsp();
117
118         void process_window();
119         double dot_product(double *data, double *filter, char filtlen);
120         int convolve_dec_2(double *input_sequence,
121                 int64_t length,
122                 double *filter,
123                 int filtlen,
124                 double *output_sequence);
125         int64_t decompose_branches(double *in_data,
126                 int64_t length,
127                 WaveletFilters *decomp_filter,
128                 double *out_low,
129                 double *out_high);
130         int wavelet_decomposition(double *in_data,
131                 int64_t in_length,
132                 double **out_data);
133         int tree_copy(double **output,
134                 double **input,
135                 int length,
136                 int levels);
137         int threshold(int window_size, double gammas, int levels);
138         double dot_product_even(double *data, double *filter, int filtlen);
139         double dot_product_odd(double *data, double *filter, int filtlen);
140         int convolve_int_2(double *input_sequence,
141                 int64_t length,
142                 double *filter,
143                 int filtlen,
144                 int sum_output,
145                 double *output_sequence);
146         int64_t reconstruct_branches(double *in_low,
147                 double *in_high,
148                 int64_t in_length,
149                 WaveletFilters *recon_filter,
150                 double *output);
151         int wavelet_reconstruction(double **in_data,
152                 int64_t in_length,
153                 double *out_data);
154
155
156         PLUGIN_CLASS_MEMBERS(DenoiseConfig)
157
158 // buffer for storing fragments until a complete window size is armed
159         double *input_buffer;
160         int64_t input_size;
161         int64_t input_allocation;
162 // buffer for storing fragments until a fragment is ready to be read
163         double *output_buffer;
164         int64_t output_size;
165         int64_t output_allocation;
166         double *dsp_in;
167         double *dsp_out;
168 // buffer for capturing output of a single iteration
169         double *dsp_iteration;
170         Tree *ex_coeff_d, *ex_coeff_r, *ex_coeff_rn;
171         WaveletCoeffs *wave_coeff_d, *wave_coeff_r;
172         WaveletFilters *decomp_filter, *recon_filter;
173 // scaling factor for transferring from input_buffer
174         double in_scale;
175 // power converted to scaling factor
176         double out_scale;
177
178 // depends on the type of music
179         int64_t levels;
180 // higher number reduces aliasing due to a high noise_level
181 // also increases high end
182         int64_t iterations;
183 // daub6 coeffs
184         double alpha;
185         double beta;
186 // power
187         float output_level;
188 // higher number kills more noise at the expense of more aliasing
189         float noise_level;
190         int64_t window_size;
191         int first_window;
192         int initialized;
193 };
194
195
196 #endif