LineGraph: z axis for lo and hi pass handles
[calf.git] / src / calf / modules_delay.h
blob918791abcc6914af432b2304d49c05bd108ebd15
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 02110-1301 USA
22 #ifndef CALF_MODULES_DELAY_H
23 #define CALF_MODULES_DELAY_H
25 #include <assert.h>
26 #include <limits.h>
27 #include "biquad.h"
28 #include "bypass.h"
29 #include "inertia.h"
30 #include "audio_fx.h"
31 #include "giface.h"
32 #include "metadata.h"
33 #include "loudness.h"
34 #include <math.h>
35 #include "plugin_tools.h"
37 namespace calf_plugins {
39 struct ladspa_plugin_info;
41 /**********************************************************************
42 * REVERB by Krzysztof Foltman
43 **********************************************************************/
45 class reverb_audio_module: public audio_module<reverb_metadata>
47 vumeters meters;
48 public:
49 dsp::reverb reverb;
50 dsp::simple_delay<131072, dsp::stereo_sample<float> > pre_delay;
51 dsp::onepole<float> left_lo, right_lo, left_hi, right_hi;
52 uint32_t srate;
53 dsp::gain_smoothing amount, dryamount;
54 int predelay_amt;
55 float meter_wet, meter_out;
56 uint32_t clip;
58 void params_changed();
59 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
60 void activate();
61 void set_sample_rate(uint32_t sr);
62 void deactivate();
65 /**********************************************************************
66 * VINTAGE DELAY by Krzysztof Foltman
67 **********************************************************************/
69 class vintage_delay_audio_module: public audio_module<vintage_delay_metadata>
71 public:
72 // 1MB of delay memory per channel... uh, RAM is cheap
73 enum { MAX_DELAY = 262144, ADDR_MASK = MAX_DELAY - 1 };
74 enum { MIXMODE_STEREO, MIXMODE_PINGPONG, MIXMODE_LR, MIXMODE_RL };
75 float buffers[2][MAX_DELAY];
76 int bufptr, deltime_l, deltime_r, mixmode, medium, old_medium;
77 /// number of table entries written (value is only important when it is less than MAX_DELAY, which means that the buffer hasn't been totally filled yet)
78 int age;
80 dsp::gain_smoothing amt_left, amt_right, fb_left, fb_right, dry, chmix;
82 dsp::biquad_d2 biquad_left[2], biquad_right[2];
84 uint32_t srate;
86 vintage_delay_audio_module();
88 void params_changed();
89 void activate();
90 void deactivate();
91 void set_sample_rate(uint32_t sr);
92 void calc_filters();
93 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
95 long _tap_avg;
96 long _tap_last;
99 /**********************************************************************
100 * COMPENSATION DELAY LINE by Vladimir Sadovnikov
101 **********************************************************************/
103 // The maximum distance for knobs
104 #define COMP_DELAY_MAX_DISTANCE (100.0 * 100.0 + 100.0 * 1.0 + 1.0)
105 // The actual speed of sound in normal conditions
106 #define COMP_DELAY_SOUND_SPEED_KM_H(temp) 1.85325 * (643.95 * std::pow(((temp + 273.15) / 273.15), 0.5))
107 #define COMP_DELAY_SOUND_SPEED_CM_S(temp) (COMP_DELAY_SOUND_SPEED_KM_H(temp) * (1000.0 * 100.0) /* cm/km */ / (60.0 * 60.0) /* s/h */)
108 #define COMP_DELAY_SOUND_FRONT_DELAY(temp) (1.0 / COMP_DELAY_SOUND_SPEED_CM_S(temp))
109 // The maximum delay may be reached by this plugin
110 #define COMP_DELAY_MAX_DELAY (COMP_DELAY_MAX_DISTANCE*COMP_DELAY_SOUND_FRONT_DELAY(50))
112 class comp_delay_audio_module: public audio_module<comp_delay_metadata>
114 public:
115 float *buffer;
116 uint32_t srate;
117 uint32_t buf_size; // guaranteed to be power of 2
118 uint32_t delay;
119 uint32_t write_ptr;
120 dsp::bypass bypass;
122 comp_delay_audio_module();
123 virtual ~comp_delay_audio_module();
125 void params_changed();
126 void activate();
127 void deactivate();
128 void set_sample_rate(uint32_t sr);
129 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
132 /**********************************************************************
133 * HAAS enhancer by Vladimir Sadovnikov
134 **********************************************************************/
135 #define HAAS_ENHANCER_MAX_DELAY (10 * 0.001) /* 10 MSec */
137 class haas_enhancer_audio_module: public audio_module<haas_enhancer_metadata>
139 public:
140 float *buffer;
141 uint32_t srate;
142 uint32_t buf_size; // guaranteed to be power of 2
143 uint32_t write_ptr;
145 dsp::bypass bypass;
146 vumeters meters;
148 uint32_t m_source, s_delay[2];
149 float s_bal_l[2], s_bal_r[2];
151 haas_enhancer_audio_module();
152 virtual ~haas_enhancer_audio_module();
154 void params_changed();
155 void activate();
156 void deactivate();
157 void set_sample_rate(uint32_t sr);
158 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
161 /**********************************************************************
162 * REVERSE DELAY
163 **********************************************************************/
165 class reverse_delay_audio_module: public audio_module<reverse_delay_metadata>
167 public:
168 enum { MAX_DELAY = 6144000, ADDR_MASK = MAX_DELAY - 1 };
169 float buffers[2][MAX_DELAY];
170 int counters[2];
171 dsp::overlap_window ow[2];
172 int deltime_l, deltime_r;
174 dsp::gain_smoothing fb_val, dry, width;
176 float feedback_buf[2];
178 uint32_t srate;
180 uint32_t line_state_old;
182 reverse_delay_audio_module();
184 void params_changed();
185 void activate();
186 void deactivate();
187 void set_sample_rate(uint32_t sr);
188 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
192 #endif