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 
68 {
69  s->imdct_calc(s, output, input);
70 }
71 
73 {
74  s->imdct_half(s, output, input);
75 }
76 
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 
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 
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
const char * s
Definition: avisynth_c.h:668
void av_fft_end(FFTContext *s)
Definition: avfft.c:47
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 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:198
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:183
DCTTransformType
Definition: avfft.h:93
void(* fft_permute)(struct FFTContext *s, FFTComplex *z)
Do the permutation needed BEFORE calling fft_calc().
Definition: fft.h:75
Spectrum Plot time data
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame This method is called when a frame is wanted on an output For an input
void(* mdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:83
FFTContext * av_fft_init(int nbits, int inverse)
Set up a complex FFT.
Definition: avfft.c:27
void(* imdct_calc)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:81
#define ff_mdct_init
Definition: fft.h:147
float FFTSample
Definition: avfft.h:35
void av_rdft_calc(RDFTContext *s, FFTSample *data)
Definition: fft.h:62
void(* dct_calc)(struct DCTContext *s, FFTSample *data)
Definition: dct.h:37
#define ff_fft_init
Definition: fft.h:126
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(* rdft_calc)(struct RDFTContext *s, FFTSample *z)
Definition: rdft.h:60
void av_imdct_calc(FFTContext *s, FFTSample *output, const FFTSample *input)
FFT functions.
void av_dct_end(DCTContext *s)
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:73
av_cold int ff_dct_init(DCTContext *s, int nbits, enum DCTTransformType inverse)
Set up DCT.
Definition: dct.c:177
void(* imdct_half)(struct FFTContext *s, FFTSample *output, const FFTSample *input)
Definition: fft.h:82
#define ff_mdct_end
Definition: fft.h:148
#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
these buffered frames must be flushed immediately if a new input produces new output(Example:frame rate-doubling filter:filter_frame must(1) flush the second copy of the previous frame, if it is still there,(2) push the first copy of the incoming frame,(3) keep the second copy for later.) If the input frame is not enough to produce output
Same thing on a dB scale
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