00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "StereoSpectrumFeatures.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 StereoSpectrumFeatures::StereoSpectrumFeatures(mrs_string name):MarSystem("StereoSpectrumFeatures", name)
00025 {
00026 m0_ = 0.0;
00027 m1_ = 0.0;
00028 }
00029
00030 StereoSpectrumFeatures::~StereoSpectrumFeatures()
00031 {
00032 }
00033
00034 MarSystem*
00035 StereoSpectrumFeatures::clone() const
00036 {
00037 return new StereoSpectrumFeatures(*this);
00038 }
00039
00040 void
00041 StereoSpectrumFeatures::myUpdate(MarControlPtr sender)
00042 {
00043 (void) sender;
00044
00045 MRSDIAG("StereoSpectrumFeatures.cpp - StereoSpectrumFeatures:myUpdate");
00046 ctrl_onSamples_->setValue(ctrl_inSamples_, NOUPDATE);
00047
00048
00049 ctrl_onObservations_->setValue((mrs_natural)4, NOUPDATE);
00050 ctrl_osrate_->setValue(ctrl_israte_, NOUPDATE);
00051
00052 ostringstream oss;
00053 oss << "StereoSpectrumFeatures_Ptotal,";
00054 oss << "StereoSpectrumFeatures_Plow,";
00055 oss << "StereoSpectrumFeatures_Pmedium,";
00056 oss << "StereoSpectrumFeatures_Phigh,";
00057 ctrl_onObsNames_->setValue(oss.str(), NOUPDATE);
00058
00059 audioBW_ = ctrl_israte_->to<mrs_real>() * ctrl_inObservations_->to<mrs_natural>();
00060
00061
00062
00063
00064
00065 low_ = (mrs_natural)(250.0 / ctrl_israte_->to<mrs_real>());
00066 high_ = (mrs_natural)(2800.0 / ctrl_israte_->to<mrs_real>());
00067 }
00068
00069 void
00070 StereoSpectrumFeatures::myProcess(realvec& in, realvec& out)
00071 {
00072 mrs_natural t,o;
00073 for (t = 0; t < inSamples_; t++)
00074 {
00075 m0_ = 0.0;
00076 for (o=0; o < inObservations_; o++)
00077 {
00078 m0_ += (in(o,t) * in(o,t));
00079 }
00080 if (m0_ != 0.0)
00081 out(0,t) = sqrt(m0_ / inObservations_);
00082 else
00083 out(0,t) = 0.0;
00084 }
00085
00086
00087 for (t = 0; t < inSamples_; t++)
00088 {
00089 m0_ = 0.0;
00090 for (o=0; o < low_; o++)
00091 {
00092 m0_ += (in(o,t) * in(o,t));
00093 }
00094 if (m0_ != 0.0)
00095 out(1,t) = sqrt(m0_ / low_);
00096 else
00097 out(1,t) = 0.0;
00098 }
00099
00100
00101 for (t = 0; t < inSamples_; t++)
00102 {
00103 m0_ = 0.0;
00104 for (o=low_; o < high_; o++)
00105 {
00106 m0_ += (in(o,t) * in(o,t));
00107 }
00108 if (m0_ != 0.0)
00109 out(2,t) = sqrt(m0_ / (high_-low_));
00110 else
00111 out(2,t) = 0.0;
00112 }
00113
00114 for (t = 0; t < inSamples_; t++)
00115 {
00116 m0_ = 0.0;
00117 for (o=high_; o < inObservations_; o++)
00118 {
00119 m0_ += (in(o,t) * in(o,t));
00120 }
00121 if (m0_ != 0.0)
00122 out(3,t) = sqrt(m0_ / (inObservations_-high_));
00123 else
00124 out(3,t) = 0.0;
00125 }
00126
00127 }