1 /* 2 * fft_helpers.h - some functions around FFT analysis 3 * 4 * Copyright (c) 2008-2012 Tobias Doerffel <tobydox/at/users.sourceforge.net> 5 * 6 * This file is part of LMMS - https://lmms.io 7 * 8 * This program is free software; you can redistribute it and/or 9 * modify it under the terms of the GNU General Public 10 * License as published by the Free Software Foundation; either 11 * version 2 of the License, or (at your option) any later version. 12 * 13 * This program is distributed in the hope that it will be useful, 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 16 * General Public License for more details. 17 * 18 * You should have received a copy of the GNU General Public 19 * License along with this program (see COPYING); if not, write to the 20 * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 21 * Boston, MA 02110-1301 USA. 22 * 23 */ 24 25 26 #ifndef FFT_HELPERS_H 27 #define FFT_HELPERS_H 28 29 #include "export.h" 30 31 #include <fftw3.h> 32 33 const int FFT_BUFFER_SIZE = 2048; 34 35 enum WINDOWS 36 { 37 KAISER=1, 38 RECTANGLE, 39 HANNING, 40 HAMMING 41 }; 42 43 /* returns biggest value from abs_spectrum[spec_size] array 44 * 45 * returns -1 on error 46 */ 47 float EXPORT maximum( float * _abs_spectrum, unsigned int _spec_size ); 48 49 /* apply hanning or hamming window to channel 50 * 51 * returns -1 on error 52 */ 53 int EXPORT hanming( float * _timebuffer, int _length, WINDOWS _type ); 54 55 /* compute absolute values of complex_buffer, save to absspec_buffer 56 * take care that - compl_len is not bigger than complex_buffer! 57 * - absspec buffer is big enough! 58 * 59 * returns 0 on success, else -1 60 */ 61 int EXPORT absspec( fftwf_complex * _complex_buffer, float * _absspec_buffer, 62 int _compl_length ); 63 64 /* build fewer subbands from many absolute spectrum values 65 * take care that - compressedbands[] array num_new elements long 66 * - num_old > num_new 67 * 68 * returns 0 on success, else -1 69 */ 70 int EXPORT compressbands( float * _absspec_buffer, float * _compressedband, 71 int _num_old, int _num_new, int _bottom, int _top ); 72 73 74 int EXPORT calc13octaveband31( float * _absspec_buffer, float * _subbands, 75 int _num_spec, float _max_frequency ); 76 77 /* compute power of finite time sequence 78 * take care num_values is length of timesignal[] 79 * 80 * returns power on success, else -1 81 */ 82 float EXPORT signalpower(float *timesignal, int num_values); 83 84 #endif 85