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
32 #include "plugin_tools.h"
35 namespace calf_plugins
{
37 /**********************************************************************
38 * GAIN REDUCTION by Thor Harald Johanssen
39 **********************************************************************/
40 class gain_reduction_audio_module
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
;
50 inline float output_level(float slope
) const;
51 inline float output_gain(float linSlope
, bool rms
) const;
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
);
56 void process(float &left
, float &right
, const float *det_left
= NULL
, const float *det_right
= NULL
);
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
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
;
84 inline float output_level(float inputt
) const;
85 inline float output_gain(float inputt
) const;
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
);
90 void process(float &left
);
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
{
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;
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
);
122 void process(float &left
, float &right
, const float *det_left
= NULL
, const float *det_right
= NULL
);
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
{
141 typedef compressor_audio_module AM
;
142 gain_reduction_audio_module compressor
;
146 typedef std::complex<double> cfloat
;
149 compressor_audio_module();
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
{
167 typedef sidechaincompressor_audio_module AM
;
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
;
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
;
191 typedef std::complex<double> cfloat
;
194 sidechaincompressor_audio_module();
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
{
214 typedef multibandcompressor_audio_module AM
;
215 static const int strips
= 4;
217 float xout
[strips
], xin
[2];
219 float meter_inL
, meter_inR
, meter_outL
, meter_outR
;
220 gain_reduction_audio_module strip
[strips
];
221 dsp::crossover crossover
;
223 int mode
, page
, bypass_
;
229 multibandcompressor_audio_module();
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
{
248 typedef monocompressor_audio_module AM
;
249 gain_reduction2_audio_module monocompressor
;
253 typedef std::complex<double> cfloat
;
256 monocompressor_audio_module();
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
{
274 enum CalfDeessModes
{
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
;
282 gain_reduction_audio_module compressor
;
283 dsp::biquad_d2 hpL
, hpR
, lpL
, lpR
, pL
, pR
;
289 deesser_audio_module();
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
{
307 typedef gate_audio_module AM
;
308 expander_audio_module gate
;
312 typedef std::complex<double> cfloat
;
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
{
333 typedef sidechaingate_audio_module AM
;
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
;
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
;
357 typedef std::complex<double> cfloat
;
360 sidechaingate_audio_module();
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
{
381 typedef multibandgate_audio_module AM
;
382 static const int strips
= 4;
384 float xout
[strips
], xin
[2];
386 float meter_inL
, meter_inR
, meter_outL
, meter_outR
;
387 expander_audio_module gate
[strips
];
388 dsp::crossover crossover
;
390 int mode
, page
, bypass_
;
396 multibandgate_audio_module();
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;
420 float meter_inL
, meter_inR
, meter_outL
, meter_outR
;
421 dsp::transients transients
;
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
;
438 transientdesigner_audio_module();
439 ~transientdesigner_audio_module();
440 void params_changed();
442 void set_sample_rate(uint32_t sr
);
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;