libcm is a C development framework with an emphasis on audio signal processing applications.
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

cmMath.h 4.9KB

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