Marsyas
0.6.0-alpha
|
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 "OverlapAdd.h" 00020 #include <algorithm> 00021 00022 using std::ostringstream; 00023 using std::max; 00024 00025 using namespace Marsyas; 00026 00027 OverlapAdd::OverlapAdd(mrs_string name):MarSystem("OverlapAdd",name) 00028 { 00029 this->addControls (); 00030 } 00031 00032 OverlapAdd::~OverlapAdd() 00033 { 00034 } 00035 00036 void 00037 OverlapAdd::addControls() 00038 { 00039 addctrl("mrs_natural/ratioBlock2Hop", 2); 00040 } 00041 00042 MarSystem* 00043 OverlapAdd::clone() const 00044 { 00045 return new OverlapAdd(*this); 00046 } 00047 00048 void 00049 OverlapAdd::myUpdate(MarControlPtr sender) 00050 { 00051 (void) sender; //suppress warning of unused parameter(s) 00052 mrs_natural ratio = max((mrs_natural)1,getctrl("mrs_natural/ratioBlock2Hop")->to<mrs_natural>()); 00053 setctrl("mrs_natural/onSamples", ctrl_inSamples_->to<mrs_natural>()/ratio); 00054 setctrl("mrs_natural/onObservations", ctrl_inObservations_->to<mrs_natural>()); 00055 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")->to<mrs_real>()); 00056 00057 back_.stretch(ctrl_onObservations_->to<mrs_natural>(), ctrl_inSamples_->to<mrs_natural>()-ctrl_onSamples_->to<mrs_natural>()); 00058 } 00059 00060 void 00061 OverlapAdd::myProcess(realvec& in, realvec& out) 00062 { 00063 mrs_natural t,o; 00064 for(o=0 ; o<onObservations_; o++) 00065 { 00066 // compute output 00067 for(t=0; t<onSamples_; t++) 00068 out(o, t) = back_(o, t)+in(o, t); 00069 00070 // old code 00071 //for(t=0;t<onSamples_;t++) 00072 // back_(o, t) = in(o, t+onSamples_); 00073 00074 // shift internal buffer and add new samples 00075 for (t = onSamples_; t < inSamples_ - onSamples_; t++) 00076 back_(o,t-onSamples_) = back_(o,t) + in(o,t); 00077 00078 // copy the non-overlapping samples 00079 for (t = inSamples_-onSamples_; t < inSamples_; t++) 00080 back_(o,t-onSamples_) = in(o,t); 00081 } 00082 } 00083 00084 00085 00086 00087 00088 00089 00090 00091 00092 00093 00094 00095