// file: $isip/class/algo/Energy/Energy.h // version: $Id: Energy.h 7609 2002-01-04 20:55:18Z gao $ // // make sure definitions are only made once // #ifndef ISIP_ENERGY #define ISIP_ENERGY // isip include files // #ifndef ISIP_ALGORITHM_BASE #include #endif #ifndef ISIP_CIRCULAR_DELAY_LINE #include #endif // Energy: a class that computes the energy of a signal. currently, // two modes are supported: SUM - a sum of squares; FILTER - a linear // filtering of the squares of the samples of a signal. a number // of scaling options are available including dB, rms, and power. // class Energy : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define the algorithm choices // enum ALGORITHM { SUM = 0, FILTER, DEF_ALGORITHM = SUM }; // define the implementation choices // enum IMPLEMENTATION { IDENTITY = 0, LOG, DB, POWER, LOG_POWER, DB_POWER, RMS, LOG_RMS, DB_RMS, DEF_IMPLEMENTATION = IDENTITY }; // define the static NameMap objects // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_FLOOR; static const String PARAM_MA_COEF; static const String PARAM_AR_COEF; //---------------------------------------- // // default values and arguments // //---------------------------------------- // define a default value for the energy floor // static const float32 DEF_FLOOR = 0.0; // define default values for the filter coefficients // static const VectorFloat DEF_MA_COEF; static const VectorFloat DEF_AR_COEF; // define default argument(s) // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::DEF_CTYPE; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 70500; static const int32 ERR_UNSUPM = 70510; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation name // IMPLEMENTATION implementation_d; // energy floor (limits the minimum value of energy): // extremely useful when performing log operations // Float floor_d; // static memory manager // static MemoryManager mgr_d; // this section contains data for a specific algorithm // // algorithm: FILTER // implementation: all // // filter coefficients // VectorFloat ma_coef_d; VectorFloat ar_coef_d; // filter memory // Vector< CircularDelayLine > ma_mem_d; Vector< CircularDelayLine > ar_mem_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 // ~Energy() {} // method: default constructor // Energy(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, float32 floor = DEF_FLOOR) { algorithm_d = algorithm; implementation_d = implementation; floor_d = floor; is_valid_d = false; } // method: copy constructor // Energy(const Energy& arg) { assign(arg); } // assign methods // bool8 assign(const Energy& arg); // method: operator= // Energy& operator= (const Energy& 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 Energy& 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; is_valid_d = false; return true; } // method: setImplementation // bool8 setImplementation(IMPLEMENTATION implementation) { implementation_d = implementation; is_valid_d = false; return true; } // method: setFloor // bool8 setFloor(float32 floor = DEF_FLOOR) { floor_d = floor; return true; } // method: setFilter // bool8 setFilter(VectorFloat& ma_coef, VectorFloat& ar_coef) { ma_coef_d.assign(ma_coef); ar_coef_d.assign(ar_coef); is_valid_d = false; return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, float32 floor = DEF_FLOOR) { algorithm_d = algorithm; implementation_d = implementation; floor_d = floor; is_valid_d = false; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // get methods // //--------------------------------------------------------------------------- // method: getAlgorithm // ALGORITHM getAlgorithm() const { return algorithm_d; } // method: getImplementation // IMPLEMENTATION getImplementation() const { return implementation_d; } // method: getFloor // float32 getFloor() const { return floor_d; } // method: getFilter // bool8 getFilter(VectorFloat& ma_coef, VectorFloat& ar_coef) const { ma_coef.assign(ma_coef_d); return ar_coef.assign(ar_coef_d); } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, float32& floor) { algorithm = algorithm_d; implementation = implementation_d; floor = floor_d; return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // computational methods // //--------------------------------------------------------------------------- bool8 compute(VectorFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE input_coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); bool8 compute(VectorFloat& output, const VectorComplexFloat& input, AlgorithmData::COEF_TYPE input_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); // method to set the parser // bool8 setParser(SofParser* parser); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // summation i/o methods // bool8 readDataSum(Sof& sof, const String& pname, int32 size, bool8 param, bool8 nested); bool8 writeDataSum(Sof& sof, const String& pname) const; // filter i/o methods // bool8 readDataFilt(Sof& sof, const String& pname, int32 size, bool8 param, bool8 nested); bool8 writeDataFilt(Sof& sof, const String& pname) const; // summation compute methods // bool8 computeSum(VectorFloat& output, const VectorFloat& input); // filter compute methods // bool8 computeFilt(VectorFloat& output, const VectorFloat& input, int32 channel_index); // implementation-specific scaling method // float32 scale(const Float& value, int32 len); }; // end of include file // #endif