Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/FFmpeg/FFmpeg.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMuhammad Faiz <mfcc64@gmail.com>2015-09-14 12:23:58 +0300
committerMichael Niedermayer <michael@niedermayer.cc>2015-09-14 13:51:43 +0300
commit145c5a99783c750f169d366db971dbde2244fd7f (patch)
tree3855929e30de27943e1ba5137bcb08069f1b41fe /libavfilter/avf_showcqt.c
parentd13a2df8de6238a54fb2c41a43c03ec422b12463 (diff)
avfilter/avf_showcqt: change fft left-right separation
This simplifies the code Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
Diffstat (limited to 'libavfilter/avf_showcqt.c')
-rw-r--r--libavfilter/avf_showcqt.c56
1 files changed, 21 insertions, 35 deletions
diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index 472520cb1e..8f06752530 100644
--- a/libavfilter/avf_showcqt.c
+++ b/libavfilter/avf_showcqt.c
@@ -68,8 +68,7 @@ typedef struct {
AVFrame *outpicref;
FFTContext *fft_context;
FFTComplex *fft_data;
- FFTComplex *fft_result_left;
- FFTComplex *fft_result_right;
+ FFTComplex *fft_result;
uint8_t *spectogram;
SparseCoeff *coeff_sort;
SparseCoeff *coeffs[VIDEO_WIDTH];
@@ -125,8 +124,7 @@ static av_cold void uninit(AVFilterContext *ctx)
for (k = 0; k < VIDEO_WIDTH; k++)
av_freep(&s->coeffs[k]);
av_freep(&s->fft_data);
- av_freep(&s->fft_result_left);
- av_freep(&s->fft_result_right);
+ av_freep(&s->fft_result);
av_freep(&s->coeff_sort);
av_freep(&s->spectogram);
av_freep(&s->font_alpha);
@@ -345,11 +343,10 @@ static int config_output(AVFilterLink *outlink)
s->fft_data = av_malloc_array(fft_len, sizeof(*s->fft_data));
s->coeff_sort = av_malloc_array(fft_len, sizeof(*s->coeff_sort));
- s->fft_result_left = av_malloc_array(fft_len, sizeof(*s->fft_result_left));
- s->fft_result_right = av_malloc_array(fft_len, sizeof(*s->fft_result_right));
+ s->fft_result = av_malloc_array(fft_len + 1, sizeof(*s->fft_result));
s->fft_context = av_fft_init(s->fft_bits, 0);
- if (!s->fft_data || !s->coeff_sort || !s->fft_result_left || !s->fft_result_right || !s->fft_context)
+ if (!s->fft_data || !s->coeff_sort || !s->fft_result || !s->fft_context)
return AVERROR(ENOMEM);
#if CONFIG_LIBFREETYPE
@@ -541,43 +538,32 @@ static int plot_cqt(AVFilterLink *inlink)
int font_height = (FONT_HEIGHT/2) * video_scale;
/* real part contains left samples, imaginary part contains right samples */
- memcpy(s->fft_result_left, s->fft_data, fft_len * sizeof(*s->fft_data));
- av_fft_permute(s->fft_context, s->fft_result_left);
- av_fft_calc(s->fft_context, s->fft_result_left);
-
- /* separate left and right, (and multiply by 2.0) */
- s->fft_result_right[0].re = 2.0f * s->fft_result_left[0].im;
- s->fft_result_right[0].im = 0;
- s->fft_result_left[0].re = 2.0f * s->fft_result_left[0].re;
- s->fft_result_left[0].im = 0;
- for (x = 1; x <= fft_len >> 1; x++) {
- FFTSample tmpy = s->fft_result_left[fft_len-x].im - s->fft_result_left[x].im;
-
- s->fft_result_right[x].re = s->fft_result_left[x].im + s->fft_result_left[fft_len-x].im;
- s->fft_result_right[x].im = s->fft_result_left[x].re - s->fft_result_left[fft_len-x].re;
- s->fft_result_right[fft_len-x].re = s->fft_result_right[x].re;
- s->fft_result_right[fft_len-x].im = -s->fft_result_right[x].im;
-
- s->fft_result_left[x].re = s->fft_result_left[x].re + s->fft_result_left[fft_len-x].re;
- s->fft_result_left[x].im = tmpy;
- s->fft_result_left[fft_len-x].re = s->fft_result_left[x].re;
- s->fft_result_left[fft_len-x].im = -s->fft_result_left[x].im;
- }
+ memcpy(s->fft_result, s->fft_data, fft_len * sizeof(*s->fft_data));
+ av_fft_permute(s->fft_context, s->fft_result);
+ av_fft_calc(s->fft_context, s->fft_result);
+ s->fft_result[fft_len] = s->fft_result[0];
/* calculating cqt */
for (x = 0; x < VIDEO_WIDTH; x++) {
int u;
- FFTComplex l = {0,0};
- FFTComplex r = {0,0};
+ FFTComplex v = {0,0};
+ FFTComplex w = {0,0};
+ FFTComplex l, r;
for (u = 0; u < s->coeffs_len[x]; u++) {
FFTSample value = s->coeffs[x][u].value;
int index = s->coeffs[x][u].index;
- l.re += value * s->fft_result_left[index].re;
- l.im += value * s->fft_result_left[index].im;
- r.re += value * s->fft_result_right[index].re;
- r.im += value * s->fft_result_right[index].im;
+ v.re += value * s->fft_result[index].re;
+ v.im += value * s->fft_result[index].im;
+ w.re += value * s->fft_result[fft_len - index].re;
+ w.im += value * s->fft_result[fft_len - index].im;
}
+
+ /* separate left and right, (and multiply by 2.0) */
+ l.re = v.re + w.re;
+ l.im = v.im - w.im;
+ r.re = w.im + v.im;
+ r.im = w.re - v.re;
/* result is power, not amplitude */
result[x][0] = l.re * l.re + l.im * l.im;
result[x][2] = r.re * r.re + r.im * r.im;