HAAS Stereo Enhancer
[calf.git] / src / calf / modules_mod.h
blob69538d3d839ec23ec8e114d2b212c0ca3142a3ea
1 /* Calf DSP plugin pack
2 * Modulation effect 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_MOD_H
22 #define CALF_MODULES_MOD_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 "multichorus.h"
32 #include "plugin_tools.h"
33 #include "bypass.h"
35 namespace calf_plugins {
37 /**********************************************************************
38 * FLANGER by Krzysztof Foltman
39 **********************************************************************/
41 class flanger_audio_module: public audio_module<flanger_metadata>, public frequency_response_line_graph
43 public:
44 dsp::simple_flanger<float, 2048> left, right;
45 uint32_t srate;
46 bool clear_reset;
47 float last_r_phase;
48 bool is_active;
49 public:
50 flanger_audio_module() {
51 is_active = false;
53 void set_sample_rate(uint32_t sr);
54 void params_changed();
55 void params_reset();
56 void activate();
57 void deactivate();
58 uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask) {
59 left.process(outs[0] + offset, ins[0] + offset, nsamples);
60 right.process(outs[1] + offset, ins[1] + offset, nsamples);
61 return outputs_mask; // XXXKF allow some delay after input going blank
63 bool get_layers(int index, int generation, unsigned int &layers) const;
64 float freq_gain(int subindex, float freq) const;
65 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
66 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
69 /**********************************************************************
70 * PHASER by Krzysztof Foltman
71 **********************************************************************/
73 class phaser_audio_module: public audio_module<phaser_metadata>, public frequency_response_line_graph
75 public:
76 enum { MaxStages = 12 };
77 uint32_t srate;
78 bool clear_reset;
79 float last_r_phase;
80 dsp::simple_phaser left, right;
81 float x1vals[2][MaxStages], y1vals[2][MaxStages];
82 bool is_active;
83 public:
84 phaser_audio_module();
85 void params_changed();
86 void params_reset();
87 void activate();
88 void set_sample_rate(uint32_t sr);
89 void deactivate();
90 uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask) {
91 left.process(outs[0] + offset, ins[0] + offset, nsamples);
92 right.process(outs[1] + offset, ins[1] + offset, nsamples);
93 return outputs_mask; // XXXKF allow some delay after input going blank
95 bool get_layers(int index, int generation, unsigned int &layers) const;
96 float freq_gain(int subindex, float freq) const;
97 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
98 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
101 /**********************************************************************
102 * ROTARY SPEAKER by Krzysztof Foltman
103 **********************************************************************/
105 class rotary_speaker_audio_module: public audio_module<rotary_speaker_metadata>
107 public:
108 /// Current phases and phase deltas for bass and treble rotors
109 uint32_t phase_l, dphase_l, phase_h, dphase_h;
110 dsp::simple_delay<1024, float> delay;
111 dsp::biquad_d2 crossover1l, crossover1r, crossover2l, crossover2r, damper1l, damper1r;
112 dsp::simple_delay<8, float> phaseshift;
113 uint32_t srate;
114 int vibrato_mode;
115 /// Current CC1 (Modulation) value, normalized to [0, 1]
116 float mwhl_value;
117 /// Current CC64 (Hold) value, normalized to [0, 1]
118 float hold_value;
119 /// Current rotation speed for bass rotor - automatic mode
120 float aspeed_l;
121 /// Current rotation speed for treble rotor - automatic mode
122 float aspeed_h;
123 /// Desired speed (0=slow, 1=fast) - automatic mode
124 float dspeed;
125 /// Current rotation speed for bass rotor - manual mode
126 float maspeed_l;
127 /// Current rotation speed for treble rotor - manual mode
128 float maspeed_h;
130 int meter_l, meter_h;
132 rotary_speaker_audio_module();
133 void set_sample_rate(uint32_t sr);
134 void setup();
135 void activate();
136 void deactivate();
138 void params_changed();
139 void set_vibrato();
140 /// Convert RPM speed to delta-phase
141 uint32_t rpm2dphase(float rpm);
142 /// Set delta-phase variables based on current calculated (and interpolated) RPM speed
143 void update_speed();
144 void update_speed_manual(float delta);
145 /// Increase or decrease aspeed towards raspeed, with required negative and positive rate
146 bool incr_towards(float &aspeed, float raspeed, float delta_decc, float delta_acc);
147 uint32_t process(uint32_t offset, uint32_t nsamples, uint32_t inputs_mask, uint32_t outputs_mask);
148 virtual void control_change(int channel, int ctl, int val);
151 /**********************************************************************
152 * MULTI CHORUS by Krzysztof Foltman
153 **********************************************************************/
155 class multichorus_audio_module: public audio_module<multichorus_metadata>, public frequency_response_line_graph
157 public:
158 uint32_t srate;
159 dsp::multichorus<float, dsp::sine_multi_lfo<float, 8>, dsp::filter_sum<dsp::biquad_d2, dsp::biquad_d2 >, 4096> left, right;
160 float last_r_phase;
161 float cutoff;
162 bool is_active;
163 float freq_old, freq2_old, q_old;
164 mutable bool redraw_sine;
165 public:
166 multichorus_audio_module();
167 void params_changed();
168 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
169 void activate();
170 void deactivate();
171 void set_sample_rate(uint32_t sr);
172 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
173 float freq_gain(int subindex, float freq) const;
174 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
175 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
176 bool get_layers(int index, int generation, unsigned int &layers) const;
179 /**********************************************************************
180 * PULSATOR by Markus Schmidt
181 **********************************************************************/
183 class pulsator_audio_module: public audio_module<pulsator_metadata>, public frequency_response_line_graph {
184 private:
185 typedef pulsator_audio_module AM;
186 float offset_old;
187 int mode_old, amount_old;
188 bool clear_reset;
189 dsp::simple_lfo lfoL, lfoR;
190 dsp::bypass bypass;
191 vumeters meters;
192 public:
193 uint32_t srate;
194 bool is_active;
195 pulsator_audio_module();
196 void activate();
197 void deactivate();
198 void params_changed();
199 void set_sample_rate(uint32_t sr);
200 void params_reset()
202 if (clear_reset) {
203 *params[param_reset] = 0.f;
204 clear_reset = false;
207 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
208 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
209 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
210 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
211 bool get_layers(int index, int generation, unsigned int &layers) const;
215 /**********************************************************************
216 * RING MODULATOR by Markus Schmidt
217 **********************************************************************/
219 class ringmodulator_audio_module: public audio_module<ringmodulator_metadata>, public frequency_response_line_graph {
220 private:
221 bool clear_reset;
222 dsp::simple_lfo lfo1, lfo2, modL, modR;
223 dsp::bypass bypass;
224 vumeters meters;
225 public:
226 uint32_t srate;
227 bool is_active;
228 ringmodulator_audio_module();
229 void activate();
230 void deactivate();
231 void params_changed();
232 void set_sample_rate(uint32_t sr);
233 void params_reset()
235 if (clear_reset) {
236 *params[param_lfo1_reset] = 0.f;
237 *params[param_lfo2_reset] = 0.f;
238 clear_reset = false;
241 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
242 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
243 bool get_dot(int index, int subindex, int phase, float &x, float &y, int &size, cairo_iface *context) const;
244 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
245 bool get_layers(int index, int generation, unsigned int &layers) const;
250 #endif