Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/ZeroCrossings.cpp
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 #include "ZeroCrossings.h"
00020 #include "../common_source.h"
00021 
00022 using namespace std;
00023 using namespace Marsyas;
00024 
00025 ZeroCrossings::ZeroCrossings(mrs_string name):MarSystem("ZeroCrossings",name)
00026 {
00027 }
00028 
00029 
00030 ZeroCrossings::~ZeroCrossings()
00031 {
00032 }
00033 
00034 
00035 MarSystem*
00036 ZeroCrossings::clone() const
00037 {
00038   return new ZeroCrossings(*this);
00039 }
00040 
00041 void
00042 ZeroCrossings::myUpdate(MarControlPtr sender)
00043 {
00044   (void) sender;  //suppress warning of unused parameter(s)
00045   MRSDIAG("ZeroCrossings.cpp - ZeroCrossings:myUpdate");
00046   ctrl_onSamples_->setValue((mrs_natural)1, NOUPDATE);
00047   ctrl_onObservations_->setValue(ctrl_inObservations_, NOUPDATE);
00048   ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>() / ctrl_inSamples_->to<mrs_natural>());
00049   ctrl_onObsNames_->setValue("ZeroCrossings_" + ctrl_inObsNames_->to<mrs_string>() , NOUPDATE);
00050 }
00051 
00052 
00053 
00054 
00055 void
00056 ZeroCrossings::myProcess(realvec& in, realvec& out)
00057 {
00058   mrs_natural o,t;
00059 
00060   for (o=0; o < inObservations_; o++)
00061   {
00062     zcrs_ = 1.0;
00063     for (t = 1; t < inSamples_; t++)
00064     {
00065       if (((in(o, t-1) > 0) && (in(o,t) < 0)) ||
00066           ((in(o, t-1) < 0) && (in(o,t) > 0)))
00067       {
00068         zcrs_++;
00069       }
00070     }
00071     out(o,0) = zcrs_ / inSamples_;
00072   }
00073 }
00074