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
3232 av_tx_fn fn2;
3333
3434 ptrdiff_t stride;
35+ int len;
36+ int inv;
3537 } AVTXWrapper;
3638
3739 /* FFT */
@@ -129,33 +131,54 @@ av_cold void av_mdct_end(FFTContext *s) · 91 unmodified lines
129131 }
130132 }
131133
132−#if CONFIG_RDFT
133−
134134 RDFTContext *av_rdft_init(int nbits, enum RDFTransformType trans)
135135 {
136− RDFTContext *s = av_malloc(sizeof(*s));
136+ int ret;
137+ float scale = trans == IDFT_C2R ? 0.5f : 1.0f;
138+ AVTXWrapper *s;
137139
138− if (s && ff_rdft_init(s, nbits, trans))
139− av_freep(&s);
140+ /* The other 2 modes are unconventional, do not form an orthogonal
141+ * transform, have never been useful, and so they're not implemented. */
142+ if (trans != IDFT_C2R && trans != DFT_R2C)
143+ return NULL;
140144
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;
142161 }
143162
144163 void av_rdft_calc(RDFTContext *s, FFTSample *data)
145164 {
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]);
147171 }
148172
149173 av_cold void av_rdft_end(RDFTContext *s)
150174 {
151175 if (s) {
152− ff_rdft_end(s);
153− av_free(s);
176+ AVTXWrapper *w = (AVTXWrapper *)s;
177+ av_tx_uninit(&w->ctx);
178+ av_free(w);
154179 }
155180 }
156181
157−#endif /* CONFIG_RDFT */
158−
159182 #if CONFIG_DCT
160183
161184 DCTContext *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