00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "Plucked.h"
00020
00021 using std::ostringstream;
00022 using namespace Marsyas;
00023
00024 Plucked::Plucked(mrs_string name):MarSystem("Plucked",name)
00025 {
00026 pointer1_ = 0;
00027 pointer2_ = 0;
00028 pointer3_ = 0;
00029 a_ = 0;
00030 b_ = 0;
00031 noteon_ = 0.0;
00032 delaylineSize_ = 0;
00033 gain_ = NULL;
00034
00035 addControls();
00036 }
00037
00038 Plucked::~Plucked()
00039 {
00040 delete gain_;
00041 }
00042
00043 MarSystem*
00044 Plucked::clone() const
00045 {
00046 return new Plucked(*this);
00047 }
00048
00049 void
00050 Plucked::addControls()
00051 {
00052 addctrl("mrs_real/frequency", 100.0);
00053 addctrl("mrs_real/pluckpos", 0.5);
00054 addctrl("mrs_real/nton", 0.5);
00055 addctrl("mrs_real/loss",1.0);
00056 addctrl("mrs_real/stretch",0.2);
00057 setctrlState("mrs_real/frequency", true);
00058 setctrlState("mrs_real/nton", true);
00059 setctrlState("mrs_real/loss", true);
00060 }
00061
00062 void
00063 Plucked::myUpdate(MarControlPtr sender)
00064 {
00065 mrs_natural t;
00066 MRSDIAG("Plucked.cpp - Plucked:localuUpdate");
00067
00068 MarSystem::myUpdate(sender);
00069
00070 gain_ = new Gain("pluckedGain");
00071 gain_->updControl("mrs_natural/inSamples", getctrl("mrs_natural/inSamples"));
00072 gain_->updControl("mrs_natural/inSamples", getctrl("mrs_natural/inSamples"));
00073 gain_->updControl("mrs_real/israte", getctrl("mrs_real/israte"));
00074 gain_->updControl("mrs_real/gain", 2.0);
00075
00076 gout_.create(gain_->getctrl("mrs_natural/inObservations")->to<mrs_natural>(),
00077 gain_->getctrl("mrs_natural/inSamples")->to<mrs_natural>());
00078
00079 mrs_real freq = getctrl("mrs_real/frequency")->to<mrs_real>();
00080 mrs_real pos = getctrl("mrs_real/pluckpos")->to<mrs_real>();
00081 noteon_ = getctrl("mrs_real/nton")->to<mrs_real>();
00082
00083 loss_ = getctrl("mrs_real/loss")->to<mrs_real>();
00084
00085 s_ = getctrl("mrs_real/stretch")->to<mrs_real>();
00086
00087
00088
00089
00090 if (delaylineSize_ == 0)
00091 {
00092 delaylineSize_ = 2048;
00093 noise_.create((mrs_natural)delaylineSize_);
00094 delayline1_.create((mrs_natural)delaylineSize_);
00095 pickDelayLine_.create((mrs_natural)delaylineSize_);
00096
00097 for (t = 0; t < delaylineSize_; t++)
00098 {
00099 noise_(t) = (mrs_real)(rand() / (RAND_MAX + 1.0) -0.5);
00100 }
00101 }
00102
00103 if (noteon_ > 0)
00104 {
00105 a_ = 0;
00106 d_ = 2*22050/freq;
00107 N_ = (mrs_natural)floor(d_);
00108 g_=-(-1+d_)/(-d_-1);
00109 picklength_= (mrs_natural)floor(N_*pos);
00110
00111 for (t = 0; t < N_; t++)
00112 {
00113 pickDelayLine_(0)=noise_(t);
00114 delayline1_(t) = noise_(t)+ (mrs_real)0.1 * pickDelayLine_(picklength_-1);
00115
00116
00117
00118 for(p=0; p<=picklength_-2; p++)
00119 pickDelayLine_(picklength_-1-p) = pickDelayLine_(picklength_-1-p-1);
00120 }
00121 wp_ = 1;
00122 wpp_ = 0;
00123 rp_ = N_-1;
00124 }
00125 }
00126
00127
00128 void
00129 Plucked::myProcess(realvec &in, realvec &out)
00130 {
00131 (void)in;
00132
00133 if (noteon_ > 0)
00134 {
00135 for (mrs_natural t = 0; t < inSamples_; t++)
00136 {
00137
00138
00139 a_ = delayline1_(wp_);
00140 b_ = delayline1_(wpp_);
00141
00142
00143 delayline1_(rp_) =loss_*((1-s_)*a_ + s_* b_);
00144
00145 rp_ = (rp_ + +1) %N_;
00146 wp_ = (wp_ + 1) %N_;
00147 wpp_ = (wpp_ + 1) %N_;
00148 gout_(0,t) = a_;
00149
00150 }
00151 }
00152
00153 gain_->process(gout_, out);
00154 }
00155
00156
00157
00158
00159
00160
00161
00162