Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2006 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_AIMPZFC_H 00020 #define MARSYAS_AIMPZFC_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 { 00047 class marsyas_EXPORT AimPZFC: public MarSystem 00048 { 00049 private: 00050 mrs_real zcrs_; 00051 00052 void myUpdate(MarControlPtr sender); 00053 void addControls(); 00054 00055 // Reset all internal state variables to their initial values 00056 void ResetInternal(); 00057 00058 // Prepare the module 00059 bool InitializeInternal(); 00060 00061 // Does the MarSystem need initialization? 00062 bool is_initialized; 00063 00064 // What changes cause it to need initialization? 00065 mrs_real initialized_israte; 00066 mrs_real initialized_inobservations; 00067 mrs_real initialized_mindamp; 00068 mrs_real initialized_maxdamp; 00069 mrs_real initialized_cf_max; 00070 mrs_real initialized_cf_min; 00071 00072 // Does the MarSystem need reset? 00073 bool is_reset; 00074 00075 // What changes cause it to need a reset? 00076 mrs_natural reseted_inobservations; 00077 mrs_natural reseted_agc_factor; 00078 00079 // Set the filterbank parameters according to a fit matrix from Unoki 00080 // bool SetPZBankCoeffsERB(); 00081 bool SetPZBankCoeffsERBFitted(); 00082 bool SetPZBankCoeffsOrig(); 00083 00084 // Sets the general filterbank coefficients 00085 bool SetPZBankCoeffs(); 00086 00087 // Automatic Gain Control 00088 void AGCDampStep(); 00089 00090 00091 // Detector function - halfwave rectification etc. Used internally, 00092 // but not applied to the output. 00093 double DetectFun(double fIN); 00094 00095 // Minimum 00096 inline double Minimum(double a, double b); 00097 00098 int channel_count_; 00099 // int buffer_length_; 00100 int agc_stage_count_; 00101 // double sample_rate_; 00102 double last_input_; 00103 00104 double agc_factor_; 00105 double offset_; 00106 00107 00108 // Parameters 00109 // User-settable scalars 00110 MarControlPtr ctrl_pole_damping_; 00111 MarControlPtr ctrl_zero_damping_; 00112 MarControlPtr ctrl_zero_factor_; 00113 MarControlPtr ctrl_step_factor_; 00114 MarControlPtr ctrl_bandwidth_over_cf_; 00115 MarControlPtr ctrl_min_bandwidth_hz_; 00116 MarControlPtr ctrl_agc_factor_; 00117 MarControlPtr ctrl_cf_max_; 00118 MarControlPtr ctrl_cf_min_; 00119 MarControlPtr ctrl_mindamp_; 00120 MarControlPtr ctrl_maxdamp_; 00121 MarControlPtr ctrl_do_agc_step_; 00122 MarControlPtr ctrl_use_fit_; 00123 00124 // Internal Buffers 00125 // Initialised once 00126 // 00127 // sness - TODO - Eventually make these realvecs. However, in the 00128 // existing code there is quite a bit of stuff that involves STL 00129 // methods, so I thought it would be safer to use STL for now. 00130 std::vector<double> pole_dampings_; 00131 std::vector<double> agc_epsilons_; 00132 std::vector<double> agc_gains_; 00133 std::vector<double> pole_frequencies_; 00134 std::vector<double> za0_; 00135 std::vector<double> za1_; 00136 std::vector<double> za2_; 00137 std::vector<double> rmin_; 00138 std::vector<double> rmax_; 00139 std::vector<double> xmin_; 00140 std::vector<double> xmax_; 00141 00142 // Modified by algorithm at each time step 00143 std::vector<double> detect_; 00144 std::vector<std::vector<double> > agc_state_; 00145 std::vector<double> state_1_; 00146 std::vector<double> state_2_; 00147 std::vector<double> previous_out_; 00148 std::vector<double> pole_damps_mod_; 00149 std::vector<double> inputs_; 00150 00151 // Hold the centre frequencies, which we will output to the second half 00152 // of the observations 00153 std::vector<double> centre_frequencies_; 00154 00155 public: 00156 AimPZFC(std::string name); 00157 AimPZFC(const AimPZFC& a); 00158 00159 ~AimPZFC(); 00160 MarSystem* clone() const; 00161 00162 void myProcess(realvec& in, realvec& out); 00163 }; 00164 00165 }//namespace marsyas 00166 00167 #endif