FFmpeg
 All Data Structures 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/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 */