00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PvFold.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 PvFold::PvFold(mrs_string name):MarSystem("PvFold",name)
00025 {
00026
00027
00028
00029 N_ = 0;
00030 Nw_ = 0;
00031 PNw_ = 0;
00032 PN_ = 0;
00033
00034 addControls();
00035 }
00036
00037 PvFold::PvFold(const PvFold& a):MarSystem(a)
00038 {
00039 N_ = 0;
00040 Nw_ = 0;
00041 PNw_ = 0;
00042 PN_ = 0;
00043 ctrl_rmsIn_ = getctrl("mrs_real/rmsIn");
00044 }
00045
00046
00047
00048 PvFold::~PvFold()
00049 {
00050 }
00051
00052 MarSystem*
00053 PvFold::clone() const
00054 {
00055 return new PvFold(*this);
00056 }
00057
00058
00059 void
00060 PvFold::addControls()
00061 {
00062 addctrl("mrs_natural/FFTSize", MRS_DEFAULT_SLICE_NSAMPLES);
00063 setctrlState("mrs_natural/FFTSize", true);
00064 addctrl("mrs_real/rmsIn", 0.0, ctrl_rmsIn_);
00065 n_ = 0;
00066 }
00067
00068
00069
00070 void
00071 PvFold::myUpdate(MarControlPtr sender)
00072 {
00073
00074 mrs_natural t;
00075 setctrl("mrs_natural/onSamples", getctrl("mrs_natural/FFTSize"));
00076 setctrl("mrs_natural/onObservations", (mrs_natural)1);
00077 setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00078
00079 N_ = getctrl("mrs_natural/onSamples")->to<mrs_natural>();
00080
00081 Nw_ = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00082
00083
00084 if ((Nw_ != PNw_)||(N_ != PN_))
00085 {
00086 n_ = -Nw_;
00087 awin_.stretch(Nw_);
00088
00089
00090
00091 for (t=0; t < Nw_; t++)
00092 {
00093 awin_(t) = (mrs_real)(0.5 * (1 - cos(TWOPI * t/(Nw_-1))));
00094 }
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114 mrs_real sum = 0.0;
00115 for (t =0; t < Nw_; t++)
00116 {
00117 sum += awin_(t);
00118 }
00119
00120 mrs_real afac = (mrs_real)(2.0/ sum);
00121
00122 awin_ *= afac;
00123 }
00124
00125
00126
00127
00128
00129
00130 PNw_ = Nw_;
00131 PN_ = N_;
00132
00133 }
00134
00135 void
00136 PvFold::myProcess(realvec& in, realvec& out)
00137 {
00138
00139 mrs_natural t;
00140
00141 for (t=0; t < Nw_; t++)
00142 {
00143 out(0,t) = in(0,t)*awin_(t);
00144
00145 }
00146
00147
00148
00149
00150
00151
00152 int half_Nw_ = Nw_/2;
00153 mrs_real tmp;
00154 for (t=0; t < half_Nw_; t++)
00155 {
00156 tmp = out(0,t);
00157 out(0,t) = out(0, t+half_Nw_);
00158 out(0,t+half_Nw_) = tmp;
00159 }
00160
00161
00162
00163 }
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174