avfft.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * This file is part of FFmpeg.
  3. *
  4. * FFmpeg is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Lesser General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2.1 of the License, or (at your option) any later version.
  8. *
  9. * FFmpeg is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Lesser General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Lesser General Public
  15. * License along with FFmpeg; if not, write to the Free Software
  16. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  17. */
  18. #include "libavutil/attributes.h"
  19. #include "libavutil/mem.h"
  20. #include "avfft.h"
  21. #include "fft.h"
  22. #include "rdft.h"
  23. #include "dct.h"
  24. /* FFT */
  25. FFTContext *av_fft_init(int nbits, int inverse)
  26. {
  27. FFTContext *s = av_mallocz(sizeof(*s));
  28. if (s && ff_fft_init(s, nbits, inverse))
  29. av_freep(&s);
  30. return s;
  31. }
  32. void av_fft_permute(FFTContext *s, FFTComplex *z)
  33. {
  34. s->fft_permute(s, z);
  35. }
  36. void av_fft_calc(FFTContext *s, FFTComplex *z)
  37. {
  38. s->fft_calc(s, z);
  39. }
  40. av_cold void av_fft_end(FFTContext *s)
  41. {
  42. if (s) {
  43. ff_fft_end(s);
  44. av_free(s);
  45. }
  46. }
  47. #if CONFIG_MDCT
  48. FFTContext *av_mdct_init(int nbits, int inverse, double scale)
  49. {
  50. FFTContext *s = av_malloc(sizeof(*s));
  51. if (s && ff_mdct_init(s, nbits, inverse, scale))
  52. av_freep(&s);
  53. return s;
  54. }
  55. void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
  56. {
  57. s->imdct_calc(s, output, input);
  58. }
  59. void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
  60. {
  61. s->imdct_half(s, output, input);
  62. }
  63. void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
  64. {
  65. s->mdct_calc(s, output, input);
  66. }
  67. av_cold void av_mdct_end(FFTContext *s)
  68. {
  69. if (s) {
  70. ff_mdct_end(s);
  71. av_free(s);
  72. }
  73. }
  74. #endif /* CONFIG_MDCT */
  75. #if CONFIG_RDFT
  76. RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
  77. {
  78. RDFTContext *s = av_malloc(sizeof(*s));
  79. if (s && ff_rdft_init(s, nbits, trans))
  80. av_freep(&s);
  81. return s;
  82. }
  83. void av_rdft_calc(RDFTContext *s, FFTSample *data)
  84. {
  85. s->rdft_calc(s, data);
  86. }
  87. av_cold void av_rdft_end(RDFTContext *s)
  88. {
  89. if (s) {
  90. ff_rdft_end(s);
  91. av_free(s);
  92. }
  93. }
  94. #endif /* CONFIG_RDFT */
  95. #if CONFIG_DCT
  96. DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
  97. {
  98. DCTContext *s = av_malloc(sizeof(*s));
  99. if (s && ff_dct_init(s, nbits, inverse))
  100. av_freep(&s);
  101. return s;
  102. }
  103. void av_dct_calc(DCTContext *s, FFTSample *data)
  104. {
  105. s->dct_calc(s, data);
  106. }
  107. av_cold void av_dct_end(DCTContext *s)
  108. {
  109. if (s) {
  110. ff_dct_end(s);
  111. av_free(s);
  112. }
  113. }
  114. #endif /* CONFIG_DCT */