#include "block.h" #include #include #include #include "wavinput.h" class WavIn : public Block { private: OutPort < double > * out; Parameter < string > * filenamePar; Wavinput wavinput; public: WavIn(const Blockopt & blockopt) : Block(blockopt) {} void makeParameters() { filenamePar = new Parameter < string > (this, "filename", "/File/wavout.wav"); } time_t getMaxMtime() { if (filenamePar->value().size() > 0) { struct stat statb; if (0 == stat(locatefile(filenamePar->value()).c_str(), &statb)) return statb.st_mtime; else simerror("error stating " + locatefile(filenamePar->value())); } return 0; } void initialize() { if (filenamePar->value().size() > 0) { if (!wavinput.open(locatefile(filenamePar->value()).c_str())) simerror("error opening " + locatefile(filenamePar->value())); } } void makeIOPorts() { out = new OutPort < double > (this, "out", 1); } void go() { out->write(wavinput.getsample()); if (wavinput.eof()) simend("end of file reached"); } void finalize() { wavinput.close(); } }; PUBLISH(WavIn);