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.

159 lines
5.8KB

  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. #ifndef AVUTIL_TX_PRIV_H
  19. #define AVUTIL_TX_PRIV_H
  20. #include "tx.h"
  21. #include <stddef.h>
  22. #include "thread.h"
  23. #include "mem.h"
  24. #include "avassert.h"
  25. #include "attributes.h"
  26. #ifdef TX_FLOAT
  27. #define TX_NAME(x) x ## _float
  28. #define SCALE_TYPE float
  29. typedef float FFTSample;
  30. typedef AVComplexFloat FFTComplex;
  31. #elif defined(TX_DOUBLE)
  32. #define TX_NAME(x) x ## _double
  33. #define SCALE_TYPE double
  34. typedef double FFTSample;
  35. typedef AVComplexDouble FFTComplex;
  36. #elif defined(TX_INT32)
  37. #define TX_NAME(x) x ## _int32
  38. #define SCALE_TYPE float
  39. typedef int32_t FFTSample;
  40. typedef AVComplexInt32 FFTComplex;
  41. #else
  42. typedef void FFTComplex;
  43. #endif
  44. #if defined(TX_FLOAT) || defined(TX_DOUBLE)
  45. #define MUL(x, y) ((x)*(y))
  46. #define CMUL(dre, dim, are, aim, bre, bim) do { \
  47. (dre) = (are) * (bre) - (aim) * (bim); \
  48. (dim) = (are) * (bim) + (aim) * (bre); \
  49. } while (0)
  50. #define SMUL(dre, dim, are, aim, bre, bim) do { \
  51. (dre) = (are) * (bre) - (aim) * (bim); \
  52. (dim) = (are) * (bim) - (aim) * (bre); \
  53. } while (0)
  54. #define RESCALE(x) (x)
  55. #define FOLD(a, b) ((a) + (b))
  56. #elif defined(TX_INT32)
  57. #define MUL(x, y) ((int32_t)(((int64_t)(x) * (int64_t)(y) + 0x40000000) >> 31))
  58. /* Properly rounds the result */
  59. #define CMUL(dre, dim, are, aim, bre, bim) do { \
  60. int64_t accu; \
  61. (accu) = (int64_t)(bre) * (are); \
  62. (accu) -= (int64_t)(bim) * (aim); \
  63. (dre) = (int)(((accu) + 0x40000000) >> 31); \
  64. (accu) = (int64_t)(bim) * (are); \
  65. (accu) += (int64_t)(bre) * (aim); \
  66. (dim) = (int)(((accu) + 0x40000000) >> 31); \
  67. } while (0)
  68. #define SMUL(dre, dim, are, aim, bre, bim) do { \
  69. int64_t accu; \
  70. (accu) = (int64_t)(bre) * (are); \
  71. (accu) -= (int64_t)(bim) * (aim); \
  72. (dre) = (int)(((accu) + 0x40000000) >> 31); \
  73. (accu) = (int64_t)(bim) * (are); \
  74. (accu) -= (int64_t)(bre) * (aim); \
  75. (dim) = (int)(((accu) + 0x40000000) >> 31); \
  76. } while (0)
  77. #define RESCALE(x) (lrintf((x) * 2147483648.0))
  78. #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
  79. #endif
  80. #define BF(x, y, a, b) do { \
  81. x = (a) - (b); \
  82. y = (a) + (b); \
  83. } while (0)
  84. #define CMUL3(c, a, b) \
  85. CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
  86. #define COSTABLE(size) \
  87. DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2]
  88. /* Used by asm, reorder with care */
  89. struct AVTXContext {
  90. int n; /* Nptwo part */
  91. int m; /* Ptwo part */
  92. int inv; /* Is inverted */
  93. int type; /* Type */
  94. FFTComplex *exptab; /* MDCT exptab */
  95. FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
  96. int *pfatab; /* Input/Output mapping for compound transforms */
  97. int *revtab; /* Input mapping for power of two transforms */
  98. };
  99. /* Shared functions */
  100. int ff_tx_type_is_mdct(enum AVTXType type);
  101. int ff_tx_gen_compound_mapping(AVTXContext *s);
  102. int ff_tx_gen_ptwo_revtab(AVTXContext *s);
  103. /* Also used by SIMD init */
  104. static inline int split_radix_permutation(int i, int n, int inverse)
  105. {
  106. int m;
  107. if (n <= 2)
  108. return i & 1;
  109. m = n >> 1;
  110. if (!(i & m))
  111. return split_radix_permutation(i, m, inverse)*2;
  112. m >>= 1;
  113. if (inverse == !(i & m))
  114. return split_radix_permutation(i, m, inverse)*4 + 1;
  115. else
  116. return split_radix_permutation(i, m, inverse)*4 - 1;
  117. }
  118. /* Templated functions */
  119. int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx,
  120. enum AVTXType type, int inv, int len,
  121. const void *scale, uint64_t flags);
  122. int ff_tx_init_mdct_fft_double(AVTXContext *s, av_tx_fn *tx,
  123. enum AVTXType type, int inv, int len,
  124. const void *scale, uint64_t flags);
  125. int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx,
  126. enum AVTXType type, int inv, int len,
  127. const void *scale, uint64_t flags);
  128. typedef struct CosTabsInitOnce {
  129. void (*func)(void);
  130. AVOnce control;
  131. } CosTabsInitOnce;
  132. #endif /* AVUTIL_TX_PRIV_H */