// Copyright 2007 "Gilles Degottex" // This file is part of "Music" // "Music" is free software; you can redistribute it and/or modify // it under the terms of the GNU Lesser General Public License as published by // the Free Software Foundation; either version 2.1 of the License, or // (at your option) any later version. // // "Music" 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 Lesser General Public License for more details. // // You should have received a copy of the GNU Lesser 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 "CombedFT.h" #include #include using namespace std; using namespace Math; #include "Music.h" #include "SPWindow.h" #include "FreqAnalysis.h" namespace Music { CombedFT::CombedFT() { m_use_audibility_treshold = false; m_audib_ratio = 0.1; m_zp_factor = 1.0; m_window_factor = 1.0; init(); } void CombedFT::setZeroPaddingFactor(double zp) { if(zp!=m_zp_factor) { m_zp_factor = zp; init(); } } void CombedFT::setWindowFactor(double wf) { if(wf!=m_window_factor) { m_window_factor = wf; init(); } } void CombedFT::init() { if(GetSamplingRate()<=0) return; m_f0 = 0.0; int win_size = int(m_window_factor*GetSamplingRate()/h2f(GetSemitoneMin()));// at least m_window_factor period of the lowest freq int best_size = 2; while(best_sizem_max_amplitude) m_max_amplitude = abs(buff[i]); } for(int i=m_win.size(); im_components_max) { max_index = i; m_components_max = m_comb.in[i]; } } m_f0 = 0.0; if(m_components_max>getComponentTreshold()) { m_f0 = PeakRefinementLogParabola(m_plan.out, max_index)*double(GetSamplingRate())/m_plan.size(); // TODO TEST *win[i]; // me semble qu'une trans de harm signal n'est pas trop discontinue aux extrémités m_comb.execute(); for(size_t i=0; i temp_comp(int(m_components.size()/step), 0.0); for(int i=1; imax_amp) { max_index = i; max_amp = m_components[i]; } } if(max_index>0) m_f0 /= max_index; } // cerr << " final: " << GetSamplingRate() << ":" << m_f0 << endl; } CombedFT::~CombedFT() { } }