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.

162 lines
6.0KB

  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 "mem_internal.h"
  25. #include "avassert.h"
  26. #include "attributes.h"
  27. #ifdef TX_FLOAT
  28. #define TX_NAME(x) x ## _float
  29. #define SCALE_TYPE float
  30. typedef float FFTSample;
  31. typedef AVComplexFloat FFTComplex;
  32. #elif defined(TX_DOUBLE)
  33. #define TX_NAME(x) x ## _double
  34. #define SCALE_TYPE double
  35. typedef double FFTSample;
  36. typedef AVComplexDouble FFTComplex;
  37. #elif defined(TX_INT32)
  38. #define TX_NAME(x) x ## _int32
  39. #define SCALE_TYPE float
  40. typedef int32_t FFTSample;
  41. typedef AVComplexInt32 FFTComplex;
  42. #else
  43. typedef void FFTComplex;
  44. #endif
  45. #if defined(TX_FLOAT) || defined(TX_DOUBLE)
  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 UNSCALE(x) (x)
  55. #define RESCALE(x) (x)
  56. #define FOLD(a, b) ((a) + (b))
  57. #elif defined(TX_INT32)
  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 UNSCALE(x) ((double)x/2147483648.0)
  78. #define RESCALE(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX))
  79. #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
  80. #endif
  81. #define BF(x, y, a, b) do { \
  82. x = (a) - (b); \
  83. y = (a) + (b); \
  84. } while (0)
  85. #define CMUL3(c, a, b) \
  86. CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
  87. #define COSTABLE(size) \
  88. DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2]
  89. /* Used by asm, reorder with care */
  90. struct AVTXContext {
  91. int n; /* Non-power-of-two part */
  92. int m; /* Power-of-two part */
  93. int inv; /* Is inverse */
  94. int type; /* Type */
  95. uint64_t flags; /* Flags */
  96. double scale; /* Scale */
  97. FFTComplex *exptab; /* MDCT exptab */
  98. FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
  99. int *pfatab; /* Input/Output mapping for compound transforms */
  100. int *revtab; /* Input mapping for power of two transforms */
  101. int *inplace_idx; /* Required indices to revtab for in-place transforms */
  102. };
  103. /* Shared functions */
  104. int ff_tx_type_is_mdct(enum AVTXType type);
  105. int ff_tx_gen_compound_mapping(AVTXContext *s);
  106. int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup);
  107. int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s);
  108. /* Also used by SIMD init */
  109. static inline int split_radix_permutation(int i, int n, int inverse)
  110. {
  111. int m;
  112. if (n <= 2)
  113. return i & 1;
  114. m = n >> 1;
  115. if (!(i & m))
  116. return split_radix_permutation(i, m, inverse)*2;
  117. m >>= 1;
  118. if (inverse == !(i & m))
  119. return split_radix_permutation(i, m, inverse)*4 + 1;
  120. else
  121. return split_radix_permutation(i, m, inverse)*4 - 1;
  122. }
  123. /* Templated functions */
  124. int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx,
  125. enum AVTXType type, int inv, int len,
  126. const void *scale, uint64_t flags);
  127. int ff_tx_init_mdct_fft_double(AVTXContext *s, av_tx_fn *tx,
  128. enum AVTXType type, int inv, int len,
  129. const void *scale, uint64_t flags);
  130. int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx,
  131. enum AVTXType type, int inv, int len,
  132. const void *scale, uint64_t flags);
  133. typedef struct CosTabsInitOnce {
  134. void (*func)(void);
  135. AVOnce control;
  136. } CosTabsInitOnce;
  137. #endif /* AVUTIL_TX_PRIV_H */