HAAS Stereo Enhancer
[calf.git] / src / calf / analyzer.h
blob10518e8f269d12cff32f0f4908e5b703ea437d9b
1 /* Calf Analyzer FFT Library
2 * Copyright (C) 2007-2013 Krzysztof Foltman, Markus Schmidt,
3 * Christian Holschuh and others
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Lesser General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General
16 * Public License along with this program; if not, write to the
17 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301 USA
21 #ifndef CALF_ANALYZER_H
22 #define CALF_ANALYZER_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 "giface.h"
31 #include "metadata.h"
32 #include "loudness.h"
33 #include <math.h>
34 #include "plugin_tools.h"
36 #define MATH_E 2.718281828
38 namespace calf_plugins {
40 class analyzer: public frequency_response_line_graph
42 private:
43 mutable int _accuracy;
44 mutable int _acc;
45 mutable int _scale;
46 mutable int _post;
47 mutable int _hold;
48 mutable int _smooth;
49 mutable int _speed;
50 mutable int _windowing;
51 mutable int _view;
52 mutable int _freeze;
53 mutable int _mode;
54 mutable float _resolution;
55 mutable float _offset;
56 mutable bool _falling;
57 mutable int _draw_upper;
60 public:
61 uint32_t srate;
62 analyzer();
63 void process(float L, float R);
64 void set_sample_rate(uint32_t sr);
65 bool set_mode(int mode);
66 void invalidate();
67 void set_params(float resolution, float offset, int accuracy, int hold, int smoothing, int mode, int scale, int post, int speed, int windowing, int view, int freeze);
68 ~analyzer();
69 bool do_fft(int subindex, int points) const;
70 void draw(int subindex, float *data, int points, bool fftdone) const;
71 bool get_graph(int subindex, int phase, float *data, int points, cairo_iface *context, int *mode) const;
72 bool get_moving(int subindex, int &direction, float *data, int x, int y, int &offset, uint32_t &color) const;
73 bool get_gridline(int subindex, int phase, float &pos, bool &vertical, std::string &legend, cairo_iface *context) const;
74 bool get_layers(int generation, unsigned int &layers) const;
75 protected:
76 int fft_buffer_size;
77 float *fft_buffer;
78 int *spline_buffer;
79 int fpos;
80 mutable bool sanitize, recreate_plan;
81 mutable fftwf_plan fft_plan;
82 static const int max_fft_cache_size = 32768;
83 static const int max_fft_buffer_size = max_fft_cache_size * 2;
84 float *fft_inL, *fft_outL;
85 float *fft_inR, *fft_outR;
86 float *fft_smoothL, *fft_smoothR;
87 float *fft_deltaL, *fft_deltaR;
88 float *fft_holdL, *fft_holdR;
89 float *fft_freezeL, *fft_freezeR;
90 mutable int lintrans;
91 mutable int analyzer_phase_drawn;
95 #endif