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
24 #include "mem_internal.h"
26 #include "attributes.h"
29 #define TX_NAME(x) x ## _float
30 #define SCALE_TYPE float
31 typedef float FFTSample;
32 typedef AVComplexFloat FFTComplex;
33 #elif defined(TX_DOUBLE)
34 #define TX_NAME(x) x ## _double
35 #define SCALE_TYPE double
36 typedef double FFTSample;
37 typedef AVComplexDouble FFTComplex;
38 #elif defined(TX_INT32)
39 #define TX_NAME(x) x ## _int32
40 #define SCALE_TYPE float
41 typedef int32_t FFTSample;
42 typedef AVComplexInt32 FFTComplex;
44 typedef void FFTComplex;
47 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
49 #define CMUL(dre, dim, are, aim, bre, bim) \
51 (dre) = (are) * (bre) - (aim) * (bim); \
52 (dim) = (are) * (bim) + (aim) * (bre); \
55 #define SMUL(dre, dim, are, aim, bre, bim) \
57 (dre) = (are) * (bre) - (aim) * (bim); \
58 (dim) = (are) * (bim) - (aim) * (bre); \
61 #define UNSCALE(x) (x)
62 #define RESCALE(x) (x)
64 #define FOLD(a, b) ((a) + (b))
66 #elif defined(TX_INT32)
68 /* Properly rounds the result */
69 #define CMUL(dre, dim, are, aim, bre, bim) \
72 (accu) = (int64_t)(bre) * (are); \
73 (accu) -= (int64_t)(bim) * (aim); \
74 (dre) = (int)(((accu) + 0x40000000) >> 31); \
75 (accu) = (int64_t)(bim) * (are); \
76 (accu) += (int64_t)(bre) * (aim); \
77 (dim) = (int)(((accu) + 0x40000000) >> 31); \
80 #define SMUL(dre, dim, are, aim, bre, bim) \
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 UNSCALE(x) ((double)x/2147483648.0)
92 #define RESCALE(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX))
94 #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
98 #define BF(x, y, a, b) \
104 #define CMUL3(c, a, b) \
105 CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
107 #define COSTABLE(size) \
108 DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/4 + 1]
110 /* Used by asm, reorder with care */
112 int n; /* Non-power-of-two part */
113 int m; /* Power-of-two part */
114 int inv; /* Is inverse */
116 uint64_t flags; /* Flags */
117 double scale; /* Scale */
119 FFTComplex *exptab; /* MDCT exptab */
120 FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
121 int *pfatab; /* Input/Output mapping for compound transforms */
122 int *revtab; /* Input mapping for power of two transforms */
123 int *inplace_idx; /* Required indices to revtab for in-place transforms */
125 int *revtab_c; /* Revtab for only the C transforms, needed because
126 * checkasm makes us reuse the same context. */
128 av_tx_fn top_tx; /* Used for computing transforms derived from other
129 * transforms, like full-length iMDCTs and RDFTs.
130 * NOTE: Do NOT use this to mix assembly with C code. */
133 /* Checks if type is an MDCT */
134 int ff_tx_type_is_mdct(enum AVTXType type);
137 * Generates the PFA permutation table into AVTXContext->pfatab. The end table
138 * is appended to the start table.
140 int ff_tx_gen_compound_mapping(AVTXContext *s);
143 * Generates a standard-ish (slightly modified) Split-Radix revtab into
144 * AVTXContext->revtab
146 int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup);
149 * Generates an index into AVTXContext->inplace_idx that if followed in the
150 * specific order, allows the revtab to be done in-place. AVTXContext->revtab
151 * must already exist.
153 int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s, int *revtab);
156 * This generates a parity-based revtab of length len and direction inv.
158 * Parity means even and odd complex numbers will be split, e.g. the even
159 * coefficients will come first, after which the odd coefficients will be
160 * placed. For example, a 4-point transform's coefficients after reordering:
161 * z[0].re, z[0].im, z[2].re, z[2].im, z[1].re, z[1].im, z[3].re, z[3].im
163 * The basis argument is the length of the largest non-composite transform
164 * supported, and also implies that the basis/2 transform is supported as well,
165 * as the split-radix algorithm requires it to be.
167 * The dual_stride argument indicates that both the basis, as well as the
168 * basis/2 transforms support doing two transforms at once, and the coefficients
169 * will be interleaved between each pair in a split-radix like so (stride == 2):
170 * tx1[0], tx1[2], tx2[0], tx2[2], tx1[1], tx1[3], tx2[1], tx2[3]
171 * A non-zero number switches this on, with the value indicating the stride
172 * (how many values of 1 transform to put first before switching to the other).
173 * Must be a power of two or 0. Must be less than the basis.
174 * Value will be clipped to the transform size, so for a basis of 16 and a
175 * dual_stride of 8, dual 8-point transforms will be laid out as if dual_stride
177 * Usually you'll set this to half the complex numbers that fit in a single
178 * register or 0. This allows to reuse SSE functions as dual-transform
179 * functions in AVX mode.
181 * If length is smaller than basis/2 this function will not do anything.
183 void ff_tx_gen_split_radix_parity_revtab(int *revtab, int len, int inv,
184 int basis, int dual_stride);
186 /* Templated init functions */
187 int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx,
188 enum AVTXType type, int inv, int len,
189 const void *scale, uint64_t flags);
190 int ff_tx_init_mdct_fft_double(AVTXContext *s, av_tx_fn *tx,
191 enum AVTXType type, int inv, int len,
192 const void *scale, uint64_t flags);
193 int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx,
194 enum AVTXType type, int inv, int len,
195 const void *scale, uint64_t flags);
197 typedef struct CosTabsInitOnce {
202 void ff_tx_init_float_x86(AVTXContext *s, av_tx_fn *tx);
204 #endif /* AVUTIL_TX_PRIV_H */