prepare loudness normalization
[ardour.git] / libs / audiographer / audiographer / general / analyser.h
1 /*
2  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17  */
18
19 #ifndef AUDIOGRAPHER_ANALYSER_H
20 #define AUDIOGRAPHER_ANALYSER_H
21
22 #include <fftw3.h>
23 #include "loudness_reader.h"
24 #include "ardour/export_analysis.h"
25
26 namespace AudioGrapher
27 {
28
29 class LIBAUDIOGRAPHER_API Analyser : public LoudnessReader
30 {
31   public:
32         Analyser (float sample_rate, unsigned int channels, framecnt_t bufsize, framecnt_t n_samples);
33         ~Analyser ();
34         void process (ProcessContext<float> const & c);
35         ARDOUR::ExportAnalysisPtr result ();
36
37         void set_normalization_gain (float gain) {
38                 _result.normalized = true;
39                 _result.norm_gain_factor = gain;
40         }
41
42         static const float fft_range_db;
43
44         using Sink<float>::process;
45
46         private:
47         float fft_power_at_bin (const uint32_t b, const float norm) const;
48
49         ARDOUR::ExportAnalysis _result;
50
51         framecnt_t   _n_samples;
52         framecnt_t   _pos;
53         framecnt_t   _spp;
54         framecnt_t   _fpp;
55
56         float*     _hann_window;
57         uint32_t   _fft_data_size;
58         double     _fft_freq_per_bin;
59         float*     _fft_data_in;
60         float*     _fft_data_out;
61         float*     _fft_power;
62         fftwf_plan _fft_plan;
63 };
64
65 } // namespace
66
67 #endif