Merge branch 'master' of https://github.com/calf-studio-gear/calf
[calf.git] / src / calf / modules_tools.h
blob9adffc412df3d4776bfd59d612367a63afc7f233
1 /* Calf DSP plugin pack
2 * Assorted 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_TOOLS_H
22 #define CALF_MODULES_TOOLS_H
24 #include <assert.h>
25 #include <limits.h>
26 #include "biquad.h"
27 #include "inertia.h"
28 #include "audio_fx.h"
29 #include "analyzer.h"
30 #include "giface.h"
31 #include "metadata.h"
32 #include "loudness.h"
33 #include <math.h>
34 #include "plugin_tools.h"
35 #include "bypass.h"
37 namespace calf_plugins {
39 struct ladspa_plugin_info;
41 /**********************************************************************
42 * STEREO TOOLS by Markus Schmidt
43 **********************************************************************/
45 class stereo_audio_module:
46 public audio_module<stereo_metadata>
48 typedef stereo_audio_module AM;
49 uint32_t srate;
50 bool active;
51 dsp::bypass bypass;
52 float meter_inL, meter_inR, meter_outL, meter_outR, meter_phase;
53 vumeters meters;
55 float * buffer;
56 unsigned int pos;
57 unsigned int buffer_size;
58 static inline float sign(float x) {
59 if(x < 0) return -1.f;
60 if(x > 0) return 1.f;
61 return 0.f;
63 float _phase, _phase_sin_coef, _phase_cos_coef, _sc_level, _inv_atan_shape;
64 public:
65 stereo_audio_module();
66 ~stereo_audio_module();
67 void params_changed();
68 void activate();
69 void set_sample_rate(uint32_t sr);
70 void deactivate();
71 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
74 /**********************************************************************
75 * MONO INPUT by Markus Schmidt
76 **********************************************************************/
78 class mono_audio_module:
79 public audio_module<mono_metadata>
81 typedef mono_audio_module AM;
82 uint32_t srate;
83 bool active;
84 dsp::bypass bypass;
85 float meter_in, meter_outL, meter_outR;
86 vumeters meters;
88 float * buffer;
89 unsigned int pos;
90 unsigned int buffer_size;
91 static inline float sign(float x) {
92 if(x < 0) return -1.f;
93 if(x > 0) return 1.f;
94 return 0.f;
96 float _phase, _phase_sin_coef, _phase_cos_coef, _sc_level, _inv_atan_shape;
97 public:
98 mono_audio_module();
99 ~mono_audio_module();
100 void params_changed();
101 void activate();
102 void set_sample_rate(uint32_t sr);
103 void deactivate();
104 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
107 /**********************************************************************
108 * ANALYZER by Markus Schmidt and Christian Holschuh
109 **********************************************************************/
111 class analyzer_audio_module:
112 public audio_module<analyzer_metadata>, public phase_graph_iface,
113 public frequency_response_line_graph
115 typedef analyzer_audio_module AM;
116 uint32_t srate;
117 bool active;
118 float envelope;
119 float attack_coef;
120 float release_coef;
121 uint32_t clip_L, clip_R;
122 float meter_L, meter_R;
123 analyzer _analyzer;
124 public:
125 analyzer_audio_module();
126 void params_changed();
127 void activate();
128 void set_sample_rate(uint32_t sr);
129 void deactivate();
130 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
131 bool get_phase_graph(float ** _buffer, int * _length, int * _mode, bool * _use_fade, float * _fade, int * _accuracy, bool * _display) const;
132 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
133 bool get_moving(int index, int subindex, int &direction, float *data, int x, int y, int &offset, uint32_t &color) const;
134 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
135 bool get_layers(int index, int generation, unsigned int &layers) const;
136 ~analyzer_audio_module();
137 protected:
138 static const int max_phase_buffer_size = 8192;
139 int phase_buffer_size;
140 float *phase_buffer;
141 int ppos;
142 int plength;
145 /**********************************************************************
146 * WIDGET TEST
147 **********************************************************************/
149 class widgets_audio_module:
150 public audio_module<widgets_metadata>
152 uint32_t srate;
153 vumeters meters;
154 dsp::simple_lfo lfo_sin, lfo_sqr, lfo_tri;
155 public:
156 widgets_audio_module();
157 ~widgets_audio_module();
158 void params_changed();
159 void set_sample_rate(uint32_t sr);
160 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
164 #endif