Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/CARFAC.h
Go to the documentation of this file.
00001 /*
00002 ** Copyright (C) 1998-2011 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_CARFAC_H
00020 #define MARSYAS_CARFAC_H
00021 
00022 #include <marsyas/system/MarSystem.h>
00023 #include "CARFAC_coeffs.h"
00024 
00025 namespace Marsyas
00026 {
00032 class CARFAC: public MarSystem
00033 {
00034 
00035 private:
00036   //Add specific controls needed by this MarSystem.
00037   void addControls();
00038   void myUpdate(MarControlPtr sender);
00039 
00040   MarControlPtr ctrl_printcoeffs_;
00041   MarControlPtr ctrl_printstate_;
00042 
00043   MarControlPtr ctrl_calculate_binaural_sai_;
00044 
00045   MarControlPtr ctrl_sai_width_;
00046   MarControlPtr ctrl_sai_memory_factor_;
00047   MarControlPtr ctrl_sai_summary_itd_;
00048   MarControlPtr ctrl_sai_threshold_alpha_;
00049   MarControlPtr ctrl_sai_threshold_jump_factor_;
00050   MarControlPtr ctrl_sai_threshold_jump_offset_;
00051 
00052   MarControlPtr ctrl_sai_output_binaural_sai_;
00053   MarControlPtr ctrl_sai_output_threshold_;
00054   MarControlPtr ctrl_sai_output_strobes_;
00055 
00056   bool calculate_binaural_sai_;
00057   int sai_width_;
00058   double sai_memory_factor_;
00059   double sai_threshold_alpha_;
00060   double sai_threshold_jump_factor_;
00061   double sai_threshold_jump_offset_;
00062 
00063   void DoubleExponentialSmoothing(std::vector<double> &data, double polez1, double polez2, int n_ch);
00064   void CARFAC_AGCStep(const std::vector<std::vector<double> > &avg_detects);
00065 
00066 public:
00067   CARFAC(std::string name);
00068   CARFAC(const CARFAC& a);
00069   ~CARFAC();
00070   MarSystem* clone() const;
00071 
00072   realvec lastin;
00073 
00074   std::vector<std::vector<std::vector<double> > > naps;
00075   std::vector<std::vector<std::vector<double> > > prev_naps;
00076   std::vector<std::vector<std::vector<double> > > decim_naps;
00077   std::vector<std::vector<std::vector<double> > > sai;
00078 
00079   std::vector<double> agcstep_prev_stage_mean;
00080   std::vector<double> agcstep_stage_sum;
00081   std::vector<double> agcstep_AGC_in;
00082   std::vector<double> agcstep_AGC_stage;
00083 
00084   void allocateVectors();
00085 
00086   // TODO(snessnet) - should be private...
00087   CF_class CF;
00088 
00089   std::string toString();
00090   void printParams();
00091   void myProcess(realvec& in, realvec& out);
00092 };
00093 
00094 }//namespace Marsyas
00095 
00096 #endif