/* * fft_helpers.cpp - some functions around FFT analysis * * Copyright (c) 2008 Tobias Doerffel * * This file is part of Linux MultiMedia Studio - http://lmms.sourceforge.net * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public * License as published by the Free Software Foundation; either * version 2 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * General Public License for more details. * * You should have received a copy of the GNU General Public * License along with this program (see COPYING); if not, write to the * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, * Boston, MA 02110-1301 USA. * */ #include "fft_helpers.h" #ifdef LMMS_HAVE_FFTW3F #include /* returns biggest value from abs_spectrum[spec_size] array returns -1 on error */ float maximum(float *abs_spectrum, unsigned int spec_size) { float maxi=0; unsigned int i; if ( abs_spectrum==NULL ) return -1; if (spec_size<=0) return -1; for ( i=0; imaxi ) maxi=abs_spectrum[i]; } return maxi; } /* apply hanning or hamming window to channel returns -1 on error */ int hanming(float *timebuffer, int length, WINDOWS type) { int i; float alpha; if ( (timebuffer==NULL)||(length<=0) ) return -1; switch (type) { case HAMMING: alpha=0.54; break; case HANNING: default: alpha=0.5; break; } for ( i=0; i num_new returns 0 on success, else -1 */ int compressbands(float *absspec_buffer, float *compressedband, int num_old, int num_new, int bottom, int top) { float ratio; int i, usefromold; float j; float j_min, j_max; if ( (absspec_buffer==NULL)||(compressedband==NULL) ) return -1; if ( num_old=num_old ) top=num_old-1; usefromold=num_old-(num_old-top)-bottom; ratio=(float)usefromold/(float)num_new; // foreach new subband for ( i=0; i