tx_priv.h 5.7 KB

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