Merge branch 'master' of https://github.com/calf-studio-gear/calf
[calf.git] / src / calf / modules_limit.h
blob264b5a24f8597081c3e634889bd0b064f056c36b
1 /* Calf DSP plugin pack
2 * Limiter 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_LIMIT_H
22 #define CALF_MODULES_LIMIT_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 "metadata.h"
31 #include "plugin_tools.h"
32 #include "bypass.h"
34 namespace calf_plugins {
36 /**********************************************************************
37 * LIMITER by Christian Holschuh and Markus Schmidt
38 **********************************************************************/
40 class limiter_audio_module: public audio_module<limiter_metadata>, public line_graph_iface {
41 private:
42 typedef limiter_audio_module AM;
43 uint32_t asc_led;
44 int mode, mode_old, oversampling_old;
45 dsp::lookahead_limiter limiter;
46 dsp::resampleN resampler[2];
47 dsp::bypass bypass;
48 vumeters meters;
49 public:
50 uint32_t srate;
51 bool is_active;
52 float limit_old;
53 bool asc_old;
54 float attack_old;
55 limiter_audio_module();
56 void activate();
57 void deactivate();
58 void params_changed();
59 void set_srates();
60 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
61 void set_sample_rate(uint32_t sr);
64 /**********************************************************************
65 * MULTIBAND LIMITER by Markus Schmidt and Christian Holschuh
66 **********************************************************************/
68 class multibandlimiter_audio_module: public audio_module<multibandlimiter_metadata>, public frequency_response_line_graph {
69 private:
70 typedef multibandlimiter_audio_module AM;
71 static const int strips = 4;
72 uint32_t asc_led, cnt;
73 int _mode, mode_old;
74 bool solo[strips];
75 bool no_solo;
76 dsp::lookahead_limiter strip[strips];
77 dsp::lookahead_limiter broadband;
78 dsp::resampleN resampler[strips][2];
79 dsp::crossover crossover;
80 dsp::bypass bypass;
81 float over;
82 unsigned int pos;
83 unsigned int buffer_size;
84 unsigned int overall_buffer_size;
85 float *buffer;
86 int channels;
87 float striprel[strips];
88 float weight[strips];
89 float weight_old[strips];
90 float limit_old;
91 bool asc_old;
92 float attack_old;
93 float oversampling_old;
94 bool _sanitize;
95 vumeters meters;
96 public:
97 uint32_t srate;
98 bool is_active;
99 multibandlimiter_audio_module();
100 ~multibandlimiter_audio_module();
101 void activate();
102 void deactivate();
103 void params_changed();
104 void set_srates();
105 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
106 void set_sample_rate(uint32_t sr);
107 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
108 bool get_layers(int index, int generation, unsigned int &layers) const;
111 class sidechainlimiter_audio_module: public audio_module<sidechainlimiter_metadata>, public frequency_response_line_graph {
112 private:
113 typedef sidechainlimiter_audio_module AM;
114 static const int strips = 5;
115 uint32_t asc_led, cnt;
116 int _mode, mode_old;
117 bool solo[strips];
118 bool no_solo;
119 dsp::lookahead_limiter strip[strips];
120 dsp::lookahead_limiter broadband;
121 dsp::resampleN resampler[strips][2];
122 dsp::crossover crossover;
123 dsp::bypass bypass;
124 float over;
125 unsigned int pos;
126 unsigned int buffer_size;
127 unsigned int overall_buffer_size;
128 float *buffer;
129 int channels;
130 float striprel[strips];
131 float weight[strips];
132 float weight_old[strips];
133 float limit_old;
134 bool asc_old;
135 float attack_old;
136 float oversampling_old;
137 bool _sanitize;
138 vumeters meters;
139 public:
140 uint32_t srate;
141 bool is_active;
142 sidechainlimiter_audio_module();
143 ~sidechainlimiter_audio_module();
144 void activate();
145 void deactivate();
146 void params_changed();
147 void set_srates();
148 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
149 void set_sample_rate(uint32_t sr);
150 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
151 bool get_layers(int index, int generation, unsigned int &layers) const;
156 #endif