00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Vibrato.h"
00021
00022 using namespace std;
00023 using namespace Marsyas;
00024
00025 Vibrato::Vibrato(mrs_string name):MarSystem("Vibrato",name)
00026 {
00027 addControls();
00028 }
00029
00030 Vibrato::~Vibrato()
00031 {
00032 }
00033
00034 MarSystem*
00035 Vibrato::clone() const
00036 {
00037 return new Vibrato(*this);
00038 }
00039
00040 void
00041 Vibrato::addControls()
00042 {
00043 addctrl("mrs_real/mod_freq", 5.0);
00044 addctrl("mrs_real/width", 0.005);
00045 setctrlState("mrs_real/mod_freq", true);
00046 setctrlState("mrs_real/width", true);
00047 }
00048
00049 void
00050 Vibrato::myUpdate(MarControlPtr sender)
00051 {
00052 MRSDIAG("Vibrato.cpp - Vibrato:localuUpdate");
00053
00054 MarSystem::myUpdate(sender);
00055
00056 mrs_real mod_freq;
00057 mod_freq = getctrl("mrs_real/mod_freq")->to<mrs_real>();
00058 width_ = getctrl("mrs_real/width")->to<mrs_real>();
00059
00060 delay_ = floor(width_ * israte_);
00061 width_ = floor(width_ * israte_);
00062 mod_freq = mod_freq / israte_;
00063
00064 mrs_natural L = mrs_natural(2 + delay_ + width_ * 2);
00065
00066
00067 if (delaylineSize_ == 0)
00068 {
00069 delaylineSize_ = L;
00070 delayline_.create((mrs_natural)delaylineSize_);
00071 wp_ = 0;
00072 rp_ = 0;
00073 rpp_ = 0;
00074 }
00075
00076 tmod_ = 0;
00077
00078 }
00079
00080
00081 void
00082 Vibrato::myProcess(realvec &in, realvec &out)
00083 {
00084 for (mrs_natural t = 0; t < inSamples_; t++)
00085 {
00086 mrs_real M = getctrl("mrs_real/mod_freq")->to<mrs_real>();
00087 M = M / israte_;
00088 mrs_real MOD = sin(M* 2 * PI * tmod_);
00089 tmod_ ++ ;
00090
00091 mrs_real Z = 1 + delay_ + width_ * MOD;
00092 mrs_natural i = (mrs_natural)floor(Z);
00093 mrs_real frac = Z - i;
00094
00095
00096 delayline_(wp_) = in(0,t);
00097
00098
00099 wp_ = (wp_+1) % delaylineSize_;
00100 rp_ = (wp_ + i + 1) % delaylineSize_;
00101 rpp_ = (wp_ + i) % delaylineSize_;
00102
00103
00104 out(0,t) = delayline_(rp_)* frac + delayline_(rpp_) * (1 -frac);
00105
00106 }
00107
00108 }
00109
00110
00111
00112
00113
00114
00115
00116