00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "SFM.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 SFM::SFM(mrs_string name):MarSystem("SFM",name)
00025 {
00026 }
00027
00028 SFM::~SFM()
00029 {
00030 }
00031
00032 MarSystem*
00033 SFM::clone() const
00034 {
00035 return new SFM(*this);
00036 }
00037
00038 void
00039 SFM::myUpdate(MarControlPtr sender)
00040 {
00041 (void) sender;
00042 MRSDIAG("SFM.cpp - SFM:myUpdate");
00043
00044
00045
00046
00047
00048
00049
00050
00051 mrs_natural i;
00052
00053
00054 nrBands_ = 24;
00055
00056
00057 nrValidBands_ = nrBands_;
00058
00059 setctrl("mrs_natural/onSamples", (mrs_natural)1);
00060 setctrl("mrs_natural/onObservations", (mrs_natural)nrBands_);
00061 setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00062
00063
00064 ostringstream oss;
00065 for (i = 0; i < nrBands_; ++i)
00066 oss << "SFM_" << i+1 << ",";
00067 setctrl("mrs_string/onObsNames", oss.str());
00068
00069 edge_.create(nrBands_ + 1);
00070 bandLoEdge_.create(nrBands_);
00071 bandHiEdge_.create(nrBands_);
00072
00073
00074 for(i = 0 ; i < nrBands_ + 1 ; ++i)
00075 {
00076 edge_(i)= 1000.0f * pow((mrs_real)2.0f, (mrs_real)(0.25f * (i - 8)));
00077 }
00078
00079 for (i = 0; i < nrBands_; ++i)
00080 {
00081 bandLoEdge_(i) = edge_(i) * 0.95f;
00082 bandHiEdge_(i) = edge_(i+1) * 1.05f;
00083 }
00084
00085 spectrumSize_ = ctrl_inObservations_->to<mrs_natural>();
00086
00087
00088
00089 df_ = ctrl_israte_->to<mrs_real>();
00090
00091
00092
00093
00094
00095
00096 il_.resize(nrBands_);
00097 ih_.resize(nrBands_);
00098 for(i = 0; i < nrBands_; ++i)
00099 {
00100
00101 il_[i] = (mrs_natural)(bandLoEdge_(i)/df_ + 0.5f);
00102 ih_[i] = (mrs_natural)(bandHiEdge_(i)/df_ + 0.5f);
00103
00104
00105
00106
00107 if(ih_[i] >= spectrumSize_)
00108 {
00109 nrValidBands_ = i;
00110 il_.resize(nrValidBands_);
00111 ih_.resize(nrValidBands_);
00112 break;
00113 }
00114 }
00115 }
00116
00117 void
00118 SFM::myProcess(realvec& in, realvec& out)
00119 {
00120 mrs_natural i, k, bandwidth;
00121 mrs_real c;
00122 mrs_real aritMean;
00123 mrs_real geoMean;
00124
00125
00126 out.setval(1.0);
00127
00128
00129
00130
00131 for(i = 0; i < nrValidBands_; ++i)
00132 {
00133 geoMean = 1.0;
00134 aritMean = 0.0;
00135 bandwidth = ih_[i] - il_[i] + 1;
00136 for(k = il_[i]; k <= ih_[i]; k++)
00137 {
00138 c = in(k);
00139 aritMean += c / bandwidth;
00140 geoMean *= pow((mrs_real)c, (mrs_real)1.0/bandwidth);
00141 }
00142 if (aritMean != 0.0)
00143 {
00144 out(i) = geoMean/aritMean;
00145 }
00146
00147
00148 }
00149
00150
00151
00152
00153
00154 }