FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
avfft.c
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 #include "libavutil/attributes.h"
20 #include "libavutil/mem.h"
21 #include "avfft.h"
22 #include "fft.h"
23 #include "rdft.h"
24 #include "dct.h"
25 
26 /* FFT */
27 
28 FFTContext *av_fft_init(int nbits, int inverse)
29 {
30  FFTContext *s = av_mallocz(sizeof(*s));
31 
32  if (s && ff_fft_init(s, nbits, inverse))
33  av_freep(&s);
34 
35  return s;
36 }
37 
39 {
40  s->fft_permute(s, z);
41 }
42 
44 {
45  s->fft_calc(s, z);
46 }
47 
49 {
50  if (s) {
51  ff_fft_end(s);
52  av_free(s);
53  }
54 }
55 
56 #if CONFIG_MDCT
57 
58 FFTContext *av_mdct_init(int nbits, int inverse, double scale)
59 {
60  FFTContext *s = av_malloc(sizeof(*s));
61 
62  if (s && ff_mdct_init(s, nbits, inverse, scale))
63  av_freep(&s);
64 
65  return s;
66 }
67 
68 void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
69 {
70  s->imdct_calc(s, output, input);
71 }
72 
73 void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
74 {
75  s->imdct_half(s, output, input);
76 }
77 
78 void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
79 {
80  s->mdct_calc(s, output, input);
81 }
82 
84 {
85  if (s) {
86  ff_mdct_end(s);
87  av_free(s);
88  }
89 }
90 
91 #endif /* CONFIG_MDCT */
92 
93 #if CONFIG_RDFT
94 
95 RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
96 {
97  RDFTContext *s = av_malloc(sizeof(*s));
98 
99  if (s && ff_rdft_init(s, nbits, trans))
100  av_freep(&s);
101 
102  return s;
103 }
104 
106 {
107  s->rdft_calc(s, data);
108 }
109 
111 {
112  if (s) {
113  ff_rdft_end(s);
114  av_free(s);
115  }
116 }
117 
118 #endif /* CONFIG_RDFT */
119 
120 #if CONFIG_DCT
121 
122 DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
123 {
124  DCTContext *s = av_malloc(sizeof(*s));
125 
126  if (s && ff_dct_init(s, nbits, inverse))
127  av_freep(&s);
128 
129  return s;
130 }
131 
132 void av_dct_calc(DCTContext *s, FFTSample *data)
133 {
134  s->dct_calc(s, data);
135 }
136 
138 {
139  if (s) {
140  ff_dct_end(s);
141  av_free(s);
142  }
143 }
144 
145 #endif /* CONFIG_DCT */
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:132
const char * s
Definition: avisynth_c.h:631
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
Definition: dct.h:37
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
av_cold void av_fft_end(FFTContext *s)
Definition: avfft.c:48
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:109
void av_mdct_end(FFTContext *s)
memory handling functions
FFTContext * av_mdct_init(int nbits, int inverse, double scale)
DCTContext * av_dct_init(int nbits, enum DCTTransformType type)
Set up DCT.
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
Definition: fft.h:101
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:38
Macro definitions for various function/variable attributes.
#define av_cold
Definition: attributes.h:82
#define av_malloc(s)
RDFTransformType
Definition: avfft.h:71
void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
DCTTransformType
Definition: avfft.h:93
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:28
#define ff_mdct_init
Definition: fft.h:169
float FFTSample
Definition: avfft.h:35
void(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:60
void av_rdft_calc(RDFTContext *s, FFTSample *data)
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:107
Definition: fft.h:88
#define ff_fft_init
Definition: fft.h:149
Definition: dct.h:31
void av_rdft_end(RDFTContext *s)
RDFTContext * av_rdft_init(int nbits, enum RDFTransformType trans)
Set up a real FFT.
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
FFT functions.
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:108
void av_dct_end(DCTContext *s)
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
Definition: dct.c:177
#define ff_mdct_end
Definition: fft.h:170
#define ff_fft_end
Definition: fft.h:150
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
Definition: fft.h:106
void av_dct_calc(DCTContext *s, FFTSample *data)
#define av_free(p)
av_cold void ff_dct_end(DCTContext *s)
Definition: dct.c:220
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
#define av_freep(p)
static uint32_t inverse(uint32_t v)
find multiplicative inverse modulo 2 ^ 32
Definition: asfcrypt.c:35
av_cold int ff_rdft_init(RDFTContext *s, int nbits, enum RDFTransformType trans)
Set up a real FFT.
Definition: rdft.c:99
void av_fft_calc(FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in av_fft_init().
Definition: avfft.c:43
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:252