HAAS Stereo Enhancer
[calf.git] / src / calf / modules_comp.h
bloba90733d894348840706f2231737ec67eaffb4ea6
1 /* Calf DSP plugin pack
2 * Compression related plugins
4 * Copyright (C) 2001-2010 Krzysztof Foltman, Markus Schmidt, Thor Harald Johansen and others
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General
17 * Public License along with this program; if not, write to the
18 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 * Boston, MA 02111-1307, USA.
21 #ifndef CALF_MODULES_COMP_H
22 #define CALF_MODULES_COMP_H
24 #include <assert.h>
25 #include <limits.h>
26 #include "biquad.h"
27 #include "inertia.h"
28 #include "audio_fx.h"
29 #include "giface.h"
30 #include "loudness.h"
31 #include "metadata.h"
32 #include "plugin_tools.h"
33 #include "bypass.h"
35 namespace calf_plugins {
37 /**********************************************************************
38 * GAIN REDUCTION by Thor Harald Johanssen
39 **********************************************************************/
40 class gain_reduction_audio_module
42 private:
43 float linSlope, detected, kneeSqrt, kneeStart, linKneeStart, kneeStop;
44 float compressedKneeStop, adjKneeStart, thres;
45 float attack, release, threshold, ratio, knee, makeup, detection, stereo_link, bypass, mute, meter_out, meter_comp;
46 float old_threshold, old_ratio, old_knee, old_makeup, old_bypass, old_mute, old_detection, old_stereo_link;
47 mutable bool redraw_graph;
48 uint32_t srate;
49 bool is_active;
50 inline float output_level(float slope) const;
51 inline float output_gain(float linSlope, bool rms) const;
52 public:
53 gain_reduction_audio_module();
54 void set_params(float att, float rel, float thr, float rat, float kn, float mak, float det, float stl, float byp, float mu);
55 void update_curve();
56 void process(float &left, float &right, const float *det_left = NULL, const float *det_right = NULL);
57 void activate();
58 void deactivate();
59 int id;
60 void set_sample_rate(uint32_t sr);
61 float get_output_level();
62 float get_comp_level();
63 bool get_graph(int subindex, float *data, int points, cairo_iface *context, int *mode) const;
64 bool get_dot(int subindex, float &x, float &y, int &size, cairo_iface *context) const;
65 bool get_gridline(int subindex, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
66 bool get_layers(int index, int generation, unsigned int &layers) const;
69 /**********************************************************************
70 * GAIN REDUCTION 2 by Damien Zammit
71 **********************************************************************/
73 class gain_reduction2_audio_module
75 private:
76 float linSlope, detected, kneeSqrt, kneeStart, linKneeStart, kneeStop;
77 float compressedKneeStop, adjKneeStart, thres;
78 float attack, release, threshold, ratio, knee, makeup, detection, stereo_link, bypass, mute, meter_out, meter_comp;
79 float old_threshold, old_ratio, old_knee, old_makeup, old_bypass, old_mute, old_detection, old_stereo_link;
80 mutable bool redraw_graph;
81 float old_y1,old_yl,old_detected;
82 uint32_t srate;
83 bool is_active;
84 inline float output_level(float inputt) const;
85 inline float output_gain(float inputt) const;
86 public:
87 gain_reduction2_audio_module();
88 void set_params(float att, float rel, float thr, float rat, float kn, float mak, float byp, float mu);
89 void update_curve();
90 void process(float &left);
91 void activate();
92 void deactivate();
93 int id;
94 void set_sample_rate(uint32_t sr);
95 float get_output_level();
96 float get_comp_level();
97 bool get_graph(int subindex, float *data, int points, cairo_iface *context, int *mode) const;
98 bool get_dot(int subindex, float &x, float &y, int &size, cairo_iface *context) const;
99 bool get_gridline(int subindex, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
100 bool get_layers(int index, int generation, unsigned int &layers) const;
103 /**********************************************************************
104 * EXPANDER by Damien Zammit
105 **********************************************************************/
107 class expander_audio_module {
108 private:
109 float linSlope, peak, detected, kneeSqrt, kneeStart, linKneeStart, kneeStop, linKneeStop;
110 float compressedKneeStop, adjKneeStart, range, thres, attack_coeff, release_coeff;
111 float attack, release, threshold, ratio, knee, makeup, detection, stereo_link, bypass, mute, meter_out, meter_gate;
112 float old_threshold, old_ratio, old_knee, old_makeup, old_bypass, old_range, old_trigger, old_mute, old_detection, old_stereo_link;
113 mutable bool redraw_graph;
114 inline float output_level(float slope) const;
115 inline float output_gain(float linSlope, bool rms) const;
116 public:
117 uint32_t srate;
118 bool is_active;
119 expander_audio_module();
120 void set_params(float att, float rel, float thr, float rat, float kn, float mak, float det, float stl, float byp, float mu, float ran);
121 void update_curve();
122 void process(float &left, float &right, const float *det_left = NULL, const float *det_right = NULL);
123 void activate();
124 void deactivate();
125 int id;
126 void set_sample_rate(uint32_t sr);
127 float get_output_level();
128 float get_expander_level();
129 bool get_graph(int subindex, float *data, int points, cairo_iface *context, int *mode) const;
130 bool get_dot(int subindex, float &x, float &y, int &size, cairo_iface *context) const;
131 bool get_gridline(int subindex, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
132 bool get_layers(int index, int generation, unsigned int &layers) const;
135 /**********************************************************************
136 * COMPRESSOR by Thor Harald Johanssen
137 **********************************************************************/
139 class compressor_audio_module: public audio_module<compressor_metadata>, public line_graph_iface {
140 private:
141 typedef compressor_audio_module AM;
142 gain_reduction_audio_module compressor;
143 dsp::bypass bypass;
144 vumeters meters;
145 public:
146 typedef std::complex<double> cfloat;
147 uint32_t srate;
148 bool is_active;
149 compressor_audio_module();
150 void activate();
151 void deactivate();
152 void params_changed();
153 void set_sample_rate(uint32_t sr);
154 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
155 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
156 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
157 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
158 bool get_layers(int index, int generation, unsigned int &layers) const;
161 /**********************************************************************
162 * SIDECHAIN COMPRESSOR by Markus Schmidt
163 **********************************************************************/
165 class sidechaincompressor_audio_module: public audio_module<sidechaincompressor_metadata>, public frequency_response_line_graph {
166 private:
167 typedef sidechaincompressor_audio_module AM;
168 enum CalfScModes {
169 WIDEBAND,
170 DEESSER_WIDE,
171 DEESSER_SPLIT,
172 DERUMBLER_WIDE,
173 DERUMBLER_SPLIT,
174 WEIGHTED_1,
175 WEIGHTED_2,
176 WEIGHTED_3,
177 BANDPASS_1,
178 BANDPASS_2
180 float f1_freq_old, f2_freq_old, f1_level_old, f2_level_old;
181 float f1_freq_old1, f2_freq_old1, f1_level_old1, f2_level_old1;
182 CalfScModes sc_mode;
183 CalfScModes sc_mode_old, sc_mode_old1;
184 mutable bool redraw_graph;
185 float f1_active, f2_active;
186 gain_reduction_audio_module compressor;
187 dsp::biquad_d2 f1L, f1R, f2L, f2R;
188 dsp::bypass bypass;
189 vumeters meters;
190 public:
191 typedef std::complex<double> cfloat;
192 uint32_t srate;
193 bool is_active;
194 sidechaincompressor_audio_module();
195 void activate();
196 void deactivate();
197 void params_changed();
198 cfloat h_z(const cfloat &z) const;
199 float freq_gain(int index, double freq) const;
200 void set_sample_rate(uint32_t sr);
201 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
202 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
203 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
204 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
205 bool get_layers(int index, int generation, unsigned int &layers) const;
208 /**********************************************************************
209 * MULTIBAND COMPRESSOR by Markus Schmidt
210 **********************************************************************/
212 class multibandcompressor_audio_module: public audio_module<multibandcompressor_metadata>, public frequency_response_line_graph {
213 private:
214 typedef multibandcompressor_audio_module AM;
215 static const int strips = 4;
216 bool solo[strips];
217 float xout[strips], xin[2];
218 bool no_solo;
219 float meter_inL, meter_inR, meter_outL, meter_outR;
220 gain_reduction_audio_module strip[strips];
221 dsp::crossover crossover;
222 dsp::bypass bypass;
223 int mode, page, bypass_;
224 mutable int redraw;
225 vumeters meters;
226 public:
227 uint32_t srate;
228 bool is_active;
229 multibandcompressor_audio_module();
230 void activate();
231 void deactivate();
232 void params_changed();
233 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
234 void set_sample_rate(uint32_t sr);
235 const gain_reduction_audio_module *get_strip_by_param_index(int index) const;
236 virtual bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
237 virtual bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
238 virtual bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
239 virtual bool get_layers(int index, int generation, unsigned int &layers) const;
242 /**********************************************************************
243 * MONO COMPRESSOR by Damien Zammit
244 **********************************************************************/
246 class monocompressor_audio_module: public audio_module<monocompressor_metadata>, public line_graph_iface {
247 private:
248 typedef monocompressor_audio_module AM;
249 gain_reduction2_audio_module monocompressor;
250 vumeters meters;
251 dsp::bypass bypass;
252 public:
253 typedef std::complex<double> cfloat;
254 uint32_t srate;
255 bool is_active;
256 monocompressor_audio_module();
257 void activate();
258 void deactivate();
259 void params_changed();
260 void set_sample_rate(uint32_t sr);
261 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
262 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
263 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
264 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
265 bool get_layers(int index, int generation, unsigned int &layers) const;
268 /**********************************************************************
269 * DEESSER by Markus Schmidt
270 **********************************************************************/
272 class deesser_audio_module: public audio_module<deesser_metadata>, public frequency_response_line_graph {
273 private:
274 enum CalfDeessModes {
275 WIDE,
276 SPLIT
278 mutable float f1_freq_old, f2_freq_old, f1_level_old, f2_level_old, f2_q_old;
279 mutable float f1_freq_old1, f2_freq_old1, f1_level_old1, f2_level_old1, f2_q_old1;
280 uint32_t detected_led;
281 float detected;
282 gain_reduction_audio_module compressor;
283 dsp::biquad_d2 hpL, hpR, lpL, lpR, pL, pR;
284 dsp::bypass bypass;
285 vumeters meters;
286 public:
287 uint32_t srate;
288 bool is_active;
289 deesser_audio_module();
290 void activate();
291 void deactivate();
292 void params_changed();
293 float freq_gain(int index, double freq) const
295 return hpL.freq_gain(freq, srate) * pL.freq_gain(freq, srate);
297 void set_sample_rate(uint32_t sr);
298 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
301 /**********************************************************************
302 * GATE AUDIO MODULE Damien Zammit
303 **********************************************************************/
305 class gate_audio_module: public audio_module<gate_metadata>, public line_graph_iface {
306 private:
307 typedef gate_audio_module AM;
308 expander_audio_module gate;
309 dsp::bypass bypass;
310 vumeters meters;
311 public:
312 typedef std::complex<double> cfloat;
313 uint32_t srate;
314 bool is_active;
315 gate_audio_module();
316 void activate();
317 void deactivate();
318 void params_changed();
319 void set_sample_rate(uint32_t sr);
320 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
321 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
322 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
323 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
324 bool get_layers(int index, int generation, unsigned int &layers) const;
327 /**********************************************************************
328 * SIDECHAIN GATE by Markus Schmidt
329 **********************************************************************/
331 class sidechaingate_audio_module: public audio_module<sidechaingate_metadata>, public frequency_response_line_graph {
332 private:
333 typedef sidechaingate_audio_module AM;
334 enum CalfScModes {
335 WIDEBAND,
336 HIGHGATE_WIDE,
337 HIGHGATE_SPLIT,
338 LOWGATE_WIDE,
339 LOWGATE_SPLIT,
340 WEIGHTED_1,
341 WEIGHTED_2,
342 WEIGHTED_3,
343 BANDPASS_1,
344 BANDPASS_2
346 float f1_freq_old, f2_freq_old, f1_level_old, f2_level_old;
347 float f1_freq_old1, f2_freq_old1, f1_level_old1, f2_level_old1;
348 CalfScModes sc_mode;
349 CalfScModes sc_mode_old, sc_mode_old1;
350 mutable bool redraw_graph;
351 float f1_active, f2_active;
352 expander_audio_module gate;
353 dsp::biquad_d2 f1L, f1R, f2L, f2R;
354 dsp::bypass bypass;
355 vumeters meters;
356 public:
357 typedef std::complex<double> cfloat;
358 uint32_t srate;
359 bool is_active;
360 sidechaingate_audio_module();
361 void activate();
362 void deactivate();
363 void params_changed();
364 cfloat h_z(const cfloat &z) const;
365 float freq_gain(int index, double freq) const;
366 void set_sample_rate(uint32_t sr);
367 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
368 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
369 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
370 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
371 bool get_layers(int index, int generation, unsigned int &layers) const;
375 /**********************************************************************
376 * MULTIBAND GATE by Markus Schmidt
377 **********************************************************************/
379 class multibandgate_audio_module: public audio_module<multibandgate_metadata>, public frequency_response_line_graph {
380 private:
381 typedef multibandgate_audio_module AM;
382 static const int strips = 4;
383 bool solo[strips];
384 float xout[strips], xin[2];
385 bool no_solo;
386 float meter_inL, meter_inR, meter_outL, meter_outR;
387 expander_audio_module gate[strips];
388 dsp::crossover crossover;
389 dsp::bypass bypass;
390 int mode, page, bypass_;
391 mutable int redraw;
392 vumeters meters;
393 public:
394 uint32_t srate;
395 bool is_active;
396 multibandgate_audio_module();
397 void activate();
398 void deactivate();
399 void params_changed();
400 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
401 void set_sample_rate(uint32_t sr);
402 const expander_audio_module *get_strip_by_param_index(int index) const;
403 virtual bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
404 virtual bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
405 virtual bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
406 bool get_layers(int index, int generation, unsigned int &layers) const;
409 /**********************************************************************
410 * TRANSIENT DESIGNER by Christian Holschuh and Markus Schmidt
411 **********************************************************************/
413 class transientdesigner_audio_module:
414 public audio_module<transientdesigner_metadata>, public frequency_response_line_graph
416 typedef transientdesigner_audio_module AM;
417 static const int channels = 2;
418 uint32_t srate;
419 bool active;
420 float meter_inL, meter_inR, meter_outL, meter_outR;
421 dsp::transients transients;
422 dsp::bypass bypass;
423 int display_old;
424 mutable int pixels;
425 mutable float *pbuffer;
426 mutable int pbuffer_pos;
427 mutable int pbuffer_size;
428 mutable int pbuffer_sample;
429 mutable int pbuffer_draw;
430 mutable bool pbuffer_available;
431 mutable int last_drawn;
432 bool attacked;
433 uint32_t attcount;
434 int attack_pos;
435 float display_max;
436 vumeters meters;
437 public:
438 transientdesigner_audio_module();
439 ~transientdesigner_audio_module();
440 void params_changed();
441 void activate();
442 void set_sample_rate(uint32_t sr);
443 void deactivate();
444 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
445 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
446 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
447 bool get_layers(int index, int generation, unsigned int &layers) const;
452 #endif