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
5.2KB

  1. /*
  2. * Copyright (c) 2000, 2001, 2002 Fabrice Bellard
  3. * Copyright (c) 2002-2004 Michael Niedermayer <michaelni@gmx.at>
  4. *
  5. * This file is part of Libav.
  6. *
  7. * Libav is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * Libav is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with Libav; if not, write to the Free Software
  19. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  20. */
  21. #ifndef AVCODEC_FFT_H
  22. #define AVCODEC_FFT_H
  23. #include <stdint.h>
  24. #include "config.h"
  25. #include "libavutil/mem.h"
  26. #include "avfft.h"
  27. /* FFT computation */
  28. struct FFTContext {
  29. int nbits;
  30. int inverse;
  31. uint16_t *revtab;
  32. FFTComplex *tmp_buf;
  33. int mdct_size; /* size of MDCT (i.e. number of input data * 2) */
  34. int mdct_bits; /* n = 2^nbits */
  35. /* pre/post rotation tables */
  36. FFTSample *tcos;
  37. FFTSample *tsin;
  38. /**
  39. * Do the permutation needed BEFORE calling fft_calc().
  40. */
  41. void (*fft_permute)(struct FFTContext *s, FFTComplex *z);
  42. /**
  43. * Do a complex FFT with the parameters defined in ff_fft_init(). The
  44. * input data must be permuted before. No 1.0/sqrt(n) normalization is done.
  45. */
  46. void (*fft_calc)(struct FFTContext *s, FFTComplex *z);
  47. void (*imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
  48. void (*imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
  49. void (*mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input);
  50. int fft_permutation;
  51. #define FF_FFT_PERM_DEFAULT 0
  52. #define FF_FFT_PERM_SWAP_LSBS 1
  53. int mdct_permutation;
  54. #define FF_MDCT_PERM_NONE 0
  55. #define FF_MDCT_PERM_INTERLEAVE 1
  56. };
  57. #if CONFIG_HARDCODED_TABLES
  58. #define COSTABLE_CONST const
  59. #define SINTABLE_CONST const
  60. #else
  61. #define COSTABLE_CONST
  62. #define SINTABLE_CONST
  63. #endif
  64. #define COSTABLE(size) \
  65. COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2]
  66. #define SINTABLE(size) \
  67. SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2]
  68. extern COSTABLE(16);
  69. extern COSTABLE(32);
  70. extern COSTABLE(64);
  71. extern COSTABLE(128);
  72. extern COSTABLE(256);
  73. extern COSTABLE(512);
  74. extern COSTABLE(1024);
  75. extern COSTABLE(2048);
  76. extern COSTABLE(4096);
  77. extern COSTABLE(8192);
  78. extern COSTABLE(16384);
  79. extern COSTABLE(32768);
  80. extern COSTABLE(65536);
  81. extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17];
  82. /**
  83. * Initialize the cosine table in ff_cos_tabs[index]
  84. * \param index index in ff_cos_tabs array of the table to initialize
  85. */
  86. void ff_init_ff_cos_tabs(int index);
  87. extern SINTABLE(16);
  88. extern SINTABLE(32);
  89. extern SINTABLE(64);
  90. extern SINTABLE(128);
  91. extern SINTABLE(256);
  92. extern SINTABLE(512);
  93. extern SINTABLE(1024);
  94. extern SINTABLE(2048);
  95. extern SINTABLE(4096);
  96. extern SINTABLE(8192);
  97. extern SINTABLE(16384);
  98. extern SINTABLE(32768);
  99. extern SINTABLE(65536);
  100. /**
  101. * Set up a complex FFT.
  102. * @param nbits log2 of the length of the input array
  103. * @param inverse if 0 perform the forward transform, if 1 perform the inverse
  104. */
  105. int ff_fft_init(FFTContext *s, int nbits, int inverse);
  106. void ff_fft_init_altivec(FFTContext *s);
  107. void ff_fft_init_mmx(FFTContext *s);
  108. void ff_fft_init_arm(FFTContext *s);
  109. void ff_dct_init_mmx(DCTContext *s);
  110. void ff_fft_end(FFTContext *s);
  111. int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale);
  112. void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
  113. void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input);
  114. void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
  115. void ff_mdct_end(FFTContext *s);
  116. /* Real Discrete Fourier Transform */
  117. struct RDFTContext {
  118. int nbits;
  119. int inverse;
  120. int sign_convention;
  121. /* pre/post rotation tables */
  122. const FFTSample *tcos;
  123. SINTABLE_CONST FFTSample *tsin;
  124. FFTContext fft;
  125. void (*rdft_calc)(struct RDFTContext *s, FFTSample *z);
  126. };
  127. /**
  128. * Set up a real FFT.
  129. * @param nbits log2 of the length of the input array
  130. * @param trans the type of transform
  131. */
  132. int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
  133. void ff_rdft_end(RDFTContext *s);
  134. void ff_rdft_init_arm(RDFTContext *s);
  135. /* Discrete Cosine Transform */
  136. struct DCTContext {
  137. int nbits;
  138. int inverse;
  139. RDFTContext rdft;
  140. const float *costab;
  141. FFTSample *csc2;
  142. void (*dct_calc)(struct DCTContext *s, FFTSample *data);
  143. void (*dct32)(FFTSample *out, const FFTSample *in);
  144. };
  145. /**
  146. * Set up DCT.
  147. * @param nbits size of the input array:
  148. * (1 << nbits) for DCT-II, DCT-III and DST-I
  149. * (1 << nbits) + 1 for DCT-I
  150. *
  151. * @note the first element of the input of DST-I is ignored
  152. */
  153. int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
  154. void ff_dct_end (DCTContext *s);
  155. #endif /* AVCODEC_FFT_H */