History

avfilter/avf_showcqt: switch to TX FFT from avutil

Paul B Mahol committed 5 years ago

Commit 0068b3d1 parent 925d41e4 files · +29 −27Browse files

Showing the changes to libavfilter (3 of 4 files). Show all

Unified · Split

3 files
  1. libavfilter/avf_showcqt.c +17 −16
  2. libavfilter/avf_showcqt.h +9 −7
  3. libavfilter/x86/avf_showcqt_init.c +1 −1
libavfilter/avf_showcqt.c+17−16
@@ -19,7 +19,7 @@ · 18 unmodified lines
1919 */
2020
2121 #include "config.h"
22−#include "libavcodec/avfft.h"
22+#include "libavutil/tx.h"
2323 #include "libavutil/channel_layout.h"
2424 #include "libavutil/opt.h"
2525 #include "libavutil/xga_font_data.h"
@@ -144,13 +144,13 @@ static void common_uninit(ShowCQTContext *s) · 118 unmodified lines
144144
145145 av_frame_free(&s->axis_frame);
146146 av_frame_free(&s->sono_frame);
147− av_fft_end(s->fft_ctx);
148− s->fft_ctx = NULL;
147+ av_tx_uninit(&s->fft_ctx);
149148 if (s->coeffs)
150149 for (k = 0; k < s->cqt_len; k++)
151150 av_freep(&s->coeffs[k].val);
152151 av_freep(&s->coeffs);
153152 av_freep(&s->fft_data);
153+ av_freep(&s->fft_input);
154154 av_freep(&s->fft_result);
155155 av_freep(&s->cqt_result);
156156 av_freep(&s->attack_data);
@@ -267,15 +267,15 @@ error: · 110 unmodified lines
267267 return ret;
268268 }
269269
270−static void cqt_calc(FFTComplex *dst, const FFTComplex *src, const Coeffs *coeffs,
270+static void cqt_calc(AVComplexFloat *dst, const AVComplexFloat *src, const Coeffs *coeffs,
271271 int len, int fft_len)
272272 {
273273 int k, x, i, j;
274274 for (k = 0; k < len; k++) {
275− FFTComplex l, r, a = {0,0}, b = {0,0};
275+ AVComplexFloat l, r, a = {0,0}, b = {0,0};
276276
277277 for (x = 0; x < coeffs[k].len; x++) {
278− FFTSample u = coeffs[k].val[x];
278+ float u = coeffs[k].val[x];
279279 i = coeffs[k].start + x;
280280 j = fft_len - i;
281281 a.re += u * src[i].re;
@@ -730,7 +730,7 @@ static float calculate_gamma(float v, float g) · 448 unmodified lines
730730 return expf(logf(v) / g);
731731 }
732732
733−static void rgb_from_cqt(ColorFloat *c, const FFTComplex *v, float g, int len, float cscheme[6])
733+static void rgb_from_cqt(ColorFloat *c, const AVComplexFloat *v, float g, int len, float cscheme[6])
734734 {
735735 int x;
736736 for (x = 0; x < len; x++) {
@@ -740,7 +740,7 @@ static void rgb_from_cqt(ColorFloat *c, const FFTComplex *v, float g, int len, f · 3 unmodified lines
740740 }
741741 }
742742
743−static void yuv_from_cqt(ColorFloat *c, const FFTComplex *v, float gamma, int len, float cm[3][3], float cscheme[6])
743+static void yuv_from_cqt(ColorFloat *c, const AVComplexFloat *v, float gamma, int len, float cm[3][3], float cscheme[6])
744744 {
745745 int x;
746746 for (x = 0; x < len; x++) {
@@ -1110,7 +1110,7 @@ static void process_cqt(ShowCQTContext *s) · 363 unmodified lines
11101110 if (s->fcount > 1) {
11111111 float rcp_fcount = 1.0f / s->fcount;
11121112 for (x = 0; x < s->width; x++) {
1113− FFTComplex result = {0.0f, 0.0f};
1113+ AVComplexFloat result = {0.0f, 0.0f};
11141114 for (i = 0; i < s->fcount; i++) {
11151115 result.re += s->cqt_result[s->fcount * x + i].re;
11161116 result.im += s->cqt_result[s->fcount * x + i].im;
@@ -1139,17 +1139,16 @@ static int plot_cqt(AVFilterContext *ctx, AVFrame **frameout) · 22 unmodified lines
11391139
11401140 last_time = av_gettime_relative();
11411141
1142− memcpy(s->fft_result, s->fft_data, s->fft_len * sizeof(*s->fft_data));
1142+ memcpy(s->fft_input, s->fft_data, s->fft_len * sizeof(*s->fft_data));
11431143 if (s->attack_data) {
11441144 int k;
11451145 for (k = 0; k < s->remaining_fill_max; k++) {
1146− s->fft_result[s->fft_len/2+k].re *= s->attack_data[k];
1147− s->fft_result[s->fft_len/2+k].im *= s->attack_data[k];
1146+ s->fft_input[s->fft_len/2+k].re *= s->attack_data[k];
1147+ s->fft_input[s->fft_len/2+k].im *= s->attack_data[k];
11481148 }
11491149 }
11501150
1151− av_fft_permute(s->fft_ctx, s->fft_result);
1152− av_fft_calc(s->fft_ctx, s->fft_result);
1151+ s->tx_fn(s->fft_ctx, s->fft_result, s->fft_input, sizeof(float));
11531152 s->fft_result[s->fft_len] = s->fft_result[0];
11541153 UPDATE_TIME(s->fft_time);
11551154
@@ -1355,6 +1354,7 @@ static int config_output(AVFilterLink *outlink) · 199 unmodified lines
13551354 AVFilterContext *ctx = outlink->src;
13561355 AVFilterLink *inlink = ctx->inputs[0];
13571356 ShowCQTContext *s = ctx->priv;
1357+ float scale;
13581358 int ret;
13591359
13601360 common_uninit(s);
@@ -1380,9 +1380,10 @@ static int config_output(AVFilterLink *outlink) · 19 unmodified lines
13801380 s->fft_len = 1 << s->fft_bits;
13811381 av_log(ctx, AV_LOG_INFO, "fft_len = %d, cqt_len = %d.\n", s->fft_len, s->cqt_len);
13821382
1383− s->fft_ctx = av_fft_init(s->fft_bits, 0);
1383+ ret = av_tx_init(&s->fft_ctx, &s->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_len, &scale, 0);
13841384 s->fft_data = av_calloc(s->fft_len, sizeof(*s->fft_data));
1385− s->fft_result = av_calloc(s->fft_len + 64, sizeof(*s->fft_result));
1385+ s->fft_input = av_calloc(FFALIGN(s->fft_len + 64, 256), sizeof(*s->fft_input));
1386+ s->fft_result = av_calloc(FFALIGN(s->fft_len + 64, 256), sizeof(*s->fft_result));
13861387 s->cqt_result = av_malloc_array(s->cqt_len, sizeof(*s->cqt_result));
13871388 if (!s->fft_ctx || !s->fft_data || !s->fft_result || !s->cqt_result)
13881389 return AVERROR(ENOMEM);
libavfilter/avf_showcqt.h+9−7
@@ -21,12 +21,12 @@ · 20 unmodified lines
2121 #ifndef AVFILTER_SHOWCQT_H
2222 #define AVFILTER_SHOWCQT_H
2323
24−#include "libavcodec/avfft.h"
24+#include "libavutil/tx.h"
2525 #include "avfilter.h"
2626 #include "internal.h"
2727
2828 typedef struct Coeffs {
29− FFTSample *val;
29+ float *val;
3030 int start, len;
3131 } Coeffs;
3232
@@ -58,11 +58,13 @@ typedef struct ShowCQTContext { · 25 unmodified lines
5858 int remaining_fill_max;
5959 int64_t next_pts;
6060 double *freq;
61− FFTContext *fft_ctx;
61+ AVTXContext *fft_ctx;
62+ av_tx_fn tx_fn;
6263 Coeffs *coeffs;
63− FFTComplex *fft_data;
64− FFTComplex *fft_result;
65− FFTComplex *cqt_result;
64+ AVComplexFloat *fft_data;
65+ AVComplexFloat *fft_input;
66+ AVComplexFloat *fft_result;
67+ AVComplexFloat *cqt_result;
6668 float *attack_data;
6769 int fft_bits;
6870 int fft_len;
@@ -76,7 +78,7 @@ typedef struct ShowCQTContext { · 7 unmodified lines
7678 float cmatrix[3][3];
7779 float cscheme_v[6];
7880 /* callback */
79− void (*cqt_calc)(FFTComplex *dst, const FFTComplex *src, const Coeffs *coeffs,
81+ void (*cqt_calc)(AVComplexFloat *dst, const AVComplexFloat *src, const Coeffs *coeffs,
8082 int len, int fft_len);
8183 void (*permute_coeffs)(float *v, int len);
8284 void (*draw_bar)(AVFrame *out, const float *h, const float *rcp_h,
libavfilter/x86/avf_showcqt_init.c+1−1
@@ -24,7 +24,7 @@ · 23 unmodified lines
2424 #include "libavfilter/avf_showcqt.h"
2525
2626 #define DECLARE_CQT_CALC(type) \
27−void ff_showcqt_cqt_calc_##type(FFTComplex *dst, const FFTComplex *src, \
27+void ff_showcqt_cqt_calc_##type(AVComplexFloat *dst, const AVComplexFloat *src, \
2828 const Coeffs *coeffs, int len, int fft_len)
2929
3030 DECLARE_CQT_CALC(sse);

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