// Copyright (C) 1999 Jean-Marc Valin #include "BufferedNode.h" #include "Buffer.h" #include "Vector.h" #include using namespace std; namespace FD { class Window; DECLARE_NODE(Window) /*Node * * @name Window * @category DSP:Base * @description Applies a window on a frame * * @input_name INPUT * @input_type Vector * @input_description Input frame * * @output_name OUTPUT * @output_type Vector * @output_description Windowed frame * * @parameter_name LENGTH * @parameter_type int * @parameter_description Length of the frames/window * * @parameter_name WINDOW * @parameter_type string * @parameter_description Window type (HANNING, HAMMING, HALF_HANNING) * * @parameter_name SYMETRIC * @parameter_type bool * @parameter_description Symetric window, uses (length-1) for normalization * END*/ class Window : public BufferedNode { int inputID; int outputID; int length; vector window; public: Window(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { inputID = addInput("INPUT"); outputID = addOutput("OUTPUT"); length = dereference_cast (parameters.get("LENGTH")); } virtual void initialize() { this->BufferedNode::initialize(); int i; window.resize(length); String type = object_cast (parameters.get("WINDOW")); int len = length; if (parameters.exist("SYMETRIC")) { if (dereference_cast (parameters.get("SYMETRIC"))) len--; } else { len--; } if (type == "HANNING") { for (i=0;i &in = object_cast > (inputValue); if (in.size() != length) { cerr << in.size() << " != " << length << endl; throw new NodeException(this, "Size of input != size of window", __FILE__, __LINE__); } Vector &output = *Vector::alloc(length); out[count] = &output; for (int i=0;i