FFTReal.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /*****************************************************************************
  2. FFTReal.h
  3. By Laurent de Soras
  4. --- Legal stuff ---
  5. This program is free software. It comes without any warranty, to
  6. the extent permitted by applicable law. You can redistribute it
  7. and/or modify it under the terms of the Do What The Fuck You Want
  8. To Public License, Version 2, as published by Sam Hocevar. See
  9. http://sam.zoy.org/wtfpl/COPYING for more details.
  10. *Tab=3***********************************************************************/
  11. #if ! defined (ffft_FFTReal_HEADER_INCLUDED)
  12. #define ffft_FFTReal_HEADER_INCLUDED
  13. #if defined (_MSC_VER)
  14. #pragma once
  15. #pragma warning (4 : 4250) // "Inherits via dominance."
  16. #endif
  17. /*\\\ INCLUDE FILES \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  18. #include "def.h"
  19. #include "DynArray.h"
  20. #include "OscSinCos.h"
  21. namespace ffft
  22. {
  23. template <class DT>
  24. class FFTReal
  25. {
  26. /*\\\ PUBLIC \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  27. public:
  28. enum { MAX_BIT_DEPTH = 30 }; // So length can be represented as long int
  29. typedef DT DataType;
  30. explicit FFTReal (long length);
  31. virtual ~FFTReal () {}
  32. long get_length () const;
  33. void do_fft (DataType f [], const DataType x []) const;
  34. void do_ifft (const DataType f [], DataType x []) const;
  35. void rescale (DataType x []) const;
  36. DataType * use_buffer () const;
  37. /*\\\ PROTECTED \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  38. protected:
  39. /*\\\ PRIVATE \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  40. private:
  41. // Over this bit depth, we use direct calculation for sin/cos
  42. enum { TRIGO_BD_LIMIT = 12 };
  43. typedef OscSinCos <DataType> OscType;
  44. void init_br_lut ();
  45. void init_trigo_lut ();
  46. void init_trigo_osc ();
  47. ffft_FORCEINLINE const long *
  48. get_br_ptr () const;
  49. ffft_FORCEINLINE const DataType *
  50. get_trigo_ptr (int level) const;
  51. ffft_FORCEINLINE long
  52. get_trigo_level_index (int level) const;
  53. inline void compute_fft_general (DataType f [], const DataType x []) const;
  54. inline void compute_direct_pass_1_2 (DataType df [], const DataType x []) const;
  55. inline void compute_direct_pass_3 (DataType df [], const DataType sf []) const;
  56. inline void compute_direct_pass_n (DataType df [], const DataType sf [], int pass) const;
  57. inline void compute_direct_pass_n_lut (DataType df [], const DataType sf [], int pass) const;
  58. inline void compute_direct_pass_n_osc (DataType df [], const DataType sf [], int pass) const;
  59. inline void compute_ifft_general (const DataType f [], DataType x []) const;
  60. inline void compute_inverse_pass_n (DataType df [], const DataType sf [], int pass) const;
  61. inline void compute_inverse_pass_n_osc (DataType df [], const DataType sf [], int pass) const;
  62. inline void compute_inverse_pass_n_lut (DataType df [], const DataType sf [], int pass) const;
  63. inline void compute_inverse_pass_3 (DataType df [], const DataType sf []) const;
  64. inline void compute_inverse_pass_1_2 (DataType x [], const DataType sf []) const;
  65. const long _length;
  66. const int _nbr_bits;
  67. DynArray <long>
  68. _br_lut;
  69. DynArray <DataType>
  70. _trigo_lut;
  71. mutable DynArray <DataType>
  72. _buffer;
  73. mutable DynArray <OscType>
  74. _trigo_osc;
  75. /*\\\ FORBIDDEN MEMBER FUNCTIONS \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/
  76. private:
  77. FFTReal ();
  78. FFTReal (const FFTReal &other);
  79. FFTReal & operator = (const FFTReal &other);
  80. bool operator == (const FFTReal &other);
  81. bool operator != (const FFTReal &other);
  82. }; // class FFTReal
  83. } // namespace ffft
  84. #include "FFTReal.hpp"
  85. #endif // ffft_FFTReal_HEADER_INCLUDED
  86. /*\\\ EOF \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\*/