1 /* 2 * Copyright (C) 2016 Robin Gareus <robin@gareus.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (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 along 15 * with this program; if not, write to the Free Software Foundation, Inc., 16 * 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, samplecnt_t bufsize, samplecnt_t n_samples); 33 ~Analyser (); 34 void process (ProcessContext<float> const & c); 35 ARDOUR::ExportAnalysisPtr result (bool ptr = false); 36 37 void set_duration (samplecnt_t n_samples); 38 set_normalization_gain(float gain)39 void set_normalization_gain (float gain) { 40 _result.normalized = true; 41 _result.norm_gain_factor = gain; 42 } 43 44 static const float fft_range_db; 45 46 using Sink<float>::process; 47 48 private: 49 float fft_power_at_bin (const uint32_t b, const float norm) const; 50 51 ARDOUR::ExportAnalysisPtr _rp; 52 ARDOUR::ExportAnalysis& _result; 53 54 samplecnt_t _n_samples; 55 samplecnt_t _pos; 56 samplecnt_t _spp; 57 samplecnt_t _fpp; 58 59 float* _hann_window; 60 uint32_t _fft_data_size; 61 double _fft_freq_per_bin; 62 float* _fft_data_in; 63 float* _fft_data_out; 64 float* _fft_power; 65 fftwf_plan _fft_plan; 66 }; 67 68 } // namespace 69 70 #endif 71