2 * This file is part of FFmpeg.
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.
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.
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
19 #ifndef AVUTIL_TX_PRIV_H
20 #define AVUTIL_TX_PRIV_H
27 #include "attributes.h"
30 #define TX_NAME(x) x ## _float
31 #define SCALE_TYPE float
32 typedef float FFTSample;
33 typedef AVComplexFloat FFTComplex;
34 #elif defined(TX_DOUBLE)
35 #define TX_NAME(x) x ## _double
36 #define SCALE_TYPE double
37 typedef double FFTSample;
38 typedef AVComplexDouble FFTComplex;
39 #elif defined(TX_INT32)
40 #define TX_NAME(x) x ## _int32
41 #define SCALE_TYPE float
42 typedef int32_t FFTSample;
43 typedef AVComplexInt32 FFTComplex;
45 typedef void FFTComplex;
48 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
50 #define MUL(x, y) ((x)*(y))
52 #define CMUL(dre, dim, are, aim, bre, bim) do { \
53 (dre) = (are) * (bre) - (aim) * (bim); \
54 (dim) = (are) * (bim) + (aim) * (bre); \
57 #define SMUL(dre, dim, are, aim, bre, bim) do { \
58 (dre) = (are) * (bre) - (aim) * (bim); \
59 (dim) = (are) * (bim) - (aim) * (bre); \
62 #define RESCALE(x) (x)
64 #define FOLD(a, b) ((a) + (b))
66 #elif defined(TX_INT32)
68 #define MUL(x, y) ((int32_t)(((int64_t)(x) * (int64_t)(y) + 0x40000000) >> 31))
70 /* Properly rounds the result */
71 #define CMUL(dre, dim, are, aim, bre, bim) do { \
73 (accu) = (int64_t)(bre) * (are); \
74 (accu) -= (int64_t)(bim) * (aim); \
75 (dre) = (int)(((accu) + 0x40000000) >> 31); \
76 (accu) = (int64_t)(bim) * (are); \
77 (accu) += (int64_t)(bre) * (aim); \
78 (dim) = (int)(((accu) + 0x40000000) >> 31); \
81 #define SMUL(dre, dim, are, aim, bre, bim) do { \
83 (accu) = (int64_t)(bre) * (are); \
84 (accu) -= (int64_t)(bim) * (aim); \
85 (dre) = (int)(((accu) + 0x40000000) >> 31); \
86 (accu) = (int64_t)(bim) * (are); \
87 (accu) -= (int64_t)(bre) * (aim); \
88 (dim) = (int)(((accu) + 0x40000000) >> 31); \
91 #define RESCALE(x) (lrintf((x) * 2147483648.0))
93 #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
97 #define BF(x, y, a, b) do { \
102 #define CMUL3(c, a, b) \
103 CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
105 #define COSTABLE(size) \
106 DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2]
108 /* Used by asm, reorder with care */
110 int n; /* Nptwo part */
111 int m; /* Ptwo part */
112 int inv; /* Is inverted */
115 FFTComplex *exptab; /* MDCT exptab */
116 FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
117 int *pfatab; /* Input/Output mapping for compound transforms */
118 int *revtab; /* Input mapping for power of two transforms */
121 /* Shared functions */
122 int ff_tx_type_is_mdct(enum AVTXType type);
123 int ff_tx_gen_compound_mapping(AVTXContext *s);
124 int ff_tx_gen_ptwo_revtab(AVTXContext *s);
126 /* Also used by SIMD init */
127 static inline int split_radix_permutation(int i, int n, int inverse)
134 return split_radix_permutation(i, m, inverse)*2;
136 if (inverse == !(i & m))
137 return split_radix_permutation(i, m, inverse)*4 + 1;
139 return split_radix_permutation(i, m, inverse)*4 - 1;
142 /* Templated functions */
143 int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx,
144 enum AVTXType type, int inv, int len,
145 const void *scale, uint64_t flags);
146 int ff_tx_init_mdct_fft_double(AVTXContext *s, av_tx_fn *tx,
147 enum AVTXType type, int inv, int len,
148 const void *scale, uint64_t flags);
149 int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx,
150 enum AVTXType type, int inv, int len,
151 const void *scale, uint64_t flags);
153 typedef struct CosTabsInitOnce {
158 #endif /* AVUTIL_TX_PRIV_H */