Merge branch 'master' of https://github.com/calf-studio-gear/calf
[calf.git] / src / calf / modules_dist.h
blob2b3760c6044496641abf948f97d1b5f4bd007dc0
1 /* Calf DSP plugin pack
2 * Distortion 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_DIST_H
22 #define CALF_MODULES_DIST_H
24 #include <assert.h>
25 #include <limits.h>
26 #include "biquad.h"
27 #include "bypass.h"
28 #include "audio_fx.h"
29 #include "giface.h"
30 #include "metadata.h"
31 #include "plugin_tools.h"
33 namespace calf_plugins {
35 /**********************************************************************
36 * SATURATOR by Markus Schmidt
37 **********************************************************************/
39 class saturator_audio_module: public audio_module<saturator_metadata> {
40 private:
41 float hp_pre_freq_old, lp_pre_freq_old;
42 float hp_post_freq_old, lp_post_freq_old;
43 float p_level_old, p_freq_old, p_q_old;
44 dsp::biquad_d2 lp[2][4], hp[2][4];
45 dsp::biquad_d2 p[2];
46 dsp::tap_distortion dist[2];
47 dsp::bypass bypass;
48 vumeters meters;
49 public:
50 uint32_t srate;
51 bool is_active;
52 saturator_audio_module();
53 void activate();
54 void deactivate();
55 void params_changed();
56 void set_sample_rate(uint32_t sr);
57 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
60 /**********************************************************************
61 * EXCITER by Markus Schmidt
62 **********************************************************************/
64 class exciter_audio_module: public audio_module<exciter_metadata> {
65 private:
66 float freq_old, ceil_old;
67 bool ceil_active_old;
68 float meter_drive;
69 dsp::biquad_d2 hp[2][4];
70 dsp::biquad_d2 lp[2][2];
71 dsp::tap_distortion dist[2];
72 dsp::bypass bypass;
73 vumeters meters;
74 public:
75 uint32_t srate;
76 bool is_active;
77 exciter_audio_module();
78 void activate();
79 void deactivate();
80 void params_changed();
81 void set_sample_rate(uint32_t sr);
82 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
85 /**********************************************************************
86 * BASS ENHANCER by Markus Schmidt
87 **********************************************************************/
89 class bassenhancer_audio_module: public audio_module<bassenhancer_metadata> {
90 private:
91 float freq_old, floor_old;
92 bool floor_active_old;
93 float meter_drive;
94 dsp::biquad_d2 lp[2][4];
95 dsp::biquad_d2 hp[2][2];
96 dsp::tap_distortion dist[2];
97 dsp::bypass bypass;
98 vumeters meters;
99 public:
100 uint32_t srate;
101 bool is_active;
102 bassenhancer_audio_module();
103 void activate();
104 void deactivate();
105 void params_changed();
106 void set_sample_rate(uint32_t sr);
107 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
110 /**********************************************************************
111 * TAPESIMULATOR by Markus Schmidt
112 **********************************************************************/
114 class tapesimulator_audio_module:
115 public audio_module<tapesimulator_metadata>, public frequency_response_line_graph
117 typedef tapesimulator_audio_module AM;
118 bool active;
119 uint32_t clip_inL, clip_inR, clip_outL, clip_outR;
120 float meter_inL, meter_inR, meter_outL, meter_outR;
121 bool mech_old;
122 mutable bool redraw_output;
123 dsp::biquad_d2 lp[2][2];
124 dsp::biquad_d2 noisefilters[2][3];
125 dsp::transients transients;
126 dsp::bypass bypass;
127 vumeters meters;
128 const static int channels = 2;
129 dsp::simple_lfo lfo1, lfo2;
130 float lp_old, output_old;
131 mutable float rms, input;
132 public:
133 uint32_t srate;
134 tapesimulator_audio_module();
135 void params_changed();
136 void activate();
137 void set_sample_rate(uint32_t sr);
138 void deactivate();
139 float freq_gain(int index, double freq) const;
140 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
141 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
142 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
143 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
144 bool get_layers(int index, int generation, unsigned int &layers) const;
147 /**********************************************************************
148 * CRUSHER by Markus Schmidt and Christian Holschuh
149 **********************************************************************/
151 class crusher_audio_module:
152 public audio_module<crusher_metadata>, public line_graph_iface
154 private:
155 vumeters meters;
156 dsp::bitreduction bitreduction;
157 dsp::samplereduction samplereduction[2];
158 dsp::simple_lfo lfo;
159 dsp::bypass bypass;
160 float smin, sdiff;
161 public:
162 uint32_t srate;
163 crusher_audio_module();
164 void set_sample_rate(uint32_t sr);
165 void activate();
166 void deactivate();
167 void params_changed();
168 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
169 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
170 bool get_layers(int index, int generation, unsigned int &layers) const;
171 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
176 #endif