Ardour  9.0-pre0-582-g084a23a80d
fft_result.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2009-2012 David Robillard <d@drobilla.net>
3  * Copyright (C) 2016 Robin Gareus <robin@gareus.org>
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
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
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 #ifndef __ardour_fft_result_h
21 #define __ardour_fft_result_h
22 
23 #include <math.h>
24 #include <fftw3.h>
25 
26 #include <gdkmm/color.h>
27 
28 #include <string>
29 #include <vector>
30 
31 class FFTGraph;
32 
33 class FFTResult
34 {
35 public:
36 
37  ~FFTResult () = default;
38 
39  void analyzeWindow (float *window);
40  void finalize ();
41 
42  unsigned int length () const { return _dataSize; }
43 
44  float avgAt (unsigned int x, bool p) const
45  { return p ? _data_prop_avg[x] : _data_flat_avg[x]; }
46  float maxAt (unsigned int x, bool p) const
47  { return p ? _data_prop_max[x] : _data_flat_max[x]; }
48  float minAt (unsigned int x, bool p) const
49  { return p ? _data_prop_min[x] : _data_flat_min[x]; }
50 
51  float minimum (bool p) const
52  { return p ? _min_prop : _min_flat; }
53  float maximum (bool p) const
54  { return p ? _max_prop : _max_flat; }
55 
56  const Gdk::Color& get_color () const { return _color; }
57 
58 private:
59  FFTResult (FFTGraph *graph, Gdk::Color color, std::string trackname);
60  friend class FFTGraph;
61 
63 
64  unsigned int _windowSize;
65  unsigned int _dataSize;
66 
67  int _averages;
68 
69  float _min_flat;
70  float _max_flat;
71  float _min_prop;
72  float _max_prop;
73 
74  std::vector<float> _data_flat_avg;
75  std::vector<float> _data_flat_max;
76  std::vector<float> _data_flat_min;
77  std::vector<float> _data_prop_avg;
78  std::vector<float> _data_prop_max;
79  std::vector<float> _data_prop_min;
80 
82  std::string _trackname;
83 
84  static float power_to_db (float v) { return v > 1e-20 ? 10.0f * log10f (v) : -200.0f; }
85 };
86 
87 #endif /* __ardour_fft_result_h */
~FFTResult()=default
float minimum(bool p) const
Definition: fft_result.h:51
std::vector< float > _data_prop_min
Definition: fft_result.h:79
unsigned int length() const
Definition: fft_result.h:42
const Gdk::Color & get_color() const
Definition: fft_result.h:56
float maxAt(unsigned int x, bool p) const
Definition: fft_result.h:46
std::string _trackname
Definition: fft_result.h:82
Gdk::Color _color
Definition: fft_result.h:81
std::vector< float > _data_flat_max
Definition: fft_result.h:75
FFTGraph * _graph
Definition: fft_result.h:62
void finalize()
float _min_flat
Definition: fft_result.h:69
std::vector< float > _data_flat_min
Definition: fft_result.h:76
float _max_flat
Definition: fft_result.h:70
float maximum(bool p) const
Definition: fft_result.h:53
std::vector< float > _data_prop_max
Definition: fft_result.h:78
float minAt(unsigned int x, bool p) const
Definition: fft_result.h:48
std::vector< float > _data_prop_avg
Definition: fft_result.h:77
void analyzeWindow(float *window)
unsigned int _windowSize
Definition: fft_result.h:64
float _min_prop
Definition: fft_result.h:71
int _averages
Definition: fft_result.h:67
FFTResult(FFTGraph *graph, Gdk::Color color, std::string trackname)
static float power_to_db(float v)
Definition: fft_result.h:84
unsigned int _dataSize
Definition: fft_result.h:65
float _max_prop
Definition: fft_result.h:72
std::vector< float > _data_flat_avg
Definition: fft_result.h:74
float avgAt(unsigned int x, bool p) const
Definition: fft_result.h:44
PBD::PropertyDescriptor< uint32_t > color