Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2010 George Tzanetakis <gtzan@cs.uvic.ca> 00003 ** 00004 ** This program is free software; you can redistribute it and/or modify 00005 ** it under the terms of the GNU General Public License as published by 00006 ** the Free Software Foundation; either version 2 of the License, or 00007 ** (at your option) any later version. 00008 ** 00009 ** This program is distributed in the hope that it will be useful, 00010 ** but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 ** GNU General Public License for more details. 00013 ** 00014 ** You should have received a copy of the GNU General Public License 00015 ** along with this program; if not, write to the Free Software 00016 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00017 */ 00018 00019 #ifndef MARSYAS_AIMPZFC2_H 00020 #define MARSYAS_AIMPZFC2_H 00021 00022 #include <marsyas/system/MarSystem.h> 00023 00024 // sness - TODO - Eventually make these realvecs. However, in the 00025 // existing code there is quite a bit of stuff that involves STL 00026 // methods, so I thought it would be safer to use STL for now. 00027 #include <vector> 00028 00029 namespace Marsyas 00030 { 00049 class marsyas_EXPORT AimPZFC2: public MarSystem 00050 { 00051 private: 00052 mrs_real zcrs_; 00053 00054 void myUpdate(MarControlPtr sender); 00055 void addControls(); 00056 00057 // Reset all internal state variables to their initial values 00058 void ResetInternal(); 00059 00060 // Prepare the module 00061 bool InitializeInternal(); 00062 00063 // Does the MarSystem need initialization? 00064 bool is_initialized; 00065 00066 // What changes cause it to need initialization? 00067 mrs_real initialized_israte; 00068 mrs_real initialized_inobservations; 00069 mrs_real initialized_mindamp; 00070 mrs_real initialized_maxdamp; 00071 mrs_real initialized_cf_max; 00072 mrs_real initialized_cf_min; 00073 00074 // Does the MarSystem need reset? 00075 bool is_reset; 00076 00077 // What changes cause it to need a reset? 00078 mrs_natural reseted_inobservations; 00079 mrs_natural reseted_agc_factor; 00080 00081 // Set the filterbank parameters according to a fit matrix from Unoki 00082 // bool SetPZBankCoeffsERB(); 00083 bool SetPZBankCoeffsERBFitted(); 00084 bool SetPZBankCoeffsOrig(); 00085 00086 // Sets the general filterbank coefficients 00087 bool SetPZBankCoeffs(); 00088 00089 // Automatic Gain Control 00090 void AGCDampStep(); 00091 00092 00093 // Detector function - halfwave rectification etc. Used internally, 00094 // but not applied to the output. 00095 double DetectFun(double fIN); 00096 00097 // Minimum 00098 inline double Minimum(double a, double b); 00099 00100 int channel_count_; 00101 // int buffer_length_; 00102 int agc_stage_count_; 00103 // double sample_rate_; 00104 double last_input_; 00105 00106 double agc_factor_; 00107 double offset_; 00108 00109 00110 // Parameters 00111 // User-settable scalars 00112 MarControlPtr ctrl_pole_damping_; 00113 MarControlPtr ctrl_zero_damping_; 00114 MarControlPtr ctrl_zero_factor_; 00115 MarControlPtr ctrl_step_factor_; 00116 MarControlPtr ctrl_bandwidth_over_cf_; 00117 MarControlPtr ctrl_min_bandwidth_hz_; 00118 MarControlPtr ctrl_agc_factor_; 00119 MarControlPtr ctrl_cf_max_; 00120 MarControlPtr ctrl_cf_min_; 00121 MarControlPtr ctrl_mindamp_; 00122 MarControlPtr ctrl_maxdamp_; 00123 MarControlPtr ctrl_do_agc_step_; 00124 MarControlPtr ctrl_use_fit_; 00125 00126 // Internal Buffers 00127 // Initialised once 00128 // 00129 00130 mrs_realvec pole_dampings_; 00131 mrs_realvec agc_epsilons_; 00132 mrs_realvec agc_gains_; 00133 mrs_realvec pole_frequencies_; 00134 00135 00136 00137 std::vector<double> za0_; 00138 std::vector<double> za1_; 00139 std::vector<double> za2_; 00140 std::vector<double> rmin_; 00141 std::vector<double> rmax_; 00142 std::vector<double> xmin_; 00143 std::vector<double> xmax_; 00144 00145 // Modified by algorithm at each time step 00146 std::vector<double> detect_; 00147 std::vector<std::vector<double> > agc_state_; 00148 std::vector<double> state_1_; 00149 std::vector<double> state_2_; 00150 // std::vector<double> previous_out_; 00151 mrs_realvec previous_out_; 00152 00153 std::vector<double> pole_damps_mod_; 00154 mrs_realvec inputs_; 00155 00156 // Hold the centre frequencies, which we will output to the second half 00157 // of the observations 00158 std::vector<double> centre_frequencies_; 00159 00160 public: 00161 AimPZFC2(std::string name); 00162 AimPZFC2(const AimPZFC2& a); 00163 00164 ~AimPZFC2(); 00165 MarSystem* clone() const; 00166 00167 void myProcess(realvec& in, realvec& out); 00168 }; 00169 00170 }//namespace marsyas 00171 00172 #endif