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 "WaveletBands.h" 00020 #include "../common_source.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 WaveletBands::WaveletBands(mrs_string name):MarSystem("WaveletBands",name) 00026 { 00027 iwvpt_ = NULL; 00028 00029 addControls(); 00030 } 00031 00032 WaveletBands::~WaveletBands() 00033 { 00034 delete iwvpt_; 00035 } 00036 00037 00038 // copy constructor 00039 WaveletBands::WaveletBands(const WaveletBands& a):MarSystem(a) 00040 { 00041 iwvpt_ = NULL; 00042 } 00043 00044 00045 00046 MarSystem* 00047 WaveletBands::clone() const 00048 { 00049 return new WaveletBands(*this); 00050 } 00051 00052 void 00053 WaveletBands::addControls() 00054 { 00055 addctrl("mrs_natural/nBands", 6); 00056 setctrlState("mrs_natural/nBands", true); 00057 addctrl("mrs_natural/startBand", 2); 00058 setctrlState("mrs_natural/startBand", true); 00059 } 00060 00061 void 00062 WaveletBands::myUpdate(MarControlPtr sender) 00063 { 00064 (void) sender; //suppress warning of unused parameter(s) 00065 00066 MRSDIAG("WaveletBands.cpp - WaveletBands:myUpdate"); 00067 mrs_natural nBands = getctrl("mrs_natural/nBands")->to<mrs_natural>(); 00068 00069 setctrl("mrs_natural/onSamples", getctrl("mrs_natural/inSamples")); 00070 setctrl("mrs_natural/onObservations", getctrl("mrs_natural/inObservations")->to<mrs_natural>() * nBands); 00071 setctrl("mrs_real/osrate", getctrl("mrs_real/israte")); 00072 00073 00074 // Set up the inverse wavelet transform object. 00075 if (!iwvpt_) 00076 { 00077 // TODO: why is this done here and not in the contructors? Please explain. 00078 iwvpt_ = new WaveletPyramid("iwvpt"); 00079 } 00080 00081 iwvpt_->setctrl("mrs_bool/forward", false); 00082 iwvpt_->updControl("mrs_natural/inSamples", getctrl("mrs_natural/inSamples")); 00083 iwvpt_->updControl("mrs_natural/inObservations", getctrl("mrs_natural/inObservations")); 00084 iwvpt_->updControl("mrs_real/israte", getctrl("mrs_real/israte")); 00085 00086 // Allocate the band and tband realvecs. 00087 band_.create(getctrl("mrs_natural/inObservations")->to<mrs_natural>(), 00088 getctrl("mrs_natural/inSamples")->to<mrs_natural>()); 00089 tband_.create(getctrl("mrs_natural/inObservations")->to<mrs_natural>(), 00090 getctrl("mrs_natural/inSamples")->to<mrs_natural>()); 00091 00092 } 00093 00094 00095 void 00096 WaveletBands::myProcess(realvec& in, realvec& out) 00097 { 00098 mrs_natural o,t; 00099 mrs_natural level; 00100 mrs_natural hlevel, llevel; 00101 mrs_natural base = getctrl("mrs_natural/startBand")->to<mrs_natural>(); 00102 00103 for (o = 0; o < onObservations_; o++) 00104 { 00105 // Copy the input for one observation channel to band_. 00106 for (t=0; t < inSamples_; t++) 00107 { 00108 band_(t) = in(0, t); 00109 } 00110 00111 // Get the ranges to set to zero. 00112 level = 7+o; 00113 hlevel = base << level; 00114 llevel = base << (level -1); 00115 00116 // Set the desired parts of band_ to zero. 00117 band_.setval(hlevel, inSamples_, 0.0); 00118 band_.setval(0, llevel, 0.0); 00119 00120 // Do the inverse wavelet transform. 00121 iwvpt_->process(band_, tband_); 00122 00123 // Copy the calculations to the output. 00124 for (t=0; t < inSamples_; t++) 00125 { 00126 out(o,t) = tband_(t); 00127 } 00128 } 00129 00130 }