Marsyas
0.6.0-alpha
|
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 "../common_source.h" 00020 #include "ADRessStereoSpectrum.h" 00021 00022 00023 using std::ostringstream; 00024 using namespace Marsyas; 00025 00026 ADRessStereoSpectrum::ADRessStereoSpectrum(mrs_string name):MarSystem("ADRessStereoSpectrum", name) 00027 { 00028 addControls(); 00029 } 00030 00031 ADRessStereoSpectrum::ADRessStereoSpectrum(const ADRessStereoSpectrum& a) : MarSystem(a) 00032 { 00033 00034 } 00035 00036 ADRessStereoSpectrum::~ADRessStereoSpectrum() 00037 { 00038 } 00039 00040 MarSystem* 00041 ADRessStereoSpectrum::clone() const 00042 { 00043 return new ADRessStereoSpectrum(*this); 00044 } 00045 00046 void 00047 ADRessStereoSpectrum::addControls() 00048 { 00049 } 00050 00051 void 00052 ADRessStereoSpectrum::myUpdate(MarControlPtr sender) 00053 { 00054 MRSDIAG("ADRessStereoSpectrum.cpp - ADRessStereoSpectrum:myUpdate"); 00055 00056 (void) sender; //suppress warning of unused parameter(s) 00057 00058 N2_ = ctrl_inObservations_->to<mrs_natural>()/2; //i.e. N/2+1 00059 00060 ctrl_onSamples_->setValue(1, NOUPDATE); 00061 ctrl_onObservations_->setValue(N2_, NOUPDATE); 00062 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00063 00064 ostringstream oss; 00065 for (mrs_natural n=0; n < N2_; n++) 00066 oss << "ADRess_stereobin_" << n << ","; 00067 ctrl_onObsNames_->setValue(oss.str(), NOUPDATE); 00068 00069 beta_ = ctrl_inSamples_->to<mrs_natural>()-2; 00070 } 00071 00072 void 00073 ADRessStereoSpectrum::myProcess(realvec& in, realvec& out) 00074 { 00075 mrs_natural o,t; 00076 for(o=0; o < N2_; ++o) 00077 { 00078 //look for the maximum in the azimuth plane 00079 //NOTE: first column of input is dedicated to bin phases... 00080 maxVal_ = 0.0; 00081 maxIndex_ = beta_; 00082 for(t=0; t<=beta_; ++t) 00083 { 00084 if(in(o,t+1) > maxVal_)//AZl 00085 { 00086 maxVal_ = in(o,t+1); 00087 maxIndex_ = t; 00088 } 00089 if(in(N2_+o, t+1) > maxVal_)//AZr 00090 { 00091 maxVal_ = in(N2_+o,t+1); 00092 maxIndex_ = beta_*2+1-t; 00093 } 00094 } 00095 00096 //avoid two indexes for center panning 00097 if(maxIndex_ > beta_) 00098 maxIndex_--; 00099 00100 //convert panning index to range [-1,1] 00101 //and save it to corresponding output 00102 out(o,0) = (mrs_real)maxIndex_/(beta_*2.0)*2.0 - 1.0; 00103 } 00104 00105 // MATLAB_PUT(out, "ADRessBinPan"); 00106 // MATLAB_EVAL("figure(3);plot(ADRessBinPan);"); 00107 }