| @@ -24,7 +24,7 @@ · 23 unmodified lines |
| 24 | 24 | #include "libavutil/avstring.h" |
| 25 | 25 | #include "libavutil/channel_layout.h" |
| 26 | 26 | #include "libavutil/opt.h" |
| 27 | | −#include "libavcodec/avfft.h" |
| 27 | +#include "libavutil/tx.h" |
| 28 | 28 | #include "avfilter.h" |
| 29 | 29 | #include "audio.h" |
| 30 | 30 | #include "formats.h" |
| @@ -66,8 +66,10 @@ typedef struct DeNoiseChannel { · 35 unmodified lines |
| 66 | 66 | double *abs_var; |
| 67 | 67 | double *rel_var; |
| 68 | 68 | double *min_abs_var; |
| 69 | | − FFTComplex *fft_data; |
| 70 | | − FFTContext *fft, *ifft; |
| 69 | + AVComplexFloat *fft_in; |
| 70 | + AVComplexFloat *fft_out; |
| 71 | + AVTXContext *fft, *ifft; |
| 72 | + av_tx_fn tx_fn, itx_fn; |
| 71 | 73 | |
| 72 | 74 | double noise_band_norm[15]; |
| 73 | 75 | double noise_band_avr[15]; |
| @@ -290,7 +292,7 @@ static double limit_gain(double a, double b) · 216 unmodified lines |
| 290 | 292 | } |
| 291 | 293 | |
| 292 | 294 | static void process_frame(AudioFFTDeNoiseContext *s, DeNoiseChannel *dnch, |
| 293 | | − FFTComplex *fft_data, |
| 295 | + AVComplexFloat *fft_data, |
| 294 | 296 | double *prior, double *prior_band_excit, int track_noise) |
| 295 | 297 | { |
| 296 | 298 | double d1, d2, d3, gain; |
| @@ -612,7 +614,7 @@ static int config_input(AVFilterLink *inlink) · 315 unmodified lines |
| 612 | 614 | AVFilterContext *ctx = inlink->dst; |
| 613 | 615 | AudioFFTDeNoiseContext *s = ctx->priv; |
| 614 | 616 | double wscale, sar, sum, sdiv; |
| 615 | | − int i, j, k, m, n; |
| 617 | + int i, j, k, m, n, ret; |
| 616 | 618 | |
| 617 | 619 | s->dnch = av_calloc(inlink->channels, sizeof(*s->dnch)); |
| 618 | 620 | if (!s->dnch) |
| @@ -680,6 +682,7 @@ static int config_input(AVFilterLink *inlink) · 61 unmodified lines |
| 680 | 682 | |
| 681 | 683 | for (int ch = 0; ch < inlink->channels; ch++) { |
| 682 | 684 | DeNoiseChannel *dnch = &s->dnch[ch]; |
| 685 | + float scale; |
| 683 | 686 | |
| 684 | 687 | switch (s->noise_type) { |
| 685 | 688 | case WHITE_NOISE: |
| @@ -727,9 +730,14 @@ static int config_input(AVFilterLink *inlink) · 41 unmodified lines |
| 727 | 730 | dnch->abs_var = av_calloc(s->bin_count, sizeof(*dnch->abs_var)); |
| 728 | 731 | dnch->rel_var = av_calloc(s->bin_count, sizeof(*dnch->rel_var)); |
| 729 | 732 | dnch->min_abs_var = av_calloc(s->bin_count, sizeof(*dnch->min_abs_var)); |
| 730 | | − dnch->fft_data = av_calloc(s->fft_length2 + 1, sizeof(*dnch->fft_data)); |
| 731 | | − dnch->fft = av_fft_init(av_log2(s->fft_length2), 0); |
| 732 | | − dnch->ifft = av_fft_init(av_log2(s->fft_length2), 1); |
| 733 | + dnch->fft_in = av_calloc(s->fft_length2 + 1, sizeof(*dnch->fft_in)); |
| 734 | + dnch->fft_out = av_calloc(s->fft_length2 + 1, sizeof(*dnch->fft_out)); |
| 735 | + ret = av_tx_init(&dnch->fft, &dnch->tx_fn, AV_TX_FLOAT_FFT, 0, s->fft_length2, &scale, 0); |
| 736 | + if (ret < 0) |
| 737 | + return ret; |
| 738 | + ret = av_tx_init(&dnch->ifft, &dnch->itx_fn, AV_TX_FLOAT_FFT, 1, s->fft_length2, &scale, 0); |
| 739 | + if (ret < 0) |
| 740 | + return ret; |
| 733 | 741 | dnch->spread_function = av_calloc(s->number_of_bands * s->number_of_bands, |
| 734 | 742 | sizeof(*dnch->spread_function)); |
| 735 | 743 | |
| @@ -742,7 +750,8 @@ static int config_input(AVFilterLink *inlink) · 6 unmodified lines |
| 742 | 750 | !dnch->clean_data || |
| 743 | 751 | !dnch->noisy_data || |
| 744 | 752 | !dnch->out_samples || |
| 745 | | − !dnch->fft_data || |
| 753 | + !dnch->fft_in || |
| 754 | + !dnch->fft_out || |
| 746 | 755 | !dnch->abs_var || |
| 747 | 756 | !dnch->rel_var || |
| 748 | 757 | !dnch->min_abs_var || |
| @@ -855,7 +864,7 @@ static int config_input(AVFilterLink *inlink) · 106 unmodified lines |
| 855 | 864 | return 0; |
| 856 | 865 | } |
| 857 | 866 | |
| 858 | | −static void preprocess(FFTComplex *in, int len) |
| 867 | +static void preprocess(AVComplexFloat *in, int len) |
| 859 | 868 | { |
| 860 | 869 | double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10; |
| 861 | 870 | int n, i, k; |
| @@ -888,7 +897,7 @@ static void preprocess(FFTComplex *in, int len) · 26 unmodified lines |
| 888 | 897 | in[0].im = d2 - in[0].im; |
| 889 | 898 | } |
| 890 | 899 | |
| 891 | | −static void postprocess(FFTComplex *in, int len) |
| 900 | +static void postprocess(AVComplexFloat *in, int len) |
| 892 | 901 | { |
| 893 | 902 | double d1, d2, d3, d4, d5, d6, d7, d8, d9, d10; |
| 894 | 903 | int n, i, k; |
| @@ -938,28 +947,27 @@ static void sample_noise_block(AudioFFTDeNoiseContext *s, · 43 unmodified lines |
| 938 | 947 | int edge, j, k, n, edgemax; |
| 939 | 948 | |
| 940 | 949 | for (int i = 0; i < s->window_length; i++) { |
| 941 | | − dnch->fft_data[i].re = s->window[i] * src[i] * (1LL << 24); |
| 942 | | − dnch->fft_data[i].im = 0.0; |
| 950 | + dnch->fft_in[i].re = s->window[i] * src[i] * (1LL << 24); |
| 951 | + dnch->fft_in[i].im = 0.0; |
| 943 | 952 | } |
| 944 | 953 | |
| 945 | 954 | for (int i = s->window_length; i < s->fft_length2; i++) { |
| 946 | | − dnch->fft_data[i].re = 0.0; |
| 947 | | − dnch->fft_data[i].im = 0.0; |
| 955 | + dnch->fft_in[i].re = 0.0; |
| 956 | + dnch->fft_in[i].im = 0.0; |
| 948 | 957 | } |
| 949 | 958 | |
| 950 | | − av_fft_permute(dnch->fft, dnch->fft_data); |
| 951 | | − av_fft_calc(dnch->fft, dnch->fft_data); |
| 959 | + dnch->tx_fn(dnch->fft, dnch->fft_out, dnch->fft_in, sizeof(float)); |
| 952 | 960 | |
| 953 | | − preprocess(dnch->fft_data, s->fft_length); |
| 961 | + preprocess(dnch->fft_out, s->fft_length); |
| 954 | 962 | |
| 955 | 963 | edge = s->noise_band_edge[0]; |
| 956 | 964 | j = edge; |
| 957 | 965 | k = 0; |
| 958 | 966 | n = j; |
| 959 | 967 | edgemax = fmin(s->fft_length2, s->noise_band_edge[15]); |
| 960 | | − dnch->fft_data[s->fft_length2].re = dnch->fft_data[0].im; |
| 961 | | − dnch->fft_data[0].im = 0.0; |
| 962 | | − dnch->fft_data[s->fft_length2].im = 0.0; |
| 968 | + dnch->fft_out[s->fft_length2].re = dnch->fft_out[0].im; |
| 969 | + dnch->fft_out[0].im = 0.0; |
| 970 | + dnch->fft_out[s->fft_length2].im = 0.0; |
| 963 | 971 | |
| 964 | 972 | for (int i = j; i <= edgemax; i++) { |
| 965 | 973 | if ((i == j) && (i < edgemax)) { |
| @@ -979,10 +987,10 @@ static void sample_noise_block(AudioFFTDeNoiseContext *s, · 13 unmodified lines |
| 979 | 987 | avr = 0.0; |
| 980 | 988 | avi = 0.0; |
| 981 | 989 | } |
| 982 | | − avr += dnch->fft_data[n].re; |
| 983 | | − avi += dnch->fft_data[n].im; |
| 984 | | − mag2 = dnch->fft_data[n].re * dnch->fft_data[n].re + |
| 985 | | − dnch->fft_data[n].im * dnch->fft_data[n].im; |
| 990 | + avr += dnch->fft_out[n].re; |
| 991 | + avi += dnch->fft_out[n].im; |
| 992 | + mag2 = dnch->fft_out[n].re * dnch->fft_out[n].re + |
| 993 | + dnch->fft_out[n].im * dnch->fft_out[n].im; |
| 986 | 994 | |
| 987 | 995 | mag2 = fmax(mag2, s->sample_floor); |
| 988 | 996 | |
| @@ -1107,30 +1115,28 @@ static int filter_channel(AVFilterContext *ctx, void *arg, int jobnr, int nb_job · 118 unmodified lines |
| 1107 | 1115 | } |
| 1108 | 1116 | |
| 1109 | 1117 | for (int m = 0; m < s->window_length; m++) { |
| 1110 | | − dnch->fft_data[m].re = s->window[m] * src[m] * (1LL << 24); |
| 1111 | | − dnch->fft_data[m].im = 0; |
| 1118 | + dnch->fft_in[m].re = s->window[m] * src[m] * (1LL << 24); |
| 1119 | + dnch->fft_in[m].im = 0; |
| 1112 | 1120 | } |
| 1113 | 1121 | |
| 1114 | 1122 | for (int m = s->window_length; m < s->fft_length2; m++) { |
| 1115 | | − dnch->fft_data[m].re = 0; |
| 1116 | | − dnch->fft_data[m].im = 0; |
| 1123 | + dnch->fft_in[m].re = 0; |
| 1124 | + dnch->fft_in[m].im = 0; |
| 1117 | 1125 | } |
| 1118 | 1126 | |
| 1119 | | − av_fft_permute(dnch->fft, dnch->fft_data); |
| 1120 | | − av_fft_calc(dnch->fft, dnch->fft_data); |
| 1127 | + dnch->tx_fn(dnch->fft, dnch->fft_out, dnch->fft_in, sizeof(float)); |
| 1121 | 1128 | |
| 1122 | | − preprocess(dnch->fft_data, s->fft_length); |
| 1123 | | − process_frame(s, dnch, dnch->fft_data, |
| 1129 | + preprocess(dnch->fft_out, s->fft_length); |
| 1130 | + process_frame(s, dnch, dnch->fft_out, |
| 1124 | 1131 | dnch->prior, |
| 1125 | 1132 | dnch->prior_band_excit, |
| 1126 | 1133 | s->track_noise); |
| 1127 | | − postprocess(dnch->fft_data, s->fft_length); |
| 1134 | + postprocess(dnch->fft_out, s->fft_length); |
| 1128 | 1135 | |
| 1129 | | − av_fft_permute(dnch->ifft, dnch->fft_data); |
| 1130 | | − av_fft_calc(dnch->ifft, dnch->fft_data); |
| 1136 | + dnch->itx_fn(dnch->ifft, dnch->fft_in, dnch->fft_out, sizeof(float)); |
| 1131 | 1137 | |
| 1132 | 1138 | for (int m = 0; m < s->window_length; m++) |
| 1133 | | − dst[m] += s->window[m] * dnch->fft_data[m].re / (1LL << 24); |
| 1139 | + dst[m] += s->window[m] * dnch->fft_in[m].re / (1LL << 24); |
| 1134 | 1140 | } |
| 1135 | 1141 | |
| 1136 | 1142 | return 0; |
| @@ -1330,11 +1336,10 @@ static av_cold void uninit(AVFilterContext *ctx) · 193 unmodified lines |
| 1330 | 1336 | av_freep(&dnch->abs_var); |
| 1331 | 1337 | av_freep(&dnch->rel_var); |
| 1332 | 1338 | av_freep(&dnch->min_abs_var); |
| 1333 | | − av_freep(&dnch->fft_data); |
| 1334 | | − av_fft_end(dnch->fft); |
| 1335 | | − dnch->fft = NULL; |
| 1336 | | − av_fft_end(dnch->ifft); |
| 1337 | | − dnch->ifft = NULL; |
| 1339 | + av_freep(&dnch->fft_in); |
| 1340 | + av_freep(&dnch->fft_out); |
| 1341 | + av_tx_uninit(&dnch->fft); |
| 1342 | + av_tx_uninit(&dnch->ifft); |
| 1338 | 1343 | } |
| 1339 | 1344 | av_freep(&s->dnch); |
| 1340 | 1345 | } |