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.

202 lines
5.9KB

  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. #define SINETABLE_CONST const
  61. #else
  62. #define COSTABLE_CONST
  63. #define SINTABLE_CONST
  64. #define SINETABLE_CONST
  65. #endif
  66. #define COSTABLE(size) \
  67. COSTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_cos_##size)[size/2]
  68. #define SINTABLE(size) \
  69. SINTABLE_CONST DECLARE_ALIGNED(16, FFTSample, ff_sin_##size)[size/2]
  70. #define SINETABLE(size) \
  71. SINETABLE_CONST DECLARE_ALIGNED(16, float, ff_sine_##size)[size]
  72. extern COSTABLE(16);
  73. extern COSTABLE(32);
  74. extern COSTABLE(64);
  75. extern COSTABLE(128);
  76. extern COSTABLE(256);
  77. extern COSTABLE(512);
  78. extern COSTABLE(1024);
  79. extern COSTABLE(2048);
  80. extern COSTABLE(4096);
  81. extern COSTABLE(8192);
  82. extern COSTABLE(16384);
  83. extern COSTABLE(32768);
  84. extern COSTABLE(65536);
  85. extern COSTABLE_CONST FFTSample* const ff_cos_tabs[17];
  86. /**
  87. * Initialize the cosine table in ff_cos_tabs[index]
  88. * \param index index in ff_cos_tabs array of the table to initialize
  89. */
  90. void ff_init_ff_cos_tabs(int index);
  91. extern SINTABLE(16);
  92. extern SINTABLE(32);
  93. extern SINTABLE(64);
  94. extern SINTABLE(128);
  95. extern SINTABLE(256);
  96. extern SINTABLE(512);
  97. extern SINTABLE(1024);
  98. extern SINTABLE(2048);
  99. extern SINTABLE(4096);
  100. extern SINTABLE(8192);
  101. extern SINTABLE(16384);
  102. extern SINTABLE(32768);
  103. extern SINTABLE(65536);
  104. /**
  105. * Set up a complex FFT.
  106. * @param nbits log2 of the length of the input array
  107. * @param inverse if 0 perform the forward transform, if 1 perform the inverse
  108. */
  109. int ff_fft_init(FFTContext *s, int nbits, int inverse);
  110. void ff_fft_init_altivec(FFTContext *s);
  111. void ff_fft_init_mmx(FFTContext *s);
  112. void ff_fft_init_arm(FFTContext *s);
  113. void ff_dct_init_mmx(DCTContext *s);
  114. void ff_fft_end(FFTContext *s);
  115. /**
  116. * Generate a sine window.
  117. * @param window pointer to half window
  118. * @param n size of half window
  119. */
  120. void ff_sine_window_init(float *window, int n);
  121. /**
  122. * initialize the specified entry of ff_sine_windows
  123. */
  124. void ff_init_ff_sine_windows(int index);
  125. extern SINETABLE( 32);
  126. extern SINETABLE( 64);
  127. extern SINETABLE( 128);
  128. extern SINETABLE( 256);
  129. extern SINETABLE( 512);
  130. extern SINETABLE(1024);
  131. extern SINETABLE(2048);
  132. extern SINETABLE(4096);
  133. extern SINETABLE_CONST float * const ff_sine_windows[13];
  134. int ff_mdct_init(FFTContext *s, int nbits, int inverse, double scale);
  135. void ff_imdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
  136. void ff_imdct_half_c(FFTContext *s, FFTSample *output, const FFTSample *input);
  137. void ff_mdct_calc_c(FFTContext *s, FFTSample *output, const FFTSample *input);
  138. void ff_mdct_end(FFTContext *s);
  139. /* Real Discrete Fourier Transform */
  140. struct RDFTContext {
  141. int nbits;
  142. int inverse;
  143. int sign_convention;
  144. /* pre/post rotation tables */
  145. const FFTSample *tcos;
  146. SINTABLE_CONST FFTSample *tsin;
  147. FFTContext fft;
  148. void (*rdft_calc)(struct RDFTContext *s, FFTSample *z);
  149. };
  150. /**
  151. * Set up a real FFT.
  152. * @param nbits log2 of the length of the input array
  153. * @param trans the type of transform
  154. */
  155. int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans);
  156. void ff_rdft_end(RDFTContext *s);
  157. void ff_rdft_init_arm(RDFTContext *s);
  158. /* Discrete Cosine Transform */
  159. struct DCTContext {
  160. int nbits;
  161. int inverse;
  162. RDFTContext rdft;
  163. const float *costab;
  164. FFTSample *csc2;
  165. void (*dct_calc)(struct DCTContext *s, FFTSample *data);
  166. void (*dct32)(FFTSample *out, const FFTSample *in);
  167. };
  168. /**
  169. * Set up DCT.
  170. * @param nbits size of the input array:
  171. * (1 << nbits) for DCT-II, DCT-III and DST-I
  172. * (1 << nbits) + 1 for DCT-I
  173. *
  174. * @note the first element of the input of DST-I is ignored
  175. */
  176. int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType type);
  177. void ff_dct_end (DCTContext *s);
  178. #endif /* AVCODEC_FFT_H */