00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Envelope.h"
00021
00022
00023 using namespace Marsyas;
00024 using std::ostringstream;
00025
00026
00027 Envelope::Envelope(mrs_string name):MarSystem("Envelope", name)
00028 {
00029 addControls();
00030 }
00031
00032
00033 Envelope::~Envelope()
00034 {
00035 }
00036
00037
00038 MarSystem*
00039 Envelope::clone() const
00040 {
00041 return new Envelope(*this);
00042 }
00043
00044 void
00045 Envelope::addControls()
00046 {
00047 addctrl("mrs_real/target", 0.0);
00048
00049 addctrl("mrs_real/time",0.2);
00050 addctrl("natural/state",0);
00051 addctrl("mrs_real/nton", 0.0);
00052 addctrl("mrs_real/ntoff", 0.0);
00053 setctrlState("mrs_real/target", true);
00054
00055 setctrlState("mrs_real/time", true);
00056 setctrlState("mrs_real/nton", true);
00057 setctrlState("mrs_real/ntoff", true);
00058 }
00059
00060
00061 void
00062 Envelope::update()
00063 {
00064 MRSDIAG("Envelope.cpp - Envelope:update");
00065 setctrl("natural/onSamples", getctrl("natural/inSamples"));
00066 setctrl("natural/onObservations", getctrl("natural/inObservations"));
00067 setctrl("mrs_real/osrate", getctrl("mrs_real/israte"));
00068 setctrl("string/onObsNames", getctrl("string/inObsNames"));
00069
00070 sampleRate_= getctrl("mrs_real/israte")->to<mrs_real>();
00071 target_ = getctrl("mrs_real/target")->to<mrs_real>();
00072
00073 time_ = getctrl("mrs_real/time")->to<mrs_real>();
00074
00075 rate_ = 1.0 / (time_ * sampleRate_);
00076
00077
00078 noteon_ = getctrl("mrs_real/nton")->to<mrs_real>();
00079 noteoff_ = getctrl("mrs_real/ntoff")->to<mrs_real>();
00080
00081 if(noteon_){
00082 value_=0.0;
00083 this->updControl("mrs_real/nton",0.0);
00084 this->updControl("mrs_real/target",1.0);
00085 state_ = 1;
00086 }
00087
00088 if(noteoff_){
00089
00090 this->updControl("mrs_real/ntoff",0.0);
00091 this->updControl("mrs_real/target",0.0);
00092 state_ = 1;
00093 }
00094
00095 }
00096
00097
00098 void
00099 Envelope::myProcess(realvec& in, realvec& out)
00100 {
00101 mrs_natural o,t;
00102
00103
00104 for (o=0; o < inObservations_; o++)
00105 for (t = 0; t < inSamples_; t++)
00106 {
00107
00108 if (state_==1) {
00109 if (target_ > value_) {
00110 value_ =value_+ rate_;
00111 if (value_ >= target_) {
00112 value_ = target_;
00113 state_ = 0;
00114 }
00115 }
00116 else {
00117
00118 value_ = value_-rate_;
00119 if (value_ <= target_) {
00120 value_ = target_;
00121 state_ = 0;
00122 }
00123 }
00124 }
00125
00126 out(o,t) = value_* in(o,t);
00127
00128 }
00129
00130
00131
00132
00133
00134 }