00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "SCF.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 SCF::SCF(mrs_string name):MarSystem("SCF",name)
00025 {
00026 }
00027
00028 SCF::~SCF()
00029 {
00030 }
00031
00032 MarSystem*
00033 SCF::clone() const
00034 {
00035 return new SCF(*this);
00036 }
00037
00038 void
00039 SCF::myUpdate(MarControlPtr sender)
00040 {
00041 (void) sender;
00042 MRSDIAG("SCF.cpp - SCF: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(ctrl_onSamples_, 1);
00060 setctrl(ctrl_onObservations_, nrBands_);
00061 setctrl(ctrl_osrate_, ctrl_israte_);
00062
00063
00064 ostringstream oss;
00065 for (i = 0; i < nrBands_; ++i)
00066 oss << "SCF_" << i+1 << ",";
00067 setctrl(ctrl_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
00077 edge_(i)= 1000.0f * pow(2.0f, (0.25f * (i - 8)));
00078 }
00079
00080 for (i = 0; i < nrBands_; ++i)
00081 {
00082 bandLoEdge_(i) = edge_(i) * 0.95f;
00083 bandHiEdge_(i) = edge_(i+1) * 1.05f;
00084 }
00085
00086 spectrumSize_ = ctrl_inObservations_->to<mrs_natural>();
00087
00088
00089
00090 df_ = ctrl_israte_->to<mrs_real>();
00091
00092
00093
00094
00095
00096
00097 il_.resize(nrBands_);
00098 ih_.resize(nrBands_);
00099 for(i = 0; i < nrBands_; ++i)
00100 {
00101
00102 il_[i] = (mrs_natural)(bandLoEdge_(i)/df_ + 0.5f);
00103 ih_[i] = (mrs_natural)(bandHiEdge_(i)/df_ + 0.5f);
00104
00105
00106
00107
00108 if(ih_[i] >= spectrumSize_)
00109 {
00110 nrValidBands_ = i;
00111 il_.resize(nrValidBands_);
00112 ih_.resize(nrValidBands_);
00113 break;
00114 }
00115 }
00116 }
00117
00118 void
00119 SCF::myProcess(realvec& in, realvec& out)
00120 {
00121 mrs_natural i, k, bandwidth;
00122 double c, maxc;
00123 double aritMean ;
00124
00125
00126 out.setval(1.0);
00127
00128
00129
00130
00131 for(i = 0; i < nrValidBands_; ++i)
00132 {
00133 aritMean = 0.0;
00134 maxc = 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 if(c > maxc)
00141 maxc = c;
00142 }
00143 if (aritMean != 0.0)
00144 {
00145 out(i) = (float)(maxc/aritMean);
00146 }
00147
00148
00149 }
00150
00151
00152
00153
00154
00155 }