libcm is a C development framework with an emphasis on audio signal processing applications.
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #ifndef cmMath_h
  2. #define cmMath_h
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. //( { file_desc:"Math utility functions" kw:[math] }
  7. double cmX80ToDouble( unsigned char s[10] );
  8. void cmDoubleToX80( double v, unsigned char s[10] );
  9. bool cmIsPowerOfTwo( unsigned i );
  10. unsigned cmNextPowerOfTwo( unsigned i );
  11. unsigned cmNearPowerOfTwo( unsigned i );
  12. bool cmIsOddU( unsigned v );
  13. bool cmIsEvenU( unsigned v );
  14. unsigned cmNextOddU( unsigned v );
  15. unsigned cmPrevOddU( unsigned v );
  16. unsigned cmNextEvenU( unsigned v );
  17. unsigned cmPrevEvenU( unsigned v );
  18. /// Increment or decrement 'idx' by 'delta' always wrapping the result into the range
  19. /// 0 to (maxN-1).
  20. /// 'idx': initial value
  21. /// 'delta': incremental amount
  22. /// 'maxN' - 1 : maximum return value.
  23. unsigned cmModIncr(int idx, int delta, int maxN );
  24. // modified bessel function of first kind, order 0
  25. // ref: orfandis appendix B io.m
  26. double cmBessel0( double x );
  27. //=================================================================
  28. // The following elliptic-related function approximations come from
  29. // Parks & Burrus, Digital Filter Design, Appendix program 9, pp. 317-326
  30. // which in turn draws directly on other sources
  31. // calculate complete elliptic integral (quarter period) K
  32. // given *complimentary* modulus kc
  33. cmReal_t cmEllipK( cmReal_t kc );
  34. // calculate elliptic modulus k
  35. // given ratio of complete elliptic integrals r = K/K'
  36. // (solves the "degree equation" for fixed N = K*K1'/K'K1)
  37. cmReal_t cmEllipDeg( cmReal_t r );
  38. // calculate arc elliptic tangent u (elliptic integral of the 1st kind)
  39. // given argument x = sc(u,k) and *complimentary* modulus kc
  40. cmReal_t cmEllipArcSc( cmReal_t x, cmReal_t kc );
  41. // calculate Jacobi elliptic functions sn, cn, and dn
  42. // given argument u and *complimentary* modulus kc
  43. cmRC_t cmEllipJ( cmReal_t u, cmReal_t kc, cmReal_t* sn, cmReal_t* cn, cmReal_t* dn );
  44. //=================================================================
  45. // bilinear transform
  46. // z = (2*sr + s)/(2*sr - s)
  47. cmRC_t cmBlt( unsigned n, cmReal_t sr, cmReal_t* rp, cmReal_t* ip );
  48. //=================================================================
  49. // Pitch conversion
  50. unsigned cmHzToMidi( double hz );
  51. float cmMidiToHz( unsigned midi );
  52. //=================================================================
  53. // Floating point byte swapping
  54. unsigned cmFfSwapFloatToUInt( float v );
  55. float cmFfSwapUIntToFloat( unsigned v );
  56. unsigned long long cmFfSwapDoubleToULLong( double v );
  57. double cmFfSwapULLongToDouble( unsigned long long v );
  58. //=================================================================
  59. int cmRandInt( int min, int max );
  60. unsigned cmRandUInt( unsigned min, unsigned max );
  61. float cmRandFloat( float min, float max );
  62. double cmRandDouble( double min, double max );
  63. //=================================================================
  64. bool cmIsCloseD( double x0, double x1, double eps );
  65. bool cmIsCloseF( float x0, float x1, double eps );
  66. bool cmIsCloseI( int x0, int x1, double eps );
  67. bool cmIsCloseU( unsigned x0, unsigned x1, double eps );
  68. //=================================================================
  69. // Run a length 'lfsrN' linear feedback shift register (LFSR) for 'yN' iterations to
  70. // produce a length 'yN' bit string in yV[yN].
  71. // 'lfsrN' count of bits in the shift register range: 2<= lfsrN <= 32.
  72. // 'tapMask' is a bit mask which gives the tap indexes positions for the LFSR.
  73. // The least significant bit corresponds to the maximum delay tap position.
  74. // The min tap position is therefore denoted by the tap mask bit location 1 << (lfsrN-1).
  75. // A minimum of two taps must exist.
  76. // 'seed' sets the initial delay state.
  77. // 'yV[yN]' is the the output vector
  78. // 'yN' is count of elements in yV.
  79. // The function resturn kOkAtRC on success or kInvalidArgsRCRC if any arguments are invalid.
  80. // /sa cmLFSR_Test.
  81. void cmLFSR( unsigned lfsrN, unsigned tapMask, unsigned seed, unsigned* yV, unsigned yN );
  82. // Example and test code for cmLFSR()
  83. bool cmLFSR_Test();
  84. // Generate a set of 'goldN' Gold codes using the Maximum Length Sequences (MLS) generated
  85. // by a length 'lfsrN' linear feedback shift register.
  86. // 'err' is an error object to be set if the the function fails.
  87. // 'lfsrN' is the length of the Linear Feedback Shift Registers (LFSR) used to generate the MLS.
  88. // 'poly_coeff0' tap mask for the first LFSR.
  89. // 'coeff1' tap mask the the second LFSR.
  90. // 'goldN' is the count of Gold codes to generate.
  91. // 'yM[mlsN', goldN] is a column major output matrix where each column contains a Gold code.
  92. // 'mlsN' is the length of the maximum length sequence for each Gold code which can be
  93. // calculated as mlsN = (1 << a->lfsrN) - 1.
  94. // Note that values of 'lfsrN' and the 'poly_coeffx' must be carefully selected such that
  95. // they will produce a MLS. For example to generate a MLS with length 31 set 'lfsrN' to 5 and
  96. // then select poly_coeff from two different elements of the set {0x12 0x14 0x17 0x1B 0x1D 0x1E}.
  97. // See http://www.ece.cmu.edu/~koopman/lfsr/index.html for a complete set of MSL polynomial
  98. // coefficients for given LFSR lengths.
  99. // Returns false if insufficient balanced pairs exist.
  100. bool cmGenGoldCodes( unsigned lfsrN, unsigned poly_coeff0, unsigned poly_coeff1, unsigned goldN, int* yM, unsigned mlsN );
  101. //)
  102. #ifdef __cplusplus
  103. }
  104. #endif
  105. #endif