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 "avassert.h"
27 #include "attributes.h"
28 
29 #ifdef TX_FLOAT
30 #define TX_NAME(x) x ## _float
31 #define SCALE_TYPE float
32 typedef float FFTSample;
34 #elif defined(TX_DOUBLE)
35 #define TX_NAME(x) x ## _double
36 #define SCALE_TYPE double
37 typedef double FFTSample;
39 #elif defined(TX_INT32)
40 #define TX_NAME(x) x ## _int32
41 #define SCALE_TYPE float
42 typedef int32_t FFTSample;
44 #else
45 typedef void FFTComplex;
46 #endif
47 
48 #if defined(TX_FLOAT) || defined(TX_DOUBLE)
49 
50 #define CMUL(dre, dim, are, aim, bre, bim) do { \
51  (dre) = (are) * (bre) - (aim) * (bim); \
52  (dim) = (are) * (bim) + (aim) * (bre); \
53  } while (0)
54 
55 #define SMUL(dre, dim, are, aim, bre, bim) do { \
56  (dre) = (are) * (bre) - (aim) * (bim); \
57  (dim) = (are) * (bim) - (aim) * (bre); \
58  } while (0)
59 
60 #define RESCALE(x) (x)
61 
62 #define FOLD(a, b) ((a) + (b))
63 
64 #elif defined(TX_INT32)
65 
66 /* Properly rounds the result */
67 #define CMUL(dre, dim, are, aim, bre, bim) do { \
68  int64_t accu; \
69  (accu) = (int64_t)(bre) * (are); \
70  (accu) -= (int64_t)(bim) * (aim); \
71  (dre) = (int)(((accu) + 0x40000000) >> 31); \
72  (accu) = (int64_t)(bim) * (are); \
73  (accu) += (int64_t)(bre) * (aim); \
74  (dim) = (int)(((accu) + 0x40000000) >> 31); \
75  } while (0)
76 
77 #define SMUL(dre, dim, are, aim, bre, bim) do { \
78  int64_t accu; \
79  (accu) = (int64_t)(bre) * (are); \
80  (accu) -= (int64_t)(bim) * (aim); \
81  (dre) = (int)(((accu) + 0x40000000) >> 31); \
82  (accu) = (int64_t)(bim) * (are); \
83  (accu) -= (int64_t)(bre) * (aim); \
84  (dim) = (int)(((accu) + 0x40000000) >> 31); \
85  } while (0)
86 
87 #define RESCALE(x) (lrintf((x) * 2147483648.0))
88 
89 #define FOLD(x, y) ((int)((x) + (unsigned)(y) + 32) >> 6)
90 
91 #endif
92 
93 #define BF(x, y, a, b) do { \
94  x = (a) - (b); \
95  y = (a) + (b); \
96  } while (0)
97 
98 #define CMUL3(c, a, b) \
99  CMUL((c).re, (c).im, (a).re, (a).im, (b).re, (b).im)
100 
101 #define COSTABLE(size) \
102  DECLARE_ALIGNED(32, FFTSample, TX_NAME(ff_cos_##size))[size/2]
103 
104 /* Used by asm, reorder with care */
105 struct AVTXContext {
106  int n; /* Nptwo part */
107  int m; /* Ptwo part */
108  int inv; /* Is inverted */
109  int type; /* Type */
110 
111  FFTComplex *exptab; /* MDCT exptab */
112  FFTComplex *tmp; /* Temporary buffer needed for all compound transforms */
113  int *pfatab; /* Input/Output mapping for compound transforms */
114  int *revtab; /* Input mapping for power of two transforms */
115 };
116 
117 /* Shared functions */
121 
122 /* Also used by SIMD init */
123 static inline int split_radix_permutation(int i, int n, int inverse)
124 {
125  int m;
126  if (n <= 2)
127  return i & 1;
128  m = n >> 1;
129  if (!(i & m))
130  return split_radix_permutation(i, m, inverse)*2;
131  m >>= 1;
132  if (inverse == !(i & m))
133  return split_radix_permutation(i, m, inverse)*4 + 1;
134  else
135  return split_radix_permutation(i, m, inverse)*4 - 1;
136 }
137 
138 /* Templated functions */
140  enum AVTXType type, int inv, int len,
141  const void *scale, uint64_t flags);
143  enum AVTXType type, int inv, int len,
144  const void *scale, uint64_t flags);
146  enum AVTXType type, int inv, int len,
147  const void *scale, uint64_t flags);
148 
149 typedef struct CosTabsInitOnce {
150  void (*func)(void);
151  AVOnce control;
153 
154 #endif /* AVUTIL_TX_PRIV_H */
thread.h
AVTXContext::pfatab
int * pfatab
Definition: tx_priv.h:113
AVTXContext
Definition: tx_priv.h:105
AVComplexFloat
Definition: tx.h:27
AVTXContext::exptab
FFTComplex * exptab
Definition: tx_priv.h:111
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:114
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:92
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
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:45
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:108
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
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
ff_tx_gen_ptwo_revtab
int ff_tx_gen_ptwo_revtab(AVTXContext *s)
Definition: tx.c:94
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:565
split_radix_permutation
static int split_radix_permutation(int i, int n, int inverse)
Definition: tx_priv.h:123
AVTXContext::m
int m
Definition: tx_priv.h:107
AVTXContext::n
int n
Definition: tx_priv.h:106
AVTXContext::tmp
FFTComplex * tmp
Definition: tx_priv.h:112
FFTComplex
Definition: avfft.h:37
tx.h
AVTXContext::type
int type
Definition: tx_priv.h:109