Marsyas
0.6.0-alpha
|
00001 /* 00002 ** Copyright (C) 1998-2007 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 "StereoSpectrumFeatures.h" 00020 #include "../common_source.h" 00021 00022 using namespace std; 00023 using namespace Marsyas; 00024 00025 StereoSpectrumFeatures::StereoSpectrumFeatures(mrs_string name):MarSystem("StereoSpectrumFeatures", name) 00026 { 00027 m0_ = 0.0; 00028 m1_ = 0.0; 00029 } 00030 00031 StereoSpectrumFeatures::~StereoSpectrumFeatures() 00032 { 00033 } 00034 00035 MarSystem* 00036 StereoSpectrumFeatures::clone() const 00037 { 00038 return new StereoSpectrumFeatures(*this); 00039 } 00040 00041 void 00042 StereoSpectrumFeatures::myUpdate(MarControlPtr sender) 00043 { 00044 (void) sender; //suppress warning of unused parameter(s) 00045 00046 MRSDIAG("StereoSpectrumFeatures.cpp - StereoSpectrumFeatures:myUpdate"); 00047 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE); 00048 00049 // CHANGE THIS TO THE RIGHT NUMBER OF FEATURES 00050 ctrl_onObservations_->setValue((mrs_natural)4, NOUPDATE); 00051 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE); 00052 00053 ostringstream oss; 00054 oss << "StereoSpectrumFeatures_Ptotal,"; 00055 oss << "StereoSpectrumFeatures_Plow,"; 00056 oss << "StereoSpectrumFeatures_Pmedium,"; 00057 oss << "StereoSpectrumFeatures_Phigh,"; 00058 ctrl_onObsNames_->setValue(oss.str(), NOUPDATE); 00059 00060 audioBW_ = ctrl_israte_->to<mrs_real>() * ctrl_inObservations_->to<mrs_natural>(); 00061 00062 // FIXME These variables are defined but unused. 00063 // mrs_real lowBounday = 250.0; // Hz 00064 // mrs_real highBounday = 2800.0; // Hz 00065 00066 low_ = (mrs_natural)(250.0 / ctrl_israte_->to<mrs_real>()); 00067 high_ = (mrs_natural)(2800.0 / ctrl_israte_->to<mrs_real>()); 00068 } 00069 00070 void 00071 StereoSpectrumFeatures::myProcess(realvec& in, realvec& out) 00072 { 00073 mrs_natural t,o; 00074 for (t = 0; t < inSamples_; t++) 00075 { 00076 m0_ = 0.0; 00077 for (o=0; o < inObservations_; o++) 00078 { 00079 m0_ += (in(o,t) * in(o,t)); 00080 } 00081 if (m0_ != 0.0) 00082 out(0,t) = sqrt(m0_ / inObservations_); 00083 else 00084 out(0,t) = 0.0; 00085 } 00086 00087 // low band panning RMS 0Hz-250Hz 00088 for (t = 0; t < inSamples_; t++) 00089 { 00090 m0_ = 0.0; 00091 for (o=0; o < low_; o++) 00092 { 00093 m0_ += (in(o,t) * in(o,t)); 00094 } 00095 if (m0_ != 0.0) 00096 out(1,t) = sqrt(m0_ / low_); 00097 else 00098 out(1,t) = 0.0; 00099 } 00100 00101 // middle band panning RMS 250Hz-2800Hz 00102 for (t = 0; t < inSamples_; t++) 00103 { 00104 m0_ = 0.0; 00105 for (o=low_; o < high_; o++) 00106 { 00107 m0_ += (in(o,t) * in(o,t)); 00108 } 00109 if (m0_ != 0.0) 00110 out(2,t) = sqrt(m0_ / (high_-low_)); 00111 else 00112 out(2,t) = 0.0; 00113 } 00114 00115 for (t = 0; t < inSamples_; t++) 00116 { 00117 m0_ = 0.0; 00118 for (o=high_; o < inObservations_; o++) 00119 { 00120 m0_ += (in(o,t) * in(o,t)); 00121 } 00122 if (m0_ != 0.0) 00123 out(3,t) = sqrt(m0_ / (inObservations_-high_)); 00124 else 00125 out(3,t) = 0.0; 00126 } 00127 00128 }