Marsyas  0.5.0-beta1
/Users/jleben/code/marsyas/src/marsyas/marsystems/BeatHistogramFromPeaks.cpp
Go to the documentation of this file.
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 #include "BeatHistogramFromPeaks.h"
00020 #include "../common_source.h"
00021 
00022 using std::ostringstream;
00023 using namespace Marsyas;
00024 
00025 
00026 BeatHistogramFromPeaks::BeatHistogramFromPeaks(mrs_string name):MarSystem("BeatHistogramFromPeaks",name)
00027 {
00028   addControls();
00029 }
00030 
00031 
00032 BeatHistogramFromPeaks::~BeatHistogramFromPeaks()
00033 {
00034 }
00035 
00036 
00037 MarSystem*
00038 BeatHistogramFromPeaks::clone() const
00039 {
00040   return new BeatHistogramFromPeaks(*this);
00041 }
00042 
00043 void
00044 BeatHistogramFromPeaks::addControls()
00045 {
00046   addctrl("mrs_real/gain", 1.0);
00047   addctrl("mrs_bool/reset", false);
00048   setctrlState("mrs_bool/reset", true);
00049   addctrl("mrs_natural/startBin", 0);
00050   setctrlState("mrs_natural/startBin", true);
00051   addctrl("mrs_natural/endBin", 100);
00052   setctrlState("mrs_natural/endBin", true);
00053 }
00054 
00055 void
00056 BeatHistogramFromPeaks::myUpdate(MarControlPtr sender)
00057 {
00058   (void) sender;  //suppress warning of unused parameter(s)
00059   MRSDIAG("BeatHistogramFromPeaks.cpp - BeatHistogramFromPeaks:myUpdate");
00060 
00061   startBin_ = getctrl("mrs_natural/startBin")->to<mrs_natural>();
00062   endBin_ = getctrl("mrs_natural/endBin")->to<mrs_natural>();
00063   reset_ = getctrl("mrs_bool/reset")->to<mrs_bool>();
00064 
00065   setctrl("mrs_natural/onSamples", endBin_ - startBin_);
00066   setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations"));
00067   setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00068 }
00069 
00070 
00071 void
00072 BeatHistogramFromPeaks::myProcess(realvec& in, realvec& out)
00073 {
00074   mrs_natural t,o;
00075   if (reset_) {
00076     out.setval(0.0);
00077     reset_ = false;
00078     setctrl("mrs_bool/reset", false);
00079   }
00080 
00081   mrs_natural bin=0;
00082   mrs_real amp;
00083 
00084   for (o=0; o < inObservations_; o++)
00085     for (t = 0; t < inSamples_/2; t++)
00086     {
00087       bin = (mrs_natural)(in(o,2*t+1)+0.5);
00088       amp = in(o,2*t);
00089 
00090       if ((bin < endBin_ - startBin_)&&(bin > 1))
00091       {
00092         //      out(0,bin) += amp;
00093         out(0,bin) += (amp * (bin-startBin_));
00094         /* out(0,bin-1) += 0.5 * amp;
00095            out(0,bin-2) += 0.25 * amp;
00096            out(0,bin+1) += 0.5 * amp;
00097            out(0,bin-2) += 0.25 * amp;
00098         */
00099 
00100         /* out(0,bin) += 0.1 * out(0, bin-1);
00101            out(0,bin) += 0.1 * out(0, bin+1);
00102         */
00103 
00104       }
00105 
00106       /*
00107          index = (mrs_natural) 2 * bin;
00108          factor = 0.25;
00109          if ((index < endBin_ - startBin_)&&(index > 0))
00110          out(0,index) += factor * amp;
00111 
00112 
00113 
00114          index = (mrs_natural) (0.5 * bin + 0.5);
00115          factor = 0.25;
00116 
00117          if ((index < endBin_ - startBin_)&&(index > 0))
00118          out(0,index) += factor * amp;
00119 
00120          index = 3 * bin;
00121          factor = 0.15;
00122          if ((index < endBin_ - startBin_)&&(index > 0))
00123          out(0,index) += factor * amp;
00124 
00125 
00126          index = (mrs_natural) (0.33333 * bin + 0.5);
00127          factor = 0.15;
00128 
00129          if ((index < endBin_ - startBin_)&&(index > 0))
00130          out(0,index) += (factor * amp);
00131       */
00132 
00133     }
00134 
00135 }