History

avfft: wrap lavu/tx instead of ff_rdft

Lynne committed 4 years ago

Commit 83ede011 parent 517e4fc1 file · +34 −11Browse files

Unified · Split

libavcodec/avfft.c+34−11
@@ -32,6 +32,8 @@ typedef struct AVTXWrapper { · 31 unmodified lines
32 av_tx_fn fn2;32 av_tx_fn fn2;
33 33
34 ptrdiff_t stride;34 ptrdiff_t stride;
35 int len;
36 int inv;
35} AVTXWrapper;37} AVTXWrapper;
36 38
37/* FFT */39/* FFT */
@@ -129,33 +131,54 @@ av_cold void av_mdct_end(FFTContext *s) · 91 unmodified lines
129 }131 }
130}132}
131 133
132#if CONFIG_RDFT
133
134RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)134RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
135{135{
136 RDFTContext *s = av_malloc(sizeof(*s));136 int ret;
137 float scale = trans == IDFT_C2R ? 0.5f : 1.0f;
138 AVTXWrapper *s;
137 139
138 if (s && ff_rdft_init(s, nbits, trans))140 /* The other 2 modes are unconventional, do not form an orthogonal
139 av_freep(&s);141 * transform, have never been useful, and so they're not implemented. */
142 if (trans != IDFT_C2R && trans != DFT_R2C)
143 return NULL;
140 144
141 return s;145 s = av_malloc(sizeof(*s));
146 if (!s)
147 return NULL;
148
149 ret = av_tx_init(&s->ctx, &s->fn, AV_TX_FLOAT_RDFT, trans == IDFT_C2R,
150 1 << nbits, &scale, AV_TX_INPLACE);
151 if (ret < 0) {
152 av_free(s);
153 return NULL;
154 }
155
156 s->stride = (trans == DFT_C2R) ? sizeof(float) : sizeof(AVComplexFloat);
157 s->len = 1 << nbits;
158 s->inv = trans == IDFT_C2R;
159
160 return (RDFTContext *)s;
142}161}
143 162
144void av_rdft_calc(RDFTContext *s, FFTSample *data)163void av_rdft_calc(RDFTContext *s, FFTSample *data)
145{164{
146 s->rdft_calc(s, data);165 AVTXWrapper *w = (AVTXWrapper *)s;
166 if (w->inv)
167 FFSWAP(float, data[1], data[w->len]);
168 w->fn(w->ctx, data, (void *)data, w->stride);
169 if (!w->inv)
170 FFSWAP(float, data[1], data[w->len]);
147}171}
148 172
149av_cold void av_rdft_end(RDFTContext *s)173av_cold void av_rdft_end(RDFTContext *s)
150{174{
151 if (s) {175 if (s) {
152 ff_rdft_end(s);176 AVTXWrapper *w = (AVTXWrapper *)s;
153 av_free(s);177 av_tx_uninit(&w->ctx);
178 av_free(w);
154 }179 }
155}180}
156 181
157#endif /* CONFIG_RDFT */
158
159#if CONFIG_DCT182#if CONFIG_DCT
160 183
161DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)184DCTContext *av_dct_init(int nbits, enum DCTTransformType inverse)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t