Marsyas  0.6.0-alpha
/usr/src/RPM/BUILD/marsyas-0.6.0/src/marsyas/marsystems/Gain.cpp
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 #include "Gain.h"
00020 #include "../common_source.h"
00021 
00022 using namespace Marsyas;
00023 
00024 Gain::Gain(mrs_string name):MarSystem("Gain", name)
00025 {
00026   //Add any specific controls needed by Gain
00027   //(default controls all MarSystems should have
00028   //were already added by MarSystem::addControl(),
00029   //called by :MarSystem(name) constructor).
00030   //If no specific controls are needed by a MarSystem
00031   //there is no need to implement and call this addControl()
00032   //method (see for e.g. Rms.cpp)
00033   addControls();
00034 }
00035 
00036 Gain::Gain(const Gain& a) : MarSystem(a)
00037 {
00038   // For any MarControlPtr in a MarSystem
00039   // it is necessary to perform this getctrl
00040   // in the copy constructor in order for cloning to work
00041   ctrl_gain_ = getctrl("mrs_real/gain");
00042 }
00043 
00044 Gain::~Gain()
00045 {
00046 }
00047 
00048 MarSystem*
00049 Gain::clone() const
00050 {
00051   return new Gain(*this);
00052 }
00053 
00054 void
00055 Gain::addControls()
00056 {
00057   //Add specific controls needed by this MarSystem.
00058   addctrl("mrs_real/gain", 1.0, ctrl_gain_);
00059 }
00060 
00061 
00062 void
00063 Gain::myUpdate(MarControlPtr sender)
00064 {
00065   // no change to network flow
00066   MarSystem::myUpdate(sender);
00067 }
00068 
00069 void
00070 Gain::myProcess(realvec& in, realvec& out)
00071 {
00072   mrs_real gainValue = ctrl_gain_->to<mrs_real>();
00073   MRSDIAG(type_ << "/" << name_ << "/mrs_real/gain = " << gainValue);
00074 
00075   // It is important to loop over both observations
00076   // and channels so that for example a gain can be
00077   // applied to multi-channel signals
00078   for (mrs_natural o=0; o < inObservations_; o++)
00079   {
00080     for (mrs_natural t = 0; t < inSamples_; t++)
00081     {
00082       //apply gain to all channels
00083       out(o,t) = gainValue * in(o,t);
00084     }
00085   }
00086 }