⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 integral.h

📁 这是一个从音频信号里提取特征参量的程序
💻 H
📖 第 1 页 / 共 2 页
字号:
// file: $isip/class/system/Integral/Integral.h// version: $Id: Integral.h,v 1.105 2003/05/14 15:35:48 zheng Exp $//// make sure definitions are only made once://  the isip convention is to use the class name preceded by "ISIP_"//#ifndef ISIP_INTEGRAL#define ISIP_INTEGRAL// system include files - since all classes include a debug method// which calls Console, a FILE* is required. we will include stdio.h// here, in order that every class need not replicate this. for// convenience, we also include stdlib.h, since this contains many// useful C functions. math.h and limits.h define useful constants and// system functions. unistd.h is included for the definition of// sleep.//#include <stdio.h>#include <stdlib.h>#include <limits.h>#include <math.h>#include <unistd.h>// possibly include the dmalloc library//#ifdef ISIP_DMALLOC#include <dmalloc.h>#endif// include the configure output//#define ISIP_INTERNAL_USE_ONLY#include <IntegralConfigure.h>#undef ISIP_INTERNAL_USE_ONLY// include the internal integral types//#define ISIP_INTERNAL_USE_ONLY#include <IntegralTypes.h>#undef ISIP_INTERNAL_USE_ONLY// include the internal namespace conflict prevention list//#define ISIP_INTERNAL_USE_ONLY#include <IntegralNameSpace.h>#undef ISIP_INTERNAL_USE_ONLY// forward class definition(s)//class SysString;class SysChar;// Integral: define some low level system functions to be used by// other classes.//class Integral {  //---------------------------------------------------------------------------  //  // public constants  //  //---------------------------------------------------------------------------public:    // define the class name  //  static const SysString CLASS_NAME;    //-----------------------------------------  //  // operating system related string constants  //  //-----------------------------------------    // define environmental variables which should be present  //  static const SysString ENV_ISIP;  static const SysString ENV_HOME;  // define some constants that facilitate parsing of environment variables  // and file pathnames under unix  //  static const SysChar ENV_MARKER;  static const SysChar DIR_DELIM;  static const SysChar DIR_HOME;  // define some unix commands  //  static const SysString UNIX_CMD_COPY;  static const SysString UNIX_CMD_MOVE;  static const SysString UNIX_CMD_REDIR;  // define some constants for temporary filename creation  //  static const SysString TMPDIR;  static const SysString TMP_FMT_0;  static const SysString TMP_FMT_1;  static const SysString TMP_TEMPLATE;  // define some constants related to help message generation  //  static const SysString HELP_FORMAT;  static const SysString HELP_OPTION;  //----------------------------------------  //  // operating system related enumerated constants  //  //----------------------------------------    // define negative and positive sign  //  static const long NEGATIVE = -1;  static const long POSITIVE = 1;    // define some sorting and comparison constants - they are useful from time  // to time to have a global notion of the result of the order of things.  // these constants should be used for sorting classes, comparisons, etc.  //  enum ORDER { ASCENDING = 0, DESCENDING, COLLATING, DEF_ORDER = ASCENDING };  enum COMPARE { LESSER = 0, EQUAL, GREATER, DEF_COMPARE = EQUAL };  // define constants that control the behavior of the clear method  //  enum CMODE { RETAIN = 0, RESET, RELEASE, FREE, DEF_CMODE = RESET };  // define constants that control the behavior of the graph class  //  enum COLOR { WHITE = 0, GREY, BLACK, BLUE, GREEN, DEF_COLOR = WHITE };    // define constants for representing the storage mode of a matrix -  // it is again useful to have a global notion of the storage type of  // a matrix:  //  //  MatrixFloat a(Integral::SYMMETRIC);  //  MatrixLong  b(Integral::SYMMETRIC);  //  // vs.  //   //  MatrixFloat a(MatrixFloat::SYMMETRIC);  //  MatrixLong  b(MatrixLong::SYMMETRIC);  //  enum MTYPE { FULL = 0, DIAGONAL, SYMMETRIC,	       LOWER_TRIANGULAR, UPPER_TRIANGULAR, SPARSE,	       UNCHANGED, UNKNOWN, DEF_MTYPE = FULL };  // define a return value for exiting  //  static const long SYS_RETURN_ERROR = 1;  static const long SYS_RETURN_NOERROR = 0;  // define some debugging constants  //  enum DEBUG { NONE = 0, BRIEF, DETAILED, ALL, DEF_DEBUG = NONE };  //----------------------------------------  //  // other numeric constants  //  //----------------------------------------    // define some maximum sizes (i/o in unix still needs some fixed  // buffers every now and then)  //  static const long MAX_FNAME_SIZE = PATH_MAX;  // define some constants related to geometry and pi  //  static const double PI = M_PI;  static const double TWO_PI = (2.0*PI);  static const double HALF_PI = (M_PI_2);  static const double QUARTER_PI = (M_PI_4);  static const double SQRT_TWO_PI = 2.506628274631;  static const double INV_PI = M_1_PI;  static const double TWO_INV_PI = M_2_PI;  static const double SQRT_TWO = M_SQRT2;  static const double INV_SQRT_TWO_PI = (1.0 / SQRT_TWO_PI);  static const double DEGREES_IN_CIRCLE = 360.0;    // define a iteration count for testing random functions in diagnose method  //  static const long DIAG_ITER_COUNT = 100;  // default arguments to find methods  //  static const long NO_POS = -1;    // define important powers of two  //  static const double TWO_EXP7  = ((ulong)1 << 7);  static const double TWO_EXP8  = ((ulong)1 << 8);  static const double TWO_EXP15 = ((ulong)1 << 15);  static const double TWO_EXP16 = ((ulong)1 << 16);  static const double TWO_EXP23 = ((ulong)1 << 23);  static const double TWO_EXP24 = ((ulong)1 << 24);  static const double TWO_EXP31 = ((ulong)1 << 31);  static const double TWO_EXP32 = (TWO_EXP16 * TWO_EXP16);  static const double TWO_EXP63 = (TWO_EXP32 * TWO_EXP31);  static const double TWO_EXP64 = (TWO_EXP32 * TWO_EXP32);    // define constants related to natural logarithms  //  static const double E = M_E;  static const double LOG2E = M_LOG2E;  static const double LOG10E = M_LOG10E;  static const double LN2 = M_LN2;  static const double LN10 = M_LN10;  // define constants related to changing the base of a logarithm:  //  currently, we only need to accommodate base 2  //  static const double INV_LN2 = 1.0 / M_LN2;    static const double INV_LN10 = 1.0 / M_LN10;    // define the square root and inverse of square root of 2  //  static const double SQRT2 = M_SQRT2;  static const double INV_SQRT2 = M_SQRT1_2;    // define dB constants  //    static const double DB_POW_MIN_VALUE = 1.0e-10;  static const double DB_POW_SCALE_FACTOR = 10.0;    static const double DB_MAG_MIN_VALUE = 1.0e-10;  static const double DB_MAG_SCALE_FACTOR = 20.0;  static const double DB_LOG_MIN_VALUE = -1.0e10;    static const double DB_MIN_VALUE = -100.0;  // define dB limits:  //  1. MIN_LOG_VALUE is computed as follows:  //     MIN_SCORE = -1e+10 = -1 / exp(MIN_LOG_SCORE)  //  static const double MIN_LOG_VALUE = -23.02585093;  //----------------------------------------  //  // default values and arguments  //  //----------------------------------------    // default arguments to methods  //  static const long DEF_GROW_SIZE = 1024;    // default precision values  //  // the almostEqual method compares two numbers to a user-specified  // level of precision.  the precision is specified as a percentage  // of the arguments.  the scale is used to control the range over  // which the comparison is imposed.  //  static const double DEF_PERCENTAGE = 0.1;  static const double DEF_BOUND = 0.01;  //---------------------------------------  //  // error codes  //  //---------------------------------------  static const long ERR = 1500;  //---------------------------------------------------------------------------  //  // protected data  //  //---------------------------------------------------------------------------protected:  // declare a static debug level:  //  the debug flag is static because the Integral class is never instantiated  //  static Integral::DEBUG debug_level_d;    //---------------------------------------------------------------------------  //  // required public methods  //  //---------------------------------------------------------------------------public:    // method: name  //  static const SysString& name() {    return CLASS_NAME;  }  // other static methods  //  static boolean diagnose(DEBUG debug_level);    // method: setDebug  //  static boolean setDebug(Integral::DEBUG level) {    debug_level_d = level;    return true;  }  // other debug methods:  //  generally, the debug method is non-static. however,  //  here it must be static so that the class can be called without being  //  instantiated  //  static boolean debug(const unichar* message);    // destructor/constructor(s) are private  //  // assign methods:  //  these methods are omitted because Integral objects  //  can not be instantiated  //  // operator= methods:  //  these methods are omitted because Integral objects  //  can not be instantiated  //    // i/o methods:  //  these methods are omitted because Integral objects  //  can not be instantiated  //  // equality methods:  //  these methods are omitted because Integral objects  //  can not be instantiated  //  // memory management methods:  //  these methods are omitted because Integral objects  //  can not be instantiated  //  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  general operating system methods  //  //---------------------------------------------------------------------------  // wrappers for operating system methods:  //  environmental variables  //  static boolean getEnv(SysString& val, const SysString& var);  static boolean getLoginDir(SysString& directory,			     const SysString& login_name);  static boolean expandName(SysString& exp_file, const SysString& in_file);  // method: getPid  //  get a process id number  //  static long getPid() {    return (long)(getpid());  }  // method: getParentPid  //  get the parent process id number  //  static long getParentPid() {    return (long)getppid();  }  // wrapper for operating system methods:  //  cleanly exit a program by invoking proper garbage collection  //  static long exit();    // wrappers for operating system methods:  //  temporary files  //  static boolean makeTemp(SysString& tmp_file, const SysString& name);  static boolean makeTemp(SysString& tmp_file);  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  bit-level methods  //  //---------------------------------------------------------------------------  // method: almostEqual (generalized case)  //  the general implementation of almostEqual performs a bitwise comparison  //  between the arguments and checks for equality. this is useful  //  for types such as integers and chars. this is not the main use  //  of this method. it is really intended to compare floating point  //  quantities to a user-specified level of precision. note that the  //  default values supplied here are essentially ignored.  //  //  note that overloads are used as opposed to default values since  //  default values do not work in concert with template specializations.  //  template <class TIntegral>  static boolean almostEqual(TIntegral arg1, TIntegral arg2,			     double percent = DEF_PERCENTAGE,                             double bound = DEF_BOUND) {    return (arg1 == arg2);  }  // method: almostEqual  //  define a specialized version for floats. the main reason for this  //  method is to make sure the double version gets called for floating  //  point numbers (avoiding type ambiguity).  //  static boolean almostEqual(float arg1, float arg2,			     double percent = DEF_PERCENTAGE,                             double bound = DEF_BOUND) {    return almostEqual((double)arg1, (double)arg2, percent, bound);  }  // method: almostEqual  //  define a specialized version for doubles  //  static boolean almostEqual(double arg1, double arg2,			     double percent = DEF_PERCENTAGE,                             double bound = DEF_BOUND);    // method: almostEqual  //  define a specialized version for complexfloats. the main reason  //  for this method is to make sure the double version gets called  //  for floating point numbers (avoiding type ambiguity).  //  static boolean almostEqual(const complexfloat& arg1,			     const complexfloat& arg2,			     double percent = DEF_PERCENTAGE,			     double bound = DEF_BOUND) {    return (almostEqual(arg1.real(), arg2.real(), percent, bound) &&	    almostEqual(arg1.imag(), arg2.imag(), percent, bound));  }  // method: almostEqual  //  define a specialized version for complexdouble. the main reason  //  for this method is to make sure the double version gets called  //  for floating point numbers (avoiding type ambiguity).  //  static boolean almostEqual(const complexdouble& arg1,			     const complexdouble& arg2,			     double percent = DEF_PERCENTAGE,                             double bound = DEF_BOUND) {    return (almostEqual(arg1.real(), arg2.real(), percent, bound) &&	    almostEqual(arg1.imag(), arg2.imag(), percent, bound));  }  //---------------------------------------------------------------------------  //  // class-specific public methods:  //  inlined wrappers for math and other C functions (listed alphabetically)  //  //---------------------------------------------------------------------------  // method: abs  //  static double abs(double arg) {    return ::fabs(arg);  }  // method: acos  //  static double acos(double arg) {    return ::acos(arg);  }  // method: acosh  //  static double acosh(double arg) {    return ::log(arg + ::sqrt(arg * arg - (double)1));  }  // method: asin  //  static double asin(double arg) {    return ::asin(arg);  }  // method: asinh  //  static double asinh(double arg) {    return ::log(arg + ::sqrt(arg * arg + (double)1));  }  // method: atan  //  static double atan(double arg) {    return ::atan(arg);  }  // method: atanh  //  static double atanh(double arg) {    return 0.5 * ::log(((double)1 + arg) / ((double)1 - arg));  }  // method: ceil

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -