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
26 #include "mem_internal.h"
28 #include "attributes.h"
31 #define TX_NAME(x) x ## _float
32 #define SCALE_TYPE float
33 typedef float FFTSample;
34 typedef AVComplexFloat FFTComplex;
35 #elif defined(TX_DOUBLE)
36 #define TX_NAME(x) x ## _double
37 #define SCALE_TYPE double
38 typedef double FFTSample;
39 typedef AVComplexDouble FFTComplex;
40 #elif defined(TX_INT32)
41 #define TX_NAME(x) x ## _int32
42 #define SCALE_TYPE float
43 typedef int32_t FFTSample;
44 typedef AVComplexInt32 FFTComplex;
46 typedef void FFTComplex;
49 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
51 #define CMUL(dre, dim, are, aim, bre, bim) do { \
52 (dre) = (are) * (bre) - (aim) * (bim); \
53 (dim) = (are) * (bim) + (aim) * (bre); \
56 #define SMUL(dre, dim, are, aim, bre, bim) do { \
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) do { \
71 (accu) = (int64_t)(bre) * (are); \
72 (accu) -= (int64_t)(bim) * (aim); \
73 (dre) = (int)(((accu) + 0x40000000) >> 31); \
74 (accu) = (int64_t)(bim) * (are); \
75 (accu) += (int64_t)(bre) * (aim); \
76 (dim) = (int)(((accu) + 0x40000000) >> 31); \
79 #define SMUL(dre, dim, are, aim, bre, bim) do { \
81 (accu) = (int64_t)(bre) * (are); \
82 (accu) -= (int64_t)(bim) * (aim); \
83 (dre) = (int)(((accu) + 0x40000000) >> 31); \
84 (accu) = (int64_t)(bim) * (are); \
85 (accu) -= (int64_t)(bre) * (aim); \
86 (dim) = (int)(((accu) + 0x40000000) >> 31); \
89 #define UNSCALE(x) ((double)x/2147483648.0)
90 #define RESCALE(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX))
92 #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
96 #define BF(x, y, a, b) do { \
101 #define CMUL3(c, a, b) \
102 CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
104 #define COSTABLE(size) \
105 DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2]
107 /* Used by asm, reorder with care */
109 int n; /* Non-power-of-two part */
110 int m; /* Power-of-two part */
111 int inv; /* Is inverse */
113 uint64_t flags; /* Flags */
114 double scale; /* Scale */
116 FFTComplex *exptab; /* MDCT exptab */
117 FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
118 int *pfatab; /* Input/Output mapping for compound transforms */
119 int *revtab; /* Input mapping for power of two transforms */
120 int *inplace_idx; /* Required indices to revtab for in-place transforms */
123 /* Shared functions */
124 int ff_tx_type_is_mdct(enum AVTXType type);
125 int ff_tx_gen_compound_mapping(AVTXContext *s);
126 int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup);
127 int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s);
129 /* Also used by SIMD init */
130 static inline int split_radix_permutation(int i, int n, int inverse)
137 return split_radix_permutation(i, m, inverse)*2;
139 if (inverse == !(i & m))
140 return split_radix_permutation(i, m, inverse)*4 + 1;
142 return split_radix_permutation(i, m, inverse)*4 - 1;
145 /* Templated functions */
146 int ff_tx_init_mdct_fft_float(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_double(AVTXContext *s, av_tx_fn *tx,
150 enum AVTXType type, int inv, int len,
151 const void *scale, uint64_t flags);
152 int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx,
153 enum AVTXType type, int inv, int len,
154 const void *scale, uint64_t flags);
156 typedef struct CosTabsInitOnce {
161 #endif /* AVUTIL_TX_PRIV_H */