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