avfft.c
Go to the documentation of this file.
1 /*
2  * This file is part of Libav.
3  *
4  * Libav 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  * Libav 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 Libav; 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/mem.h"
20 #include "avfft.h"
21 #include "fft.h"
22 #include "rdft.h"
23 #include "dct.h"
24 
25 /* FFT */
26 
27 FFTContext *av_fft_init(int nbits, int inverse)
28 {
29  FFTContext *s = av_malloc(sizeof(*s));
30 
31  if (s && ff_fft_init(s, nbits, inverse))
32  av_freep(&s);
33 
34  return s;
35 }
36 
38 {
39  s->fft_permute(s, z);
40 }
41 
43 {
44  s->fft_calc(s, z);
45 }
46 
48 {
49  if (s) {
50  ff_fft_end(s);
51  av_free(s);
52  }
53 }
54 
55 #if CONFIG_MDCT
56 
57 FFTContext *av_mdct_init(int nbits, int inverse, double scale)
58 {
59  FFTContext *s = av_malloc(sizeof(*s));
60 
61  if (s && ff_mdct_init(s, nbits, inverse, scale))
62  av_freep(&s);
63 
64  return s;
65 }
66 
67 void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
68 {
69  s->imdct_calc(s, output, input);
70 }
71 
72 void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
73 {
74  s->imdct_half(s, output, input);
75 }
76 
77 void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
78 {
79  s->mdct_calc(s, output, input);
80 }
81 
82 void av_mdct_end(FFTContext *s)
83 {
84  if (s) {
85  ff_mdct_end(s);
86  av_free(s);
87  }
88 }
89 
90 #endif /* CONFIG_MDCT */
91 
92 #if CONFIG_RDFT
93 
94 RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
95 {
96  RDFTContext *s = av_malloc(sizeof(*s));
97 
98  if (s && ff_rdft_init(s, nbits, trans))
99  av_freep(&s);
100 
101  return s;
102 }
103 
105 {
106  s->rdft_calc(s, data);
107 }
108 
109 void av_rdft_end(RDFTContext *s)
110 {
111  if (s) {
112  ff_rdft_end(s);
113  av_free(s);
114  }
115 }
116 
117 #endif /* CONFIG_RDFT */
118 
119 #if CONFIG_DCT
120 
121 DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)
122 {
123  DCTContext *s = av_malloc(sizeof(*s));
124 
125  if (s && ff_dct_init(s, nbits, inverse))
126  av_freep(&s);
127 
128  return s;
129 }
130 
131 void av_dct_calc(DCTContext *s, FFTSample *data)
132 {
133  s->dct_calc(s, data);
134 }
135 
136 void av_dct_end(DCTContext *s)
137 {
138  if (s) {
139  ff_dct_end(s);
140  av_free(s);
141  }
142 }
143 
144 #endif /* CONFIG_DCT */
av_cold void ff_rdft_end(RDFTContext *s)
Definition: rdft.c:130
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:61
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
Definition: dct.h:35
void av_fft_end(FFTContext *s)
Definition: avfft.c:47
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:83
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:75
void av_fft_permute(FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling ff_fft_calc().
Definition: avfft.c:37
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:151
const char data[16]
Definition: mxf.c:66
RDFTransformType
Definition: avfft.h:71
void av_imdct_half(FFTContext *s, FFTSample *output, const FFTSample *input)
void av_free(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc(). ...
Definition: mem.c:139
DCTTransformType
Definition: avfft.h:93
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:27
#define ff_mdct_init
Definition: fft.h:146
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:81
Definition: fft.h:62
#define ff_fft_init
Definition: fft.h:126
Definition: dct.h:29
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:82
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
static const uint16_t scale[4]
#define ff_mdct_end
Definition: fft.h:147
#define ff_fft_end
Definition: fft.h:127
void(* fft_calc)(struct FFTContext *s, FFTComplex *z)
Do a complex FFT with the parameters defined in ff_fft_init().
Definition: fft.h:80
void av_dct_calc(DCTContext *s, FFTSample *data)
av_cold void ff_dct_end(DCTContext *s)
Definition: dct.c:218
void av_mdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
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:42