Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/AimSAI.h
Go to the documentation of this file.
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_AIMSAI_H
00020 #define MARSYAS_AIMSAI_H
00021 
00022 #include <marsyas/system/MarSystem.h>
00023 #include <marsyas/StrobeList.h>
00024 
00025 // sness - TODO - Eventually make these realvecs.  However, in the
00026 // existing code there is quite a bit of stuff that involves STL
00027 // methods, so I thought it would be safer to use STL for now.
00028 #include <vector>
00029 
00030 namespace Marsyas
00031 {
00047 class marsyas_EXPORT AimSAI: public MarSystem
00048 {
00049 private:
00050   void myUpdate(MarControlPtr sender);
00051 
00052   // Reset all internal state variables to their initial values
00053   void ResetInternal();
00054 
00055   // Prepare the module
00056   void InitializeInternal();
00057 
00058   // Does the MarSystem need initialization?
00059   bool is_initialized;
00060 
00061   // What changes cause it to need initialization?
00062   mrs_real initialized_israte;
00063   mrs_natural initialized_inobservations;
00064   mrs_natural initialized_insamples;
00065   mrs_real initialized_frame_period_ms;
00066   mrs_real initialized_min_delay_ms;
00067   mrs_real initialized_max_delay_ms;
00068   mrs_real initialized_buffer_memory_decay;
00069   mrs_natural initialized_max_concurrent_strobes;
00070   mrs_real initialized_strobe_weight_alpha;
00071 
00072   // Does the MarSystem need reset?
00073   bool is_reset;
00074 
00075   // What changes cause it to need a reset?
00076   mrs_real reseted_israte;
00077   mrs_natural reseted_inobservations;
00078   mrs_real reseted_frame_period_ms;
00079 
00080   // Does the MarSystem need to recalculate the centre frequencies
00081   bool is_centre_frequencies_calculated;
00082 
00083   // What causes it to need to recalculate the centre frequencies
00084   mrs_natural centre_frequencies_inobservations;
00085   mrs_natural centre_frequencies_max_frequency;
00086   mrs_natural centre_frequencies_min_frequency;
00087 
00088   //
00089   // MarControls
00090   //
00091   MarControlPtr ctrl_min_delay_ms_;
00092   MarControlPtr ctrl_max_delay_ms_;
00093   MarControlPtr ctrl_strobe_weight_alpha_;
00094 
00095   // Buffer decay parameter
00096   MarControlPtr ctrl_buffer_memory_decay_;
00097 
00098   // Period in milliseconds between output frames
00099   MarControlPtr ctrl_frame_period_ms_;
00100 
00101   // The maximum number strobes that can be active at the same time.
00102   MarControlPtr ctrl_max_concurrent_strobes_;
00103 
00104   // List of strobes for each channel
00105   std::vector<StrobeList> active_strobes_;
00106 
00107   // Sample index of minimum strobe delay
00108   int min_strobe_delay_idx_;
00109 
00110   // Sample index of maximum strobe delay
00111   int max_strobe_delay_idx_;
00112 
00113   // Factor with which the SAI should be decayed
00114   double sai_decay_factor_;
00115 
00116   // Precomputed 1/n^alpha values for strobe weighting
00117   std::vector<double> strobe_weights_;
00118 
00119   // Next Strobe for each channels
00120   std::vector<int> next_strobes_;
00121 
00122   // Temporary buffer for constructing the current SAI frame
00123   realvec sai_temp_;
00124 
00125   int fire_counter_;
00126   int frame_period_samples_;
00127   // int channel_count_;
00128 
00129   // The strobes for each observation
00130   std::vector<std::vector<int> > strobes_;
00131   void findStrobes(realvec& in);
00132 
00133   // // sness - From AimGammatone.  We need these in order to calculate
00134   // // the centre frequencies.
00135   // MarControlPtr ctrl_max_frequency_;
00136   // MarControlPtr ctrl_min_frequency_;
00137   std::vector<double> centre_frequencies_;
00138   // void CalculateCentreFrequencies();
00139 
00140   // The actual number of signal channels in the input.  The output
00141   // from PZFC + HCL + Localmax is a realvec with the first third of
00142   // observations being the signal, and the second third being the
00143   // channels and the last third being the strobes.
00144   mrs_natural channel_count_;
00145 
00146 
00147 public:
00148   AimSAI(std::string name);
00149 
00150   ~AimSAI();
00151   MarSystem* clone() const;
00152   void addControls();
00153 
00154   void myProcess(realvec& in, realvec& out);
00155 };
00156 
00157 }//namespace marsyas
00158 
00159 #endif