fast_math.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #ifndef _Fast_Math_H__
  2. #define _Fast_Math_H__
  3. #include <arm_math.h>
  4. // Constants
  5. #define ONE_BY_SQRT3 (0.57735026919f) // 1/sqrt(3)
  6. #define TWO_BY_SQRT3 (2.0f * 0.57735026919f)
  7. #define SQRT3_BY_2 (0.86602540378f)
  8. #define SQRT3 (1.73205080757f)
  9. #define SQRT2_BY_SQRT3 (0.8164966f)
  10. #define M_PI (3.14159265f)
  11. #define ONE_BY_SQRT3_Q14 (9459L) //0.57735026919 * 16384.0F
  12. #define SQRT3_BY_2_Q14 (14189L)//0.86602540378 * 16384.0F
  13. #define TWO_BY_SQRT3_Q14 (18918L)
  14. #ifndef SQ
  15. #define SQ(x) ((x)*(x))
  16. #endif
  17. void fast_sincos(float angle, float *sin, float *cos);
  18. static void fast_norm_angle(float *angle) {
  19. *angle = fmodf(*angle, 360.0f);
  20. if (*angle < 0.0f) {
  21. *angle += 360.0f;
  22. }
  23. }
  24. static void normal_sincosf(float angle, float *sin, float *cos) {
  25. *sin = arm_sin_f32(angle);
  26. *cos = arm_cos_f32(angle);
  27. }
  28. #define degree_2_pi(d) ((float)d * M_PI / 180.0f)
  29. #define pi_2_degree(d) ((float)d * 180.0f / M_PI)
  30. /**
  31. * A simple low pass filter.
  32. *
  33. * @param value
  34. * The filtered value.
  35. *
  36. * @param sample
  37. * Next sample.
  38. *
  39. * @param filter_constant
  40. * Filter constant. Range 0.0 to 1.0, where 1.0 gives the unfiltered value.
  41. */
  42. //#define LowPass_Filter(value, sample, filter_constant) (value = value * (1.0f - filter_constant) + sample * filter_constant)
  43. #define LowPass_Filter(value, sample, filter_constant) (value = (sample - value) * filter_constant + value)
  44. #endif /* _Fast_Math_H__ */