00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "PWMSource.h"
00020
00021 using namespace std;
00022 using namespace Marsyas;
00023
00024 PWMSource::PWMSource(mrs_string name):MarSystem("PWMSource",name)
00025 {
00026
00027
00028
00029 addControls();
00030
00031
00032 }
00033
00034 PWMSource::~PWMSource()
00035 {
00036 }
00037
00038 MarSystem*
00039 PWMSource::clone() const
00040 {
00041 return new PWMSource(*this);
00042 }
00043
00044 void
00045 PWMSource::addControls()
00046 {
00047 addctrl("mrs_real/frequency", 440.0);
00048 addctrl("mrs_real/duty_cicle", 0.5);
00049 }
00050
00051 void
00052 PWMSource::myUpdate(MarControlPtr sender)
00053 {
00054
00055
00056
00057
00058 MarSystem::myUpdate(sender);
00059 }
00060
00061 void
00062 PWMSource::myProcess(realvec &in, realvec &out)
00063 {
00064 (void) in;
00065
00066 mrs_real frequency = (getctrl("mrs_real/frequency")->to<mrs_real>());
00067 mrs_real duty = getctrl("mrs_real/duty_cicle")->to<mrs_real>();
00068 mrs_real irate = (getctrl("mrs_real/israte")->to<mrs_real>());
00069 mrs_real incr = frequency / irate;
00070 mrs_natural inSamples = getctrl("mrs_natural/inSamples")->to<mrs_natural>();
00071
00072
00073
00074
00075
00076
00077
00078
00079 for (mrs_natural t=0; t < inSamples; t++)
00080 {
00081 out(0,t)=0;
00082 phase += incr;
00083 if (phase>duty) {
00084 out(0,t) = 0;
00085 } else {
00086 out(0,t) = 1;
00087 }
00088 if (phase>1) {
00089 phase=0;
00090 }
00091 }
00092 }
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106