// file: $isip/class/algo/Window/Window.h // version: $Id: Window.h 8165 2002-05-31 21:57:33Z picone $ // // make sure definitions are only made once // #ifndef ISIP_WINDOW #define ISIP_WINDOW // isip include files // #ifndef ISIP_ALGORITHM_BASE #include #endif // Window: a class used to design various types of windows such as: // rectangular, hamming, hanning, blackman, and bartlett. the windows // implemented here represent the most common windows found in the // signal processing literature. the user can select different types // of windows and apply them to a vector of data. alternatively, they // can define their own window in custom mode and apply that window on // input data. // class Window : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define algorithm choices: // rectangular is chosen as the default for obvious reasons. the remaining // windows are listed in alphabetical order. custom is listed last // because it is a special case. // enum ALGORITHM { RECTANGULAR = 0, BLACKMAN, BARTLETT, DOLPH_CHEBYSHEV, GAUSSIAN, HAMMING, HANNING, KAISER, LIFTER, CUSTOM, DEF_ALGORITHM = RECTANGULAR }; // define implementation choices: // multiplication is the only implementation for window since it // multiplies the two vectors. // enum IMPLEMENTATION { MULTIPLICATION = 0, DEF_IMPLEMENTATION = MULTIPLICATION }; // define alignment choices: // center means that the center of the window is aligned with // the center of the frame. left means that the first sample in // the window corresponds to the first sample in the current frame // (and the remainder of the window extends into the future). right // means that the last sample in the window corresponds to the last // sample in the frame (and the remainder of the window extends // into the past. // enum ALIGNMENT { CENTER = 0, LEFT, RIGHT, DEF_ALIGNMENT = CENTER }; // define normalization choices: // unit_energy means that the energy of the window function is always // normalized to be unity. // enum NORMALIZATION { NONE = 0, UNIT_ENERGY, DEF_NORMALIZATION = NONE }; // define static NameMap objects for the enumerated values // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; static const NameMap ALGN_MAP; static const NameMap NORM_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_ALIGNMENT; static const String PARAM_NORMALIZATION; static const String PARAM_DURATION; static const String PARAM_CONSTANTS; static const String PARAM_DATA; static const String PARAM_CMODE; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define the default value(s) of the class data // static const float32 DEF_DURATION = 0.025; // define default argument(s) // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::SIGNAL; // default constants for each window algorithm // static const VectorFloat DEF_RECT_CONSTANTS; static const VectorFloat DEF_BLCK_CONSTANTS; static const VectorFloat DEF_BART_CONSTANTS; static const VectorFloat DEF_DCHB_CONSTANTS; static const VectorFloat DEF_GAUS_CONSTANTS; static const VectorFloat DEF_HAMM_CONSTANTS; static const VectorFloat DEF_HANN_CONSTANTS; static const VectorFloat DEF_KAIS_CONSTANTS; static const VectorFloat DEF_LIFT_CONSTANTS; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 72000; static const int32 ERR_PRM = 72001; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation name // IMPLEMENTATION implementation_d; // alignment name // ALIGNMENT alignment_d; // normalization name // NORMALIZATION normalization_d; // window duration (in seconds) // Float duration_d; // static memory manager // static MemoryManager mgr_d; // this section contains data for a specific algorithm // // algorithm: non-CUSTOM // mode: all // implementation: MULTIPLICATION // // parameters of the window function: // since different algorithms require different numbers of parameters, // by making this a vector we are able to collapse all algorithms into // one set of function calls. // VectorFloat constants_d; // algorithm: CUSTOM // mode: all // implementation: MULTIPLICATION // // a user-defined window function // VectorFloat data_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static bool8 diagnose(Integral::DEBUG debug_level); // debug methods: // setDebug is inherited from the base class // bool8 debug(const unichar* msg) const; // method: destructor // ~Window() {} // method: default constructor // Window(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, ALIGNMENT alignment = DEF_ALIGNMENT, NORMALIZATION normalization = DEF_NORMALIZATION, float32 duration = DEF_DURATION) { algorithm_d = algorithm; implementation_d = implementation; alignment_d = alignment; normalization_d = normalization; duration_d = duration; is_valid_d = false; } // method: copy constructor // Window(const Window& arg) { assign(arg); } // assign methods // bool8 assign(const Window& arg); // method: operator= // Window& operator= (const Window& arg) { assign(arg); return *this; } // i/o methods // int32 sofSize() const; bool8 read(Sof& sof, int32 tag, const String& name = CLASS_NAME); bool8 write(Sof& sof, int32 tag, const String& name = CLASS_NAME) const; bool8 readData(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeData(Sof& sof, const String& pname = DEF_PARAM) const; // equality methods // bool8 eq(const Window& arg) const; // method: new // static void* operator new(size_t size) { return mgr_d.get(); } // method: new[] // static void* operator new[](size_t size) { return mgr_d.getBlock(size); } // method: delete // static void operator delete(void* ptr) { mgr_d.release(ptr); } // method: delete[] // static void operator delete[](void* ptr) { mgr_d.releaseBlock(ptr); } // method: setGrowSize // static bool8 setGrowSize(int32 grow_size) { return mgr_d.setGrow(grow_size); } // other memory management methods // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE); //--------------------------------------------------------------------------- // // class-specific public methods // set methods // //--------------------------------------------------------------------------- // method: setAlgorithm // bool8 setAlgorithm(ALGORITHM algorithm) { algorithm_d = algorithm; constants_d.clear(Integral::RESET); is_valid_d = false; return true; } // method: setImplementation // bool8 setImplementation(IMPLEMENTATION implementation) { implementation_d = implementation; is_valid_d = false; return true; } // method: setAlignment // bool8 setAlignment(ALIGNMENT alignment) { alignment_d = alignment; is_valid_d = false; return true; } // method: setNormalization // bool8 setNormalization(NORMALIZATION normalization) { normalization_d = normalization; is_valid_d = false; return true; } // method: setDuration // bool8 setDuration(float32 duration) { duration_d = duration; is_valid_d = false; return true; } // method: setSize // bool8 setSize(int32 num_points) { if (data_d.length() != num_points) { data_d.setLength(num_points); is_valid_d = false; } return true; } // method: setData // bool8 setData(const VectorFloat& data) { if (algorithm_d == CUSTOM) { return data_d.assign(data); } else { return Error::handle(name(), L"setData", ERR, __FILE__, __LINE__); } } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, ALIGNMENT alignment = DEF_ALIGNMENT, NORMALIZATION normalization = DEF_NORMALIZATION, float32 duration = DEF_DURATION) { algorithm_d = algorithm; implementation_d = implementation; alignment_d = alignment; normalization_d = normalization; duration_d = duration; is_valid_d = false; return true; } // other set methods // bool8 setConstants(const VectorFloat& constants); //--------------------------------------------------------------------------- // // class-specific public methods // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // ALGORITHM getAlgorithm() const { return algorithm_d; } // method: getImplementation // IMPLEMENTATION getImplementation() const { return implementation_d; } // method: getAlignment // ALIGNMENT getAlignment() const { return alignment_d; } // method: getNormalization // NORMALIZATION getNormalization() const { return normalization_d; } // method: getDuration // float32 getDuration() const { return duration_d; } // method: getSize // int32 getSize() const { return data_d.length(); } // method: getData // const VectorFloat& getData() const { return data_d; } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, ALIGNMENT& alignment, NORMALIZATION& normalization, float32& duration) { algorithm = algorithm_d; implementation = implementation_d; alignment = alignment_d; normalization = normalization_d; duration = duration_d; return true; } // method: getConstants // const VectorFloat& getConstants() const { return constants_d; } //--------------------------------------------------------------------------- // // class-specific public methods: // computational methods // //--------------------------------------------------------------------------- bool8 compute(VectorFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); bool8 compute(VectorComplexFloat& output, const VectorComplexFloat& input, AlgorithmData::COEF_TYPE coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); //--------------------------------------------------------------------------- // // class-specific public methods: // public methods required by the AlgorithmBase interface contract // //--------------------------------------------------------------------------- // assign method // bool8 assign(const AlgorithmBase& arg); // equality method // bool8 eq(const AlgorithmBase& arg) const; // method: className // const String& className() const { return CLASS_NAME; } // initialization method // bool8 init(); // apply method // bool8 apply(Vector& output, const Vector< CircularBuffer >& input); // pad time methods: // windows typically extend beyond the current frame. the leading and // trailing pads return values in frames since the algorithm classes // are designed to be frame based. // int32 getLeadingPad() const; int32 getTrailingPad() const; // method to set the parser // bool8 setParser(SofParser* parser); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // common i/o methods // bool8 readDataCommon(Sof& sof, const String& pname, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeDataCommon(Sof& sof, const String& pname) const; // common compute methods // bool8 computeCommon(VectorFloat& vector_out, const VectorFloat& vector_in); bool8 computeCommon(VectorComplexFloat& vector_out, const VectorComplexFloat& vector_in); // window generation methods: // these methods generate common window functions // bool8 generateRectangular(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateBartlett(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateBlackman(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateDolphChebyshev(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateGaussian(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateGeneralizedHanning(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateKaiser(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 generateLifter(VectorFloat& output, const VectorFloat& params, int32 num_points) const; bool8 compute(VectorFloat& output_a, const CircularBuffer& input_a, AlgorithmData::COEF_TYPE coef_type_a = DEF_COEF_TYPE, int32 channel_index_a = DEF_CHANNEL_INDEX); }; // end of include file // #endif