You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

178 lines
6.6KB

  1. /* Copyright (c) 2013 Julien Pommier ( pommier@modartt.com )
  2. Based on original fortran 77 code from FFTPACKv4 from NETLIB,
  3. authored by Dr Paul Swarztrauber of NCAR, in 1985.
  4. As confirmed by the NCAR fftpack software curators, the following
  5. FFTPACKv5 license applies to FFTPACKv4 sources. My changes are
  6. released under the same terms.
  7. FFTPACK license:
  8. http://www.cisl.ucar.edu/css/software/fftpack5/ftpk.html
  9. Copyright (c) 2004 the University Corporation for Atmospheric
  10. Research ("UCAR"). All rights reserved. Developed by NCAR's
  11. Computational and Information Systems Laboratory, UCAR,
  12. www.cisl.ucar.edu.
  13. Redistribution and use of the Software in source and binary forms,
  14. with or without modification, is permitted provided that the
  15. following conditions are met:
  16. - Neither the names of NCAR's Computational and Information Systems
  17. Laboratory, the University Corporation for Atmospheric Research,
  18. nor the names of its sponsors or contributors may be used to
  19. endorse or promote products derived from this Software without
  20. specific prior written permission.
  21. - Redistributions of source code must retain the above copyright
  22. notices, this list of conditions, and the disclaimer below.
  23. - Redistributions in binary form must reproduce the above copyright
  24. notice, this list of conditions, and the disclaimer below in the
  25. documentation and/or other materials provided with the
  26. distribution.
  27. THIS SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  28. EXPRESS OR IMPLIED, INCLUDING, BUT NOT LIMITED TO THE WARRANTIES OF
  29. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  30. NONINFRINGEMENT. IN NO EVENT SHALL THE CONTRIBUTORS OR COPYRIGHT
  31. HOLDERS BE LIABLE FOR ANY CLAIM, INDIRECT, INCIDENTAL, SPECIAL,
  32. EXEMPLARY, OR CONSEQUENTIAL DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  33. ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  34. CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
  35. SOFTWARE.
  36. */
  37. /*
  38. PFFFT : a Pretty Fast FFT.
  39. This is basically an adaptation of the single precision fftpack
  40. (v4) as found on netlib taking advantage of SIMD instruction found
  41. on cpus such as intel x86 (SSE1), powerpc (Altivec), and arm (NEON).
  42. For architectures where no SIMD instruction is available, the code
  43. falls back to a scalar version.
  44. Restrictions:
  45. - 1D transforms only, with 32-bit single precision.
  46. - supports only transforms for inputs of length N of the form
  47. N=(2^a)*(3^b)*(5^c), a >= 5, b >=0, c >= 0 (32, 48, 64, 96, 128,
  48. 144, 160, etc are all acceptable lengths). Performance is best for
  49. 128<=N<=8192.
  50. - all (float*) pointers in the functions below are expected to
  51. have an "simd-compatible" alignment, that is 16 bytes on x86 and
  52. powerpc CPUs.
  53. You can allocate such buffers with the functions
  54. pffft_aligned_malloc / pffft_aligned_free (or with stuff like
  55. posix_memalign..)
  56. */
  57. #ifndef PFFFT_H
  58. #define PFFFT_H
  59. #include <stddef.h> // for size_t
  60. #ifdef __cplusplus
  61. extern "C" {
  62. #endif
  63. /* opaque struct holding internal stuff (precomputed twiddle factors)
  64. this struct can be shared by many threads as it contains only
  65. read-only data.
  66. */
  67. typedef struct PFFFT_Setup PFFFT_Setup;
  68. /* direction of the transform */
  69. typedef enum { PFFFT_FORWARD, PFFFT_BACKWARD } pffft_direction_t;
  70. /* type of transform */
  71. typedef enum { PFFFT_REAL, PFFFT_COMPLEX } pffft_transform_t;
  72. /*
  73. prepare for performing transforms of size N -- the returned
  74. PFFFT_Setup structure is read-only so it can safely be shared by
  75. multiple concurrent threads.
  76. */
  77. PFFFT_Setup *pffft_new_setup(int N, pffft_transform_t transform);
  78. void pffft_destroy_setup(PFFFT_Setup *);
  79. /*
  80. Perform a Fourier transform , The z-domain data is stored in the
  81. most efficient order for transforming it back, or using it for
  82. convolution. If you need to have its content sorted in the
  83. "usual" way, that is as an array of interleaved complex numbers,
  84. either use pffft_transform_ordered , or call pffft_zreorder after
  85. the forward fft, and before the backward fft.
  86. Transforms are not scaled: PFFFT_BACKWARD(PFFFT_FORWARD(x)) = N*x.
  87. Typically you will want to scale the backward transform by 1/N.
  88. The 'work' pointer should point to an area of N (2*N for complex
  89. fft) floats, properly aligned. If 'work' is NULL, then stack will
  90. be used instead (this is probably the best strategy for small
  91. FFTs, say for N < 16384).
  92. input and output may alias.
  93. */
  94. void pffft_transform(PFFFT_Setup *setup, const float *input, float *output, float *work, pffft_direction_t direction);
  95. /*
  96. Similar to pffft_transform, but makes sure that the output is
  97. ordered as expected (interleaved complex numbers). This is
  98. similar to calling pffft_transform and then pffft_zreorder.
  99. input and output may alias.
  100. */
  101. void pffft_transform_ordered(PFFFT_Setup *setup, const float *input, float *output, float *work, pffft_direction_t direction);
  102. /*
  103. call pffft_zreorder(.., PFFFT_FORWARD) after pffft_transform(...,
  104. PFFFT_FORWARD) if you want to have the frequency components in
  105. the correct "canonical" order, as interleaved complex numbers.
  106. (for real transforms, both 0-frequency and half frequency
  107. components, which are real, are assembled in the first entry as
  108. F(0)+i*F(n/2+1). Note that the original fftpack did place
  109. F(n/2+1) at the end of the arrays).
  110. input and output should not alias.
  111. */
  112. void pffft_zreorder(PFFFT_Setup *setup, const float *input, float *output, pffft_direction_t direction);
  113. /*
  114. Perform a multiplication of the frequency components of dft_a and
  115. dft_b and accumulate them into dft_ab. The arrays should have
  116. been obtained with pffft_transform(.., PFFFT_FORWARD) and should
  117. *not* have been reordered with pffft_zreorder (otherwise just
  118. perform the operation yourself as the dft coefs are stored as
  119. interleaved complex numbers).
  120. the operation performed is: dft_ab += (dft_a * fdt_b)*scaling
  121. The dft_a, dft_b and dft_ab pointers may alias.
  122. */
  123. void pffft_zconvolve_accumulate(PFFFT_Setup *setup, const float *dft_a, const float *dft_b, float *dft_ab, float scaling);
  124. /*
  125. the float buffers must have the correct alignment (16-byte boundary
  126. on intel and powerpc). This function may be used to obtain such
  127. correctly aligned buffers.
  128. */
  129. void *pffft_aligned_malloc(size_t nb_bytes);
  130. void pffft_aligned_free(void *);
  131. /* return 4 or 1 wether support SSE/Altivec instructions was enable when building pffft.c */
  132. int pffft_simd_size();
  133. #ifdef __cplusplus
  134. }
  135. #endif
  136. #endif // PFFFT_H