libcm is a C development framework with an emphasis on audio signal processing applications.
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

cmMath.h 5.1KB

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