HAAS Stereo Enhancer
[calf.git] / src / calf / modules_tools.h
blob567e3f5538ac6a32fa88a13dbefe82964541de72
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 <fftw3.h>
26 #include <limits.h>
27 #include "biquad.h"
28 #include "inertia.h"
29 #include "audio_fx.h"
30 #include "analyzer.h"
31 #include "giface.h"
32 #include "metadata.h"
33 #include "loudness.h"
34 #include <math.h>
35 #include "plugin_tools.h"
36 #include "bypass.h"
38 namespace calf_plugins {
40 struct ladspa_plugin_info;
42 /**********************************************************************
43 * STEREO TOOLS by Markus Schmidt
44 **********************************************************************/
46 class stereo_audio_module:
47 public audio_module<stereo_metadata>
49 typedef stereo_audio_module AM;
50 float LL, LR, RL, RR;
51 uint32_t srate;
52 bool active;
53 dsp::bypass bypass;
54 float meter_inL, meter_inR, meter_outL, meter_outR, meter_phase;
55 vumeters meters;
57 float * buffer;
58 unsigned int pos;
59 unsigned int buffer_size;
60 static inline float sign(float x) {
61 if(x < 0) return -1.f;
62 if(x > 0) return 1.f;
63 return 0.f;
65 float _phase, _phase_sin_coef, _phase_cos_coef, _sc_level, _inv_atan_shape;
66 public:
67 stereo_audio_module();
68 ~stereo_audio_module();
69 void params_changed();
70 void activate();
71 void set_sample_rate(uint32_t sr);
72 void deactivate();
73 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
76 /**********************************************************************
77 * MONO INPUT by Markus Schmidt
78 **********************************************************************/
80 class mono_audio_module:
81 public audio_module<mono_metadata>
83 typedef mono_audio_module AM;
84 uint32_t srate;
85 bool active;
86 dsp::bypass bypass;
87 float meter_in, meter_outL, meter_outR;
88 vumeters meters;
90 float * buffer;
91 unsigned int pos;
92 unsigned int buffer_size;
93 static inline float sign(float x) {
94 if(x < 0) return -1.f;
95 if(x > 0) return 1.f;
96 return 0.f;
98 float _phase, _phase_sin_coef, _phase_cos_coef, _sc_level, _inv_atan_shape;
99 public:
100 mono_audio_module();
101 ~mono_audio_module();
102 void params_changed();
103 void activate();
104 void set_sample_rate(uint32_t sr);
105 void deactivate();
106 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
109 /**********************************************************************
110 * ANALYZER by Markus Schmidt and Christian Holschuh
111 **********************************************************************/
113 class analyzer_audio_module:
114 public audio_module<analyzer_metadata>, public phase_graph_iface,
115 public frequency_response_line_graph
117 typedef analyzer_audio_module AM;
118 uint32_t srate;
119 bool active;
120 float envelope;
121 float attack_coef;
122 float release_coef;
123 uint32_t clip_L, clip_R;
124 float meter_L, meter_R;
125 analyzer _analyzer;
126 public:
127 analyzer_audio_module();
128 void params_changed();
129 void activate();
130 void set_sample_rate(uint32_t sr);
131 void deactivate();
132 uint32_t process(uint32_t offset, uint32_t numsamples, uint32_t inputs_mask, uint32_t outputs_mask);
133 bool get_phase_graph(float ** _buffer, int * _length, int * _mode, bool * _use_fade, float * _fade, int * _accuracy, bool * _display) const;
134 bool get_graph(int index, int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
135 bool get_moving(int index, int subindex, int &direction, float *data, int x, int y, int &offset, uint32_t &color) const;
136 bool get_gridline(int index, int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
137 bool get_layers(int index, int generation, unsigned int &layers) const;
138 ~analyzer_audio_module();
139 protected:
140 static const int max_phase_buffer_size = 8192;
141 int phase_buffer_size;
142 float *phase_buffer;
143 int ppos;
144 int plength;
148 #endif