// file: $isip/class/algo/Spectrum/Spectrum.h // version: $Id: Spectrum.h 8348 2002-07-12 03:51:03Z parihar $ // // make sure definitions are only made once // #ifndef ISIP_SPECTRUM #define ISIP_SPECTRUM // isip include files // #ifndef ISIP_ALGORITM_BASE #include #endif #ifndef ISIP_FOURIER_TRANSFORM #include #endif #ifndef ISIP_MEMORY_MANAGER #include #endif #ifndef ISIP_PREDICTION #include #endif #ifndef ISIP_CORRELATION #include #endif #ifndef ISIP_REFLECTION #include #endif // Spectrum: a class that is used to calculate the spectrum of given // data. the input data can be sampled data, linear prediction // coefficients or autocorrelation coefficients. the output spectrum // can be in complex spectrum. // class Spectrum : public AlgorithmBase { //--------------------------------------------------------------------------- // // public constants // //--------------------------------------------------------------------------- public: // define the class name // static const String CLASS_NAME; //---------------------------------------- // // other important constants // //---------------------------------------- // define algorithm choices // enum ALGORITHM { FOURIER, MAXIMUM_ENTROPY, DEF_ALGORITHM = FOURIER }; // define implementation choices // enum IMPLEMENTATION { MAGNITUDE = 0, COMPLEX, DEF_IMPLEMENTATION = MAGNITUDE }; // define static NameMap objects for the enumerated values // static const NameMap ALGO_MAP; static const NameMap IMPL_MAP; // define maximum entropy spectrum scale // static const Float MAGNITUDE_SCALE; static const ComplexFloat COMPLEX_SCALE; //---------------------------------------- // // i/o related constants // //---------------------------------------- static const String DEF_PARAM; static const String PARAM_ALGORITHM; static const String PARAM_IMPLEMENTATION; static const String PARAM_DYN_RANGE; static const String PARAM_FT; //---------------------------------------- // // default values and arguments // //---------------------------------------- // default arguments to methods // static const AlgorithmData::COEF_TYPE DEF_COEF_TYPE = AlgorithmData::SIGNAL; //---------------------------------------- // // error codes // //---------------------------------------- static const int32 ERR = 71600; //--------------------------------------------------------------------------- // // protected data // //--------------------------------------------------------------------------- protected: // algorithm name // ALGORITHM algorithm_d; // implementation name // IMPLEMENTATION implementation_d; // parameters related to the alogorithm specification // Float dyn_range_d; // FourierTransform object // FourierTransform ft_d; // static memory manager // static MemoryManager mgr_d; //--------------------------------------------------------------------------- // // required public methods // //--------------------------------------------------------------------------- public: // method: name // static const String& name() { return CLASS_NAME; } // other static methods // static bool8 diagnose(Integral::DEBUG debug_level); // method: setDebug // this method is inherited from the AlgorithmBase class // other debug methods // bool8 debug(const unichar* msg) const; // method: destructor // ~Spectrum() {} // method: default constructor // Spectrum(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, float32 dyn_range = Prediction::DEF_DYN_RANGE) { algorithm_d = algorithm; implementation_d = implementation; dyn_range_d = dyn_range; } // method: copy consturctor // Spectrum(const Spectrum& arg) { assign(arg); } // method: assign // bool8 assign(const Spectrum& arg) { algorithm_d = arg.algorithm_d; implementation_d = arg.implementation_d; dyn_range_d = arg.dyn_range_d; ft_d.assign(arg.ft_d); return true; } // method: operator= // Spectrum& operator= (const Spectrum& copy_node) { assign(copy_node); 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; // method: eq // bool8 eq(const Spectrum& arg) const { return ((algorithm_d == arg.algorithm_d) && (implementation_d == arg.implementation_d) && (dyn_range_d == arg.dyn_range_d) && (ft_d.eq(arg.ft_d))); } // 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); } // method: clear // bool8 clear(Integral::CMODE ctype = Integral::DEF_CMODE) { if (ctype != Integral::RETAIN) { ft_d.clear(ctype); algorithm_d = DEF_ALGORITHM; implementation_d = DEF_IMPLEMENTATION; dyn_range_d = Prediction::DEF_DYN_RANGE; } return AlgorithmBase::clear(ctype); } //--------------------------------------------------------------------------- // // class-specific public methods: // set methods // //--------------------------------------------------------------------------- // method: setAlgorithm // bool8 setAlgorithm(ALGORITHM algorithm) { algorithm_d = algorithm; return true; } // method: setImplementation // bool8 setImplementation(IMPLEMENTATION implementation) { implementation_d = implementation; is_valid_d = false; return true; } // method: setDynRange // bool8 setDynRange(float32 dyn_range) { dyn_range_d = dyn_range; return true; } // method: setFtAlgorithm // bool8 setFtAlgorithm(FourierTransform::ALGORITHM algorithm) { ft_d.setAlgorithm(algorithm); return true; } // method: setFtImplementation // bool8 setFtImplementation(FourierTransform::IMPLEMENTATION implementation) { ft_d.setImplementation(implementation); return true; } // method: setFtOrder // bool8 setFtOrder(int32 order) { ft_d.setOrder(order); return true; } // method: set // bool8 set(ALGORITHM algorithm = DEF_ALGORITHM, IMPLEMENTATION implementation = DEF_IMPLEMENTATION, float32 dyn_range = Prediction::DEF_DYN_RANGE, FourierTransform::ALGORITHM ft_algorithm = FourierTransform::DEF_ALGORITHM, FourierTransform::IMPLEMENTATION ft_implementation = FourierTransform::DEF_IMPLEMENTATION, int32 order = FourierTransform::DEF_ORDER) { setAlgorithm(algorithm); setImplementation(implementation); setDynRange(dyn_range); setFtAlgorithm(ft_algorithm); setFtImplementation(ft_implementation); setFtOrder(order); 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: getDynRange // float32 getDynRange() const { return dyn_range_d; } // method: getFtAlgorithm // FourierTransform::ALGORITHM getFtAlgorithm() const { return ft_d.getAlgorithm(); } // method: getFtImplementation // FourierTransform::IMPLEMENTATION getFtImplementation() const { return ft_d.getImplementation(); } // method: getFtOrder // int32 getFtOrder() const { return ft_d.getOrder(); } // method: get // bool8 get(ALGORITHM& algorithm, IMPLEMENTATION& implementation, float32& dyn_range, FourierTransform::ALGORITHM& ft_algorithm, FourierTransform::IMPLEMENTATION& ft_implementation, float32& order) const { algorithm = algorithm_d; implementation = implementation_d; dyn_range = dyn_range_d; ft_algorithm = ft_d.getAlgorithm(); ft_implementation = ft_d.getImplementation(); order = ft_d.getOrder(); return true; } //--------------------------------------------------------------------------- // // class-specific public methods: // computational methods // //--------------------------------------------------------------------------- // compute methods for floats // bool8 compute(VectorFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE input_coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); bool8 compute(VectorComplexFloat& output, const VectorFloat& input, AlgorithmData::COEF_TYPE input_coef_type = DEF_COEF_TYPE, int32 index = DEF_CHANNEL_INDEX); //--------------------------------------------------------------------------- // // class-specific public methods: // interface contract methods // //-------------------------------------------------------------------------- // assign method // bool8 assign(const AlgorithmBase& arg); // equality method // bool8 eq(const AlgorithmBase& arg) const; // method: className // const String& className() const { return CLASS_NAME; } // apply method // bool8 apply(Vector& output, const Vector< CircularBuffer >& input); // other set methods // bool8 setParser(SofParser* parser); //--------------------------------------------------------------------------- // // private methods // //--------------------------------------------------------------------------- private: // common i/o methods // bool8 readDataCommon(Sof& sof, const String& pname = DEF_PARAM, int32 size = SofParser::FULL_OBJECT, bool8 param = true, bool8 nested = false); bool8 writeDataCommon(Sof& sof, const String& pname = DEF_PARAM) const; // algorithm-specific compute methods: // algorithm: FOURIER // implementation: MAGNITUDE // bool8 computeFourierMag(VectorFloat& output, const VectorFloat& input); // algorithm-specific compute methods: // algorithm: FOURIER // implementation: COMPLEX // bool8 computeFourierComplex(VectorComplexFloat& output, const VectorFloat& input); // algorithm-specific compute methods: // algorithm: MAXIMUM_ENTROPY // implementation: MAGNITUDE // bool8 computeReflectionMag(VectorFloat& output, const VectorFloat& input, float64 range = Prediction::DEF_DYN_RANGE); bool8 computePredictionMag(VectorFloat& output, const VectorFloat& input); bool8 computeCorrelationMag(VectorFloat& output, const VectorFloat& input, float64 range = Prediction::DEF_DYN_RANGE); // algorithm-specific compute methods: // algorithm: MAXIMUM_ENTROPY // implementation: COMPLEX // bool8 computeReflectionComplex(VectorComplexFloat& output, const VectorFloat& input, float64 range = Prediction::DEF_DYN_RANGE); bool8 computePredictionComplex(VectorComplexFloat& output, const VectorFloat& input); bool8 computeCorrelationComplex(VectorComplexFloat& output, const VectorFloat& input, float64 range = Prediction::DEF_DYN_RANGE); }; // end of include file // #endif