FFmpeg
tx_priv.h
Go to the documentation of this file.
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 
19 #ifndef AVUTIL_TX_PRIV_H
20 #define AVUTIL_TX_PRIV_H
21 
22 #include "tx.h"
23 #include <stddef.h>
24 #include "thread.h"
25 #include "mem.h"
26 #include "mem_internal.h"
27 #include "avassert.h"
28 #include "attributes.h"
29 
30 #ifdef TX_FLOAT
31 #define TX_NAME(x) x ## _float
32 #define SCALE_TYPE float
33 typedef float FFTSample;
35 #elif defined(TX_DOUBLE)
36 #define TX_NAME(x) x ## _double
37 #define SCALE_TYPE double
38 typedef double FFTSample;
40 #elif defined(TX_INT32)
41 #define TX_NAME(x) x ## _int32
42 #define SCALE_TYPE float
43 typedef int32_t FFTSample;
45 #else
46 typedef void FFTComplex;
47 #endif
48 
49 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
50 
51 #define CMUL(dre, dim, are, aim, bre, bim) do { \
52  (dre) = (are) * (bre) - (aim) * (bim); \
53  (dim) = (are) * (bim) + (aim) * (bre); \
54  } while (0)
55 
56 #define SMUL(dre, dim, are, aim, bre, bim) do { \
57  (dre) = (are) * (bre) - (aim) * (bim); \
58  (dim) = (are) * (bim) - (aim) * (bre); \
59  } while (0)
60 
61 #define UNSCALE(x) (x)
62 #define RESCALE(x) (x)
63 
64 #define FOLD(a, b) ((a) + (b))
65 
66 #elif defined(TX_INT32)
67 
68 /* Properly rounds the result */
69 #define CMUL(dre, dim, are, aim, bre, bim) do { \
70  int64_t accu; \
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); \
77  } while (0)
78 
79 #define SMUL(dre, dim, are, aim, bre, bim) do { \
80  int64_t accu; \
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); \
87  } while (0)
88 
89 #define UNSCALE(x) ((double)x/2147483648.0)
90 #define RESCALE(x) (av_clip64(lrintf((x) * 2147483648.0), INT32_MIN, INT32_MAX))
91 
92 #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
93 
94 #endif
95 
96 #define BF(x, y, a, b) do { \
97  x = (a) - (b); \
98  y = (a) + (b); \
99  } while (0)
100 
101 #define CMUL3(c, a, b) \
102  CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
103 
104 #define COSTABLE(size) \
105  DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2]
106 
107 /* Used by asm, reorder with care */
108 struct AVTXContext {
109  int n; /* Non-power-of-two part */
110  int m; /* Power-of-two part */
111  int inv; /* Is inverse */
112  int type; /* Type */
113  uint64_t flags; /* Flags */
114  double scale; /* Scale */
115 
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 */
121 };
122 
123 /* Shared functions */
126 int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup);
128 
129 /* Also used by SIMD init */
130 static inline int split_radix_permutation(int i, int n, int inverse)
131 {
132  int m;
133  if (n <= 2)
134  return i & 1;
135  m = n >> 1;
136  if (!(i & m))
137  return split_radix_permutation(i, m, inverse)*2;
138  m >>= 1;
139  if (inverse == !(i & m))
140  return split_radix_permutation(i, m, inverse)*4 + 1;
141  else
142  return split_radix_permutation(i, m, inverse)*4 - 1;
143 }
144 
145 /* Templated functions */
147  enum AVTXType type, int inv, int len,
148  const void *scale, uint64_t flags);
150  enum AVTXType type, int inv, int len,
151  const void *scale, uint64_t flags);
153  enum AVTXType type, int inv, int len,
154  const void *scale, uint64_t flags);
155 
156 typedef struct CosTabsInitOnce {
157  void (*func)(void);
158  AVOnce control;
160 
161 #endif /* AVUTIL_TX_PRIV_H */
mem_internal.h
thread.h
AVTXContext::pfatab
int * pfatab
Definition: tx_priv.h:118
AVTXContext
Definition: tx_priv.h:108
AVComplexFloat
Definition: tx.h:27
AVTXContext::exptab
FFTComplex * exptab
Definition: tx_priv.h:116
CosTabsInitOnce::func
void(* func)(void)
Definition: fft_template.c:70
ff_tx_type_is_mdct
int ff_tx_type_is_mdct(enum AVTXType type)
Definition: tx.c:21
AVTXContext::revtab
int * revtab
Definition: tx_priv.h:119
type
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf type
Definition: writing_filters.txt:86
CosTabsInitOnce::control
AVOnce control
Definition: fft_template.c:71
avassert.h
av_tx_fn
void(* av_tx_fn)(AVTXContext *s, void *out, void *in, ptrdiff_t stride)
Function pointer to a function to perform the transform.
Definition: tx.h:99
AVComplexInt32
Definition: tx.h:35
ff_tx_init_mdct_fft_double
int ff_tx_init_mdct_fft_double(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
s
#define s(width, name)
Definition: cbs_vp9.c:257
AVTXContext::scale
double scale
Definition: tx_priv.h:114
int32_t
int32_t
Definition: audio_convert.c:194
ff_tx_init_mdct_fft_float
int ff_tx_init_mdct_fft_float(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
FFTSample
float FFTSample
Definition: avfft.h:35
AVOnce
#define AVOnce
Definition: thread.h:172
FFTComplex
void FFTComplex
Definition: tx_priv.h:46
AVTXType
AVTXType
Definition: tx.h:39
CosTabsInitOnce
Definition: fft_template.c:69
ff_tx_init_mdct_fft_int32
int ff_tx_init_mdct_fft_int32(AVTXContext *s, av_tx_fn *tx, enum AVTXType type, int inv, int len, const void *scale, uint64_t flags)
attributes.h
AVTXContext::inv
int inv
Definition: tx_priv.h:111
AVTXContext::inplace_idx
int * inplace_idx
Definition: tx_priv.h:120
i
int i
Definition: input.c:407
ff_tx_gen_ptwo_revtab
int ff_tx_gen_ptwo_revtab(AVTXContext *s, int invert_lookup)
Definition: tx.c:94
ff_tx_gen_ptwo_inplace_revtab_idx
int ff_tx_gen_ptwo_inplace_revtab_idx(AVTXContext *s)
Definition: tx.c:113
len
int len
Definition: vorbis_enc_data.h:452
ff_tx_gen_compound_mapping
int ff_tx_gen_compound_mapping(AVTXContext *s)
Definition: tx.c:44
AVComplexDouble
Definition: tx.h:31
AVTXContext::flags
uint64_t flags
Definition: tx_priv.h:113
mem.h
inverse
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
Definition: asfcrypt.c:35
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
split_radix_permutation
static int split_radix_permutation(int i, int n, int inverse)
Definition: tx_priv.h:130
AVTXContext::m
int m
Definition: tx_priv.h:110
AVTXContext::n
int n
Definition: tx_priv.h:109
AVTXContext::tmp
FFTComplex * tmp
Definition: tx_priv.h:117
FFTComplex
Definition: avfft.h:37
tx.h
AVTXContext::type
int type
Definition: tx_priv.h:112