NUMfft_f.cpp 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* NUMfft_f.c
  2. *
  3. * Copyright (C) 1997-2011 David Weenink
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or (at
  8. * your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful, but
  11. * WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  18. */
  19. /* djmw 20020701 GPL header
  20. djmw 20040511 Added n>1 test for compatibility with old behaviour.
  21. */
  22. #include "NUM2.h"
  23. #include "melder.h"
  24. #define my me ->
  25. #define FFT_DATA_TYPE float
  26. #include "NUMfft_core.h"
  27. void NUMforwardRealFastFourierTransform_f (float *data, integer n) {
  28. struct NUMfft_Table_f table_struct;
  29. NUMfft_Table_f table = &table_struct;
  30. NUMfft_Table_init_f (table, n);
  31. NUMfft_forward_f (table, data);
  32. if (n > 1) {
  33. // To be compatible with old behaviour
  34. float tmp = data[n];
  35. for (integer i = n; i > 2; i--) {
  36. data[i] = data[i - 1];
  37. }
  38. data[2] = tmp;
  39. }
  40. NUMfft_Table_free_f (table);
  41. }
  42. void NUMreverseRealFastFourierTransform_f (float *data, integer n) {
  43. struct NUMfft_Table_f table_struct;
  44. NUMfft_Table_f table = & table_struct;
  45. if (n > 1) {
  46. // To be compatible with old behaviour
  47. float tmp = data[2];
  48. for (integer i = 2; i < n; i++) {
  49. data[i] = data[i + 1];
  50. }
  51. data[n] = tmp;
  52. }
  53. NUMfft_Table_init_f (table, n);
  54. NUMfft_backward_f (table, data);
  55. NUMfft_Table_free_f (table);
  56. }
  57. void NUMfft_forward_f (NUMfft_Table_f me, float *data) {
  58. if (my n == 1) {
  59. return;
  60. }
  61. drftf1 (my n, &data[1], my trigcache, my trigcache + my n, my splitcache);
  62. }
  63. void NUMfft_backward_f (NUMfft_Table_f me, float *data) {
  64. if (my n == 1) {
  65. return;
  66. }
  67. drftb1 (my n, &data[1], my trigcache, my trigcache + my n, my splitcache);
  68. }
  69. void NUMfft_Table_init_f (NUMfft_Table_f me, integer n) {
  70. my n = n;
  71. my trigcache = NUMvector<float> (0, 3 * n - 1);
  72. my splitcache = NUMvector<integer> (0, 31);
  73. NUMrffti (n, my trigcache, my splitcache);
  74. }
  75. void NUMfft_Table_free_f (NUMfft_Table_f me) {
  76. if (me) {
  77. NUMvector_free (my trigcache, 0);
  78. NUMvector_free (my splitcache, 0);
  79. }
  80. }
  81. void NUMrealft_f (float *data, integer n, int isign) {
  82. isign == 1 ? NUMforwardRealFastFourierTransform_f (data, n) :
  83. NUMreverseRealFastFourierTransform_f (data, n);
  84. }
  85. /* End of file NUMfft.cpp */