00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Spectrum.h"
00021
00022 using namespace std;
00023 using namespace Marsyas;
00024
00025 Spectrum::Spectrum(mrs_string name):MarSystem("Spectrum",name)
00026 {
00027 ponObservations_ = 0;
00028
00029 cutoff_ = 1.0;
00030 lowcutoff_ = 0.0;
00031 re_ = 0.0;
00032 im_ = 0.0;
00033 addControls();
00034 }
00035
00036 Spectrum::~Spectrum()
00037 {
00038 }
00039
00040 Spectrum::Spectrum(const Spectrum& a): MarSystem(a)
00041 {
00042 ctrl_cutoff_ = getctrl("mrs_real/cutoff");
00043 ctrl_lowcutoff_ = getctrl("mrs_real/lowcutoff");
00044 }
00045
00046 void
00047 Spectrum::addControls()
00048 {
00049 addctrl("mrs_real/cutoff", 1.0, ctrl_cutoff_);
00050 setctrlState("mrs_real/cutoff", true);
00051 addctrl("mrs_real/lowcutoff", 0.0, ctrl_lowcutoff_);
00052 setctrlState("mrs_real/lowcutoff", true);
00053 }
00054
00055 MarSystem*
00056 Spectrum::clone() const
00057 {
00058 return new Spectrum(*this);
00059 }
00060
00061 void
00062 Spectrum::myUpdate(MarControlPtr sender)
00063 {
00064 (void) sender;
00065 ctrl_onSamples_->setValue((mrs_natural)1, NOUPDATE);
00066 ctrl_onObservations_->setValue(ctrl_inSamples_, NOUPDATE);
00067 ctrl_osrate_->setValue(ctrl_israte_->to<mrs_real>() / ctrl_inSamples_->to<mrs_natural>());
00068
00069 cutoff_ = ctrl_cutoff_->to<mrs_real>();
00070 lowcutoff_ = ctrl_lowcutoff_->to<mrs_real>();
00071
00072 onObservations_ = ctrl_onObservations_->to<mrs_natural>();
00073
00074 if (ponObservations_ != onObservations_)
00075 {
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086 }
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096 ostringstream oss;
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108 ctrl_onObsNames_->setValue("FFT" + oss.str() + "_" + ctrl_inObsNames_->to<mrs_string>(), NOUPDATE);
00109
00110
00111
00112
00113 ponObservations_ = onObservations_;
00114 }
00115
00116 void
00117 Spectrum::myProcess(realvec& in, realvec& out)
00118 {
00119
00120 mrs_natural t;
00121
00122
00123
00124 for (t=0; t < inSamples_; t++)
00125 {
00126 out(t,0) = in(0,t);
00127 }
00128
00129 mrs_real *tmp = out.getData();
00130 myfft_.rfft(tmp, inSamples_/2, FFT_FORWARD);
00131
00132 if (cutoff_ != 1.0)
00133 {
00134 for (t= (mrs_natural)((cutoff_ * inSamples_) / 2); t < inSamples_/2; t++)
00135 {
00136 out(2*t,0) = 0;
00137 out(2*t+1,0) = 0;
00138 }
00139 }
00140
00141 if (lowcutoff_ != 0.0)
00142 {
00143 for (t=0; t < (mrs_natural)((lowcutoff_ * inSamples_) /2); t++)
00144 {
00145 out(2*t,0) = 0;
00146 out(2*t+1,0) = 0;
00147 }
00148 }
00149
00150
00151
00152
00153
00154
00155 return;
00156 }