new/reworked audio plugins ported from hv72 compressor/multi/reverb, glyph workaround...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / compressormulti / comprmulti.h
1
2 /*
3  * CINELERRA
4  * Copyright (C) 2008-2019 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 #ifndef COMPRMULTI_H
22 #define COMPRMULTI_H
23
24 #include "bchash.inc"
25 #include "compressortools.h"
26 #include "fourier.h"
27 #include "mutex.h"
28 #include "pluginaclient.h"
29 #include "samples.inc"
30 #include "vframe.inc"
31
32 class ComprMultiEffect;
33 class ComprMultiFFT;
34
35 //#define LOG_CROSSOVER
36 #define DRAW_AFTER_BANDPASS
37
38 #define TOTAL_BANDS 3
39
40 class ComprMultiConfig : public CompressorConfigBase
41 {
42 public:
43         ComprMultiConfig();
44
45         void copy_from(ComprMultiConfig &that);
46         int equivalent(ComprMultiConfig &that);
47         void interpolate(ComprMultiConfig &prev, ComprMultiConfig &next,
48                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
49         double q;
50         int window_size;
51 };
52
53 class ComprMultiFFT :public CrossfadeFFT
54 {
55 public:
56         ComprMultiFFT(ComprMultiEffect *plugin, int channel);
57         ~ComprMultiFFT();
58         
59         int signal_process(int band);
60         int post_process(int band);
61         int read_samples(int64_t output_sample, int samples, Samples *buffer);
62
63         ComprMultiEffect *plugin;
64         int channel;
65         CompressorFreqFrame *frame;
66 };
67
68 // processing state of a single band
69 class BandState
70 {
71 public:
72         BandState(ComprMultiEffect *plugin, int band);
73         ~BandState();
74
75         void delete_dsp();
76         void reset();
77         void reconfigure();
78 // calculate the envelope for only this band
79         void calculate_envelope();
80         void process_readbehind(int size,
81                 int reaction_samples, int decay_samples, int trigger);
82         void process_readahead(int size, int preview_samples,
83                 int reaction_samples, int decay_samples, int trigger);
84         void allocate_filtered(int new_size);
85
86 // bandpass filter for this band
87         double *envelope;
88         int envelope_allocated;
89 // The input for all channels with filtering by this band
90         Samples **filtered_buffer;
91 // ending input value of smoothed input
92         double next_target;
93 // starting input value of smoothed input
94         double previous_target;
95 // samples between previous and next target value for readahead
96         int target_samples;
97 // current sample from 0 to target_samples
98         int target_current_sample;
99 // current smoothed input value
100         double current_value;
101 // Temporaries for linear transfer
102         ArrayList<compressor_point_t> levels;
103         ComprMultiEffect *plugin;
104         int band;
105         CompressorEngine *engine;
106 };
107
108 class ComprMultiEffect : public PluginAClient
109 {
110 public:
111         ComprMultiEffect(PluginServer *server);
112         ~ComprMultiEffect();
113
114         int is_multichannel();
115         int is_realtime();
116         void read_data(KeyFrame *keyframe);
117         void save_data(KeyFrame *keyframe);
118         int process_buffer(int64_t size, Samples **buffer,
119                 int64_t start_position, int sample_rate);
120
121 // calculate envelopes of all the bands
122         void calculate_envelope();
123
124         void allocate_input(int new_size);
125
126         void reset();
127         void update_gui();
128         void render_stop();
129         void delete_dsp();
130         void dump_frames();
131
132         PLUGIN_CLASS_MEMBERS(ComprMultiConfig)
133
134 #ifndef DRAW_AFTER_BANDPASS
135 // The out of band data for each channel with readahead
136         Samples **input_buffer;
137 // Number of samples in the unfiltered input buffers
138         int64_t input_size;
139 // input buffer size being calculated by the FFT readers
140         int64_t new_input_size;
141 #endif // !DRAW_AFTER_BANDPASS
142 // Starting sample of the input buffer relative to project in the requested rate.
143         int64_t input_start;
144 // Number of samples in the filtered input buffers
145         int64_t filtered_size;
146
147 // detect seeking
148         int64_t last_position;
149
150 // count spectrogram frames for each band
151         int new_spectrogram_frames[TOTAL_BANDS];
152
153         BandState *band_states[TOTAL_BANDS];
154 // The big FFT with multiple channels & multiple bands extracted per channel.
155         ComprMultiFFT **fft;
156
157         int need_reconfigure;
158         double start_pos;
159         int dir;
160 };
161
162
163 #endif