#include "block.h" #include using std::complex; class ComplexGen : public Block { private: OutPort < complex < double > > * out; Parameter < double > * omegaPar; Parameter < double > * phi0Par; double omega; double phi; public: ComplexGen(const Blockopt & blockopt) : Block(blockopt) {} void makeParameters() { omegaPar = new Parameter < double > (this, "omega", 2.*M_PI*1000./44100.); phi0Par = new Parameter < double > (this, "phi0", 0); } void makeIOPorts() { out = new OutPort < complex < double > > (this, "out", 1); } void initialize() { omega = omegaPar->value(); phi = phi0Par->value(); } void go() { out->write(complex < double > (cos(phi), sin(phi))); phi += omega; while (phi >= 2.*M_PI) phi -= 2. * M_PI; } }; PUBLISH(ComplexGen);