Marsyas
0.6.0-alpha
|
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 "Upsample.h" 00020 #include <iostream> 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 Upsample::Upsample(mrs_string name):MarSystem("Upsample",name) 00026 { 00027 addControls(); 00028 } 00029 00030 Upsample::~Upsample() 00031 { 00032 } 00033 00034 MarSystem* 00035 Upsample::clone() const 00036 { 00037 return new Upsample(*this); 00038 } 00039 00040 void 00041 Upsample::addControls() 00042 { 00043 addctrl("mrs_real/default", 0.0); 00044 addctrl("mrs_natural/factor", 2); 00045 addctrl("mrs_string/interpolation", "none"); 00046 getControl("mrs_natural/factor")->setState(true); 00047 } 00048 00049 00050 00051 void 00052 Upsample::myUpdate(MarControlPtr sender) 00053 { 00054 (void) sender; //suppress warning of unused parameter(s) 00055 mrs_natural factor = getctrl("mrs_natural/factor")->to<mrs_natural>(); 00056 mrs_natural onSamples = (mrs_natural)(mrs_real)(ctrl_inSamples_->to<mrs_natural>() * factor); 00057 ctrl_onSamples_->setValue(onSamples, NOUPDATE); 00058 ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>() / factor, NOUPDATE); 00059 } 00060 00061 void 00062 Upsample::myProcess(realvec& in, realvec& out) 00063 { 00064 //checkFlow(in,out); 00065 mrs_natural factor = getctrl("mrs_natural/factor")->to<mrs_natural>(); 00066 mrs_natural inSamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>(); 00067 mrs_string interpolation = getctrl("mrs_string/interpolation")->to<mrs_string>(); 00068 //updControl("mrs_natural/osRate", getctrl("mrs_natural/isRate")/factor); 00069 //if (getctrl("mrs_natural/onSamples")->to<mrs_natural>() !=(inSamples*factor)) { 00070 // updControl("mrs_natural/onSamples", inSamples*factor); 00071 //} 00072 00073 // Set default values 00074 if (getctrl("mrs_real/default")->to<mrs_real>() != 0.0) { 00075 for (mrs_natural t=0; t < inSamples*factor; t++) 00076 { 00077 out(0,t)=getctrl("mrs_real/default")->to<mrs_real>();; 00078 } 00079 } 00080 00081 // Get actual values 00082 for (mrs_natural t=0; t < inSamples; t++) 00083 { 00084 // no interpolation 00085 if (interpolation=="none") { 00086 out(0,t*factor) = in(0,t); 00087 } 00088 if (interpolation=="repeat") { 00089 for (mrs_natural k=(t*factor); k<((t+1)*factor); k++) { 00090 out(0,k)=in(0,t); 00091 } 00092 } 00093 } 00094 } 00095