new/reworked audio plugins ported from hv72 compressor/multi/reverb, glyph workaround...
[goodguy/cinelerra.git] / cinelerra-5.1 / plugins / reverb / reverb.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 REVERB_H
22 #define REVERB_H
23
24 class Reverb;
25 class ReverbEngine;
26 class ReverbFFT;
27
28 #include "compressortools.h"
29 #include "fourier.h"
30 #include "reverbwindow.h"
31 #include "loadbalance.h"
32 #include "pluginaclient.h"
33
34 #define MAX_DELAY_INIT 1000
35 #define MIN_REFLECTIONS 1
36 #define MAX_REFLECTIONS 255
37 #define MIN_REFLENGTH 3
38 #define MAX_REFLENGTH 5000
39
40 class ReverbConfig
41 {
42 public:
43         ReverbConfig();
44
45
46         int equivalent(ReverbConfig &that);
47         void copy_from(ReverbConfig &that);
48         void interpolate(ReverbConfig &prev, ReverbConfig &next,
49                 int64_t prev_frame, int64_t next_frame, int64_t current_frame);
50         void dump();
51         void boundaries();
52
53         float level_init;
54         int delay_init;
55         float ref_level1;
56         float ref_level2;
57         int ref_total;
58         int ref_length;
59 // high frequency
60         int high;
61 // low frequency
62         int low;
63         float q;
64         int window_size;
65 };
66
67 class Reverb : public PluginAClient
68 {
69 public:
70         Reverb(PluginServer *server);
71         ~Reverb();
72
73         void reset();
74         void render_stop();
75         void update_gui();
76
77 // required for all realtime/multichannel plugins
78         PLUGIN_CLASS_MEMBERS(ReverbConfig);
79         int process_buffer(int64_t size, Samples **buffer,
80                         int64_t start_position, int sample_rate);
81         double gauss(double sigma, double center, double x);
82         void calculate_envelope();
83         void reallocate_dsp(int new_dsp_allocated);
84
85         int is_realtime();
86         int is_synthesis();
87         int is_multichannel();
88         void save_data(KeyFrame *keyframe);
89         void read_data(KeyFrame *keyframe);
90
91 // the output all reflections are painted on
92         double **dsp_in;
93 // may have to expand it for fft windows larger than the reflected time
94         int dsp_in_allocated;
95 // total samples read into dsp_in by the FFT
96         int dsp_in_length;
97 // new value calculated by the FFT readers
98         int new_dsp_length;
99 // total spectrogram frames generated by the FFT.  Each channel overwrites the same
100 // spectrograms
101         int new_spectrogram_frames;
102
103 // source channels of reflections
104         int **ref_channels;
105 // destination offsets of reflections
106         int **ref_offsets;
107 // levels of reflections
108         double **ref_levels;
109 // detect seeking
110         int64_t last_position;
111 // start_position / sample_rate
112         double start_pos;
113 // get_direction fwd=1, rev=-1, stop=0
114         int dir;
115         DB db;
116
117         ReverbEngine *engine;
118         ReverbFFT **fft;
119         double *envelope;
120         int need_reconfigure;
121 };
122
123 class ReverbClientFrame : public CompressorFreqFrame
124 {
125 public:
126         ReverbClientFrame(int size);
127         ~ReverbClientFrame();
128 };
129
130
131 class ReverbFFT :public CrossfadeFFT
132 {
133 public:
134         ReverbFFT(Reverb *plugin, int channel);
135         ~ReverbFFT();
136
137         int signal_process();
138         int post_process();
139         int read_samples(int64_t output_sample, int samples, Samples *buffer);
140
141         Reverb *plugin;
142         ReverbClientFrame *frame;
143         int channel;
144 };
145
146
147 class ReverbPackage : public LoadPackage
148 {
149 public:
150         ReverbPackage();
151         int channel;
152 };
153
154
155 class ReverbUnit : public LoadClient
156 {
157 public:
158         ReverbUnit(ReverbEngine *engine, Reverb *plugin);
159         ~ReverbUnit();
160         void process_package(LoadPackage *package);
161         ReverbEngine *engine;
162         Reverb *plugin;
163 };
164
165 // This allocates 1 CPU for each output channel.
166 // They simultaneously read from all the input FFT channels.
167 class ReverbEngine : public LoadServer
168 {
169 public:
170         ReverbEngine(Reverb *plugin);
171         ~ReverbEngine();
172
173         void init_packages();
174         LoadClient* new_client();
175         LoadPackage* new_package();
176
177         Reverb *plugin;
178 };
179
180 #endif