ffmpeg | branch: master | Muhammad Faiz <mfc...@gmail.com> | Mon Sep 14 
16:23:58 2015 +0700| [145c5a99783c750f169d366db971dbde2244fd7f] | committer: 
Michael Niedermayer

avfilter/avf_showcqt: change fft left-right separation

This simplifies the code

Signed-off-by: Michael Niedermayer <mich...@niedermayer.cc>

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=145c5a99783c750f169d366db971dbde2244fd7f
---

 libavfilter/avf_showcqt.c |   56 +++++++++++++++++----------------------------
 1 file changed, 21 insertions(+), 35 deletions(-)

diff --git a/libavfilter/avf_showcqt.c b/libavfilter/avf_showcqt.c
index 472520c..8f06752 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;

_______________________________________________
ffmpeg-cvslog mailing list
ffmpeg-cvslog@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-cvslog

Reply via email to