fast_math.h 887 B

123456789101112131415161718192021222324252627282930313233
  1. #ifndef _Fast_Math_H__
  2. #define _Fast_Math_H__
  3. // Constants
  4. #define ONE_BY_SQRT3 (0.57735026919f) // 1/sqrt(3)
  5. #define TWO_BY_SQRT3 (2.0f * 0.57735026919f)
  6. #define SQRT3_BY_2 (0.86602540378f)
  7. #define SQRT3 (1.73205080757f)
  8. #define SQRT2_BY_SQRT3 (0.8164966f)
  9. #define M_PI (3.14159265f)
  10. #ifndef SQ
  11. #define SQ(x) ((x)*(x))
  12. #endif
  13. void fast_sincos(float angle, float *sin, float *cos);
  14. void fast_norm_angle(float *angle);
  15. void normal_sincosf(float angle, float *sin, float *cos);
  16. /**
  17. * A simple low pass filter.
  18. *
  19. * @param value
  20. * The filtered value.
  21. *
  22. * @param sample
  23. * Next sample.
  24. *
  25. * @param filter_constant
  26. * Filter constant. Range 0.0 to 1.0, where 1.0 gives the unfiltered value.
  27. */
  28. #define LowPass_Filter(value, sample, filter_constant) (value = value * (1.0f - filter_constant) + sample * filter_constant)
  29. #endif /* _Fast_Math_H__ */