// Copyright (C) 2022 Then Try This // // 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; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include #include #include using namespace spiralcore; using namespace std; static const int MAX_FFT_LENGTH = 4096; FFT::FFT(u32 length, u32 bins) : m_length(length), m_num_bins(bins), m_in(new double[length]), m_spectrum(new fftw_complex[length]), m_bin(new float[bins]) { memset(m_spectrum,0,sizeof(fftw_complex)*length); m_plan = fftw_plan_dft_r2c_1d(m_length, m_in, m_spectrum, FFTW_ESTIMATE); } FFT::~FFT() { delete[] m_in; fftw_destroy_plan(m_plan); } void FFT::impulse2freq(const float *imp) { unsigned int i; for (i=0; ihighest) { index=i; highest=t; } } float freq = index * (SRATE/(float)m_length); if (freq<0.01) freq=0.01; return freq; } void FFT::calculate_bins() { float useful_area = m_length/2; for (unsigned int n=0; n