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 30 class FFTGraph; 31 32 class FFTResult 33 { 34 public: 35 36 ~FFTResult (); 37 38 void analyzeWindow (float *window); 39 void finalize (); 40 length()41 unsigned int length () const { return _dataSize; } 42 avgAt(unsigned int x,bool p)43 float avgAt (unsigned int x, bool p) const 44 { return p ? _data_prop_avg[x] : _data_flat_avg[x]; } maxAt(unsigned int x,bool p)45 float maxAt (unsigned int x, bool p) const 46 { return p ? _data_prop_max[x] : _data_flat_max[x]; } minAt(unsigned int x,bool p)47 float minAt (unsigned int x, bool p) const 48 { return p ? _data_prop_min[x] : _data_flat_min[x]; } 49 minimum(bool p)50 float minimum (bool p) const 51 { return p ? _min_prop : _min_flat; } maximum(bool p)52 float maximum (bool p) const 53 { return p ? _max_prop : _max_flat; } 54 get_color()55 const Gdk::Color& get_color () const { return _color; } 56 57 private: 58 FFTResult (FFTGraph *graph, Gdk::Color color, std::string trackname); 59 friend class FFTGraph; 60 61 int _averages; 62 63 float* _data_flat_avg; 64 float* _data_flat_max; 65 float* _data_flat_min; 66 float* _data_prop_avg; 67 float* _data_prop_max; 68 float* _data_prop_min; 69 70 unsigned int _windowSize; 71 unsigned int _dataSize; 72 73 float _min_flat; 74 float _max_flat; 75 float _min_prop; 76 float _max_prop; 77 78 FFTGraph *_graph; 79 80 Gdk::Color _color; 81 std::string _trackname; 82 power_to_db(float v)83 static float power_to_db (float v) { return v > 1e-20 ? 10.0f * log10f (v) : -200.0f; } 84 }; 85 86 #endif /* __ardour_fft_result_h */ 87