libcm is a C development framework with an emphasis on audio signal processing applications.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

cmGlobal.h 5.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. //{
  2. //(
  3. // cmGlobal.h contains the global macros, header files, and
  4. // typedefs availale to all other cm modules.
  5. //
  6. // All operating system dependencies should be resolved in this file via
  7. // testing for OS_LINUX, OS_OSX, or OS_W32.
  8. //)
  9. #ifndef cmGlobal_h
  10. #define cmGlobal_h
  11. //(
  12. #include "config.h" // created by 'configure'
  13. #include <stdio.h>
  14. #include <stdlib.h>
  15. #include <string.h>
  16. #include <assert.h>
  17. #include <stdbool.h>
  18. #include <stdarg.h>
  19. #include <math.h>
  20. #include <ctype.h>
  21. #include <errno.h>
  22. #include <float.h>
  23. #include <limits.h>
  24. #include <signal.h>
  25. #include <time.h>
  26. #ifdef __cplusplus
  27. extern "C" {
  28. #endif
  29. #define CM_FLOAT_SMP 1 //< make cmSample_t = float in cmFloatTypes.h
  30. #define CM_FLOAT_REAL 0 //< make cmReal_t = double in cmFloatTypes.h
  31. #ifdef NDEBUG
  32. #define cmDEBUG_FL 0 //< Define cmDEBUG_FL as 0 when building in release mode. See \ref debug_mode.
  33. #else
  34. #define cmDEBUG_FL 1 //< Define cmDEBUG_FL as 1 when building in debug mode. See \ref debug_mode.
  35. #endif
  36. // Perform byte swapping on 16 bit values.
  37. #define cmSwap16(x) \
  38. (((((unsigned short)(x)) & 0x00ff) << 8) | ((((unsigned short)(x)) & 0xff00) >> 8))
  39. #ifdef OS_LINUX
  40. #include <byteswap.h> // gcc specific
  41. #include <unistd.h>
  42. // Perform byte swapping on 32 bit values on systems were <byteswap.h> is available.
  43. #define cmSwap32(x) (bswap_32(x))
  44. // Perform byte swapping on 64 bit values on systems were <byteswap.h> is available.
  45. #define cmSwap64(x) (bswap_64(x))
  46. #endif
  47. #ifdef OS_OSX
  48. #include <unistd.h>
  49. // Perform byte swapping on 32 bit values on systems were <byteswap.h> is not available.
  50. #define cmSwap32(x) \
  51. ((((unsigned)((x) & 0x000000FF)) << 24) | \
  52. (((unsigned)((x) & 0x0000FF00)) << 8) | \
  53. (((unsigned)((x) & 0x00FF0000)) >> 8) | \
  54. (((unsigned)((x) & 0xFF000000)) >> 24))
  55. // Perform byte swapping on 64 bit values on systems were <byteswap.h> is not available.
  56. #define cmSwap64(x) \
  57. (((((unsigned long long)(x))<<56) & 0xFF00000000000000ULL) | \
  58. ((((unsigned long long)(x))<<40) & 0x00FF000000000000ULL) | \
  59. ((((unsigned long long)(x))<<24) & 0x0000FF0000000000ULL) | \
  60. ((((unsigned long long)(x))<< 8) & 0x000000FF00000000ULL) | \
  61. ((((unsigned long long)(x))>> 8) & 0x00000000FF000000ULL) | \
  62. ((((unsigned long long)(x))>>24) & 0x0000000000FF0000ULL) | \
  63. ((((unsigned long long)(x))>>40) & 0x000000000000FF00ULL) | \
  64. ((((unsigned long long)(x))>>56) & 0x00000000000000FFULL))
  65. #endif
  66. #define cmAllFlags(f,m) (((f) & (m)) == (m)) //< Test if all of a group 'm' of binary flags in 'f' are set.
  67. #define cmIsFlag(f,m) (((f) & (m)) ? true : false) //< Test if any one of a the bits in 'm' is also set in 'f'.
  68. #define cmIsNotFlag(f,m) (cmIsFlag(f,m)==false) //< Test if none of the bits in 'm' are set in 'f'.
  69. #define cmSetFlag(f,m) ((f) | (m)) //< Return 'f' with the bits in 'm' set.
  70. #define cmClrFlag(f,m) ((f) & (~(m))) //< Return 'f' with the bits in 'm' cleared.
  71. #define cmTogFlag(f,m) ((f)^(m)) //< Return 'f' with the bits in 'm' toggled.
  72. #define cmEnaFlag(f,m,b) (b) ? cmSetFlag(f,m) : cmClrFlag(f,m) //< \brief Set or clear bits in 'f' based on bits in 'm' and the state of 'b'.
  73. //<
  74. //< If 'b' == 0 then return 'f' with the bits in 'm' cleared.
  75. //< otherwise return 'f' with the bits in 'm' set.
  76. #define cmMin(v0,v1) ((v0)<(v1) ? (v0) : (v1)) //< Return the minimum arg.
  77. #define cmMax(v0,v1) ((v0)>(v1) ? (v0) : (v1)) //< Return the maximum arg.
  78. #define cmStringNullGuard(p) ((p)==NULL?"<null>":(p)) //< If 'p'==NULL return the static string "<null>" otherwise return 'p'.
  79. // Default return code indicating successful function completion.
  80. #define cmOkRC (0)
  81. // Default directory separator character for unix based systems.
  82. #define cmPathSeparatorChar ("/")
  83. #define cmInvalidIdx (0xffffffff) //< cm wide value indicating a invalid or NULL index.
  84. #define cmInvalidId (cmInvalidIdx) //< cm wide value indicating an invalid or NULL numeric id.
  85. #define cmInvalidCnt (cmInvalidIdx) //< cm wide value indicating a invalid or NULL count of items.
  86. #define cmSTATIC_NULL_HANDLE {NULL} //< Default NULL value for cmHandle_t
  87. // Generic data type for implementing opaque object handles.
  88. /*
  89. typedef struct cmHandle_str
  90. {
  91. void* h;
  92. } cmHandle_t;
  93. */
  94. #define cmHandle_t struct { void* h; }
  95. #define cmHandlesAreEqual( a, b ) ((a).h == (b).h) //< Test if two cmHandle_t values are equivalent.
  96. #define cmHandlesAreNotEqual( a, b ) (!cmHandlesAreEqual(a,b)) //< Test if two cmHandle_t value are not equivalent.
  97. // Data type commonly used as a function return value. Functions returning cmRC_t values
  98. // return cmOkRC (0) to indicate successful completion or some other value to indicate
  99. // some kind of exceptional conidtion. In general the condition indicates an unexpected condition
  100. // such as resource exhaution, or a missing file.
  101. typedef unsigned cmRC_t;
  102. // A data type which indicates a system dependent error. This is generally an abstraction for an 'errno'
  103. // like code.
  104. typedef int cmSysErrCode_t; // same as errno
  105. // cmChar_t is a data type used to indicate that a char is being used to hold human readable
  106. // text. Eventually this type will be used to locate and handle unicode based strings.
  107. typedef char cmChar_t;
  108. typedef unsigned int cmUInt32_t; //< This typedef is used to indicate that the type must be an unsigned 32 bit integer.
  109. typedef unsigned short cmUInt16_t; //< This typedef is used to indicate that hte type must be an unsigned 16 bit integer.
  110. #ifdef __cplusplus
  111. }
  112. #endif
  113. //)
  114. //}
  115. #endif