Button: emit slopes (fix for stuck modulaor plug-ins)
[calf.git] / src / calf / modules_delay.h
blob0d8cfb80a20091874bd13abf7dfede3eceba0bca
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 "inertia.h"
29 #include "audio_fx.h"
30 #include "giface.h"
31 #include "metadata.h"
32 #include "loudness.h"
33 #include <math.h>
34 #include "plugin_tools.h"
36 namespace calf_plugins {
38 struct ladspa_plugin_info;
40 /**********************************************************************
41 * REVERB by Krzysztof Foltman
42 **********************************************************************/
44 class reverb_audio_module: public audio_module<reverb_metadata>
46 vumeters meters;
47 public:
48 dsp::reverb reverb;
49 dsp::simple_delay<131072, dsp::stereo_sample<float> > pre_delay;
50 dsp::onepole<float> left_lo, right_lo, left_hi, right_hi;
51 uint32_t srate;
52 dsp::gain_smoothing amount, dryamount;
53 int predelay_amt;
54 float meter_wet, meter_out;
55 uint32_t clip;
57 void params_changed();
58 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
59 void activate();
60 void set_sample_rate(uint32_t sr);
61 void deactivate();
64 /**********************************************************************
65 * VINTAGE DELAY by Krzysztof Foltman
66 **********************************************************************/
68 class vintage_delay_audio_module: public audio_module<vintage_delay_metadata>
70 public:
71 // 1MB of delay memory per channel... uh, RAM is cheap
72 enum { MAX_DELAY = 262144, ADDR_MASK = MAX_DELAY - 1 };
73 enum { MIXMODE_STEREO, MIXMODE_PINGPONG, MIXMODE_LR, MIXMODE_RL };
74 float buffers[2][MAX_DELAY];
75 int bufptr, deltime_l, deltime_r, mixmode, medium, old_medium;
76 /// 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)
77 int age;
79 dsp::gain_smoothing amt_left, amt_right, fb_left, fb_right, dry, chmix;
81 dsp::biquad_d2 biquad_left[2], biquad_right[2];
83 uint32_t srate;
85 vintage_delay_audio_module();
87 void params_changed();
88 void activate();
89 void deactivate();
90 void set_sample_rate(uint32_t sr);
91 void calc_filters();
92 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
94 long _tap_avg;
95 long _tap_last;
98 /**********************************************************************
99 * COMPENSATION DELAY LINE by Vladimir Sadovnikov
100 **********************************************************************/
102 // The maximum distance for knobs
103 #define COMP_DELAY_MAX_DISTANCE (100.0 * 100.0 + 100.0 * 1.0 + 1.0)
104 // The actual speed of sound in normal conditions
105 #define COMP_DELAY_SOUND_SPEED_KM_H(temp) 1.85325 * (643.95 * std::pow(((temp + 273.15) / 273.15), 0.5))
106 #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 */)
107 #define COMP_DELAY_SOUND_FRONT_DELAY(temp) (1.0 / COMP_DELAY_SOUND_SPEED_CM_S(temp))
108 // The maximum delay may be reached by this plugin
109 #define COMP_DELAY_MAX_DELAY (COMP_DELAY_MAX_DISTANCE*COMP_DELAY_SOUND_FRONT_DELAY(50))
111 class comp_delay_audio_module: public audio_module<comp_delay_metadata>
113 public:
114 float *buffer;
115 uint32_t srate;
116 uint32_t buf_size; // guaranteed to be power of 2
117 uint32_t delay;
118 uint32_t write_ptr;
120 comp_delay_audio_module();
121 virtual ~comp_delay_audio_module();
123 void params_changed();
124 void activate();
125 void deactivate();
126 void set_sample_rate(uint32_t sr);
127 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
131 #endif