diff mbox

[FFmpeg-devel] avfilter/firequalizer: use zero phase kernel

Message ID 1476890947-6613-1-git-send-email-mfcc64@gmail.com
State Accepted
Commit 258c49d61451236e28a34265195481ef8f00d968
Headers show

Commit Message

Muhammad Faiz Oct. 19, 2016, 3:29 p.m. UTC
this makes real-valued kernel

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
---
 libavfilter/af_firequalizer.c | 26 +++++++++++++++-----------
 1 file changed, 15 insertions(+), 11 deletions(-)

Comments

Muhammad Faiz Oct. 20, 2016, 7:23 a.m. UTC | #1
On 10/19/16, Muhammad Faiz <mfcc64@gmail.com> wrote:
> this makes real-valued kernel
>
> Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>
> ---
>  libavfilter/af_firequalizer.c | 26 +++++++++++++++-----------
>  1 file changed, 15 insertions(+), 11 deletions(-)

applied

thanks
diff mbox

Patch

diff --git a/libavfilter/af_firequalizer.c b/libavfilter/af_firequalizer.c
index e799e34..4988717 100644
--- a/libavfilter/af_firequalizer.c
+++ b/libavfilter/af_firequalizer.c
@@ -198,20 +198,19 @@  static void fast_convolute(FIREqualizerContext *s, const float *kernel_buf, floa
     if (nsamples <= s->nsamples_max) {
         float *buf = conv_buf + idx->buf_idx * s->rdft_len;
         float *obuf = conv_buf + !idx->buf_idx * s->rdft_len + idx->overlap_idx;
+        int center = s->fir_len/2;
         int k;
 
-        memcpy(buf, data, nsamples * sizeof(*data));
-        memset(buf + nsamples, 0, (s->rdft_len - nsamples) * sizeof(*data));
+        memset(buf, 0, center * sizeof(*data));
+        memcpy(buf + center, data, nsamples * sizeof(*data));
+        memset(buf + center + nsamples, 0, (s->rdft_len - nsamples - center) * sizeof(*data));
         av_rdft_calc(s->rdft, buf);
 
         buf[0] *= kernel_buf[0];
-        buf[1] *= kernel_buf[1];
-        for (k = 2; k < s->rdft_len; k += 2) {
-            float re, im;
-            re = buf[k] * kernel_buf[k] - buf[k+1] * kernel_buf[k+1];
-            im = buf[k] * kernel_buf[k+1] + buf[k+1] * kernel_buf[k];
-            buf[k] = re;
-            buf[k+1] = im;
+        buf[1] *= kernel_buf[s->rdft_len/2];
+        for (k = 1; k < s->rdft_len/2; k++) {
+            buf[2*k] *= kernel_buf[k];
+            buf[2*k+1] *= kernel_buf[k];
         }
 
         av_rdft_calc(s->irdft, buf);
@@ -534,8 +533,8 @@  static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
         }
 
         memset(s->analysis_buf + center + 1, 0, (s->analysis_rdft_len - s->fir_len) * sizeof(*s->analysis_buf));
-        memcpy(rdft_buf, s->analysis_buf + s->analysis_rdft_len - center, center * sizeof(*s->analysis_buf));
-        memcpy(rdft_buf + center, s->analysis_buf, (s->rdft_len - center) * sizeof(*s->analysis_buf));
+        memcpy(rdft_buf, s->analysis_buf, s->rdft_len/2 * sizeof(*s->analysis_buf));
+        memcpy(rdft_buf + s->rdft_len/2, s->analysis_buf + s->analysis_rdft_len - s->rdft_len/2, s->rdft_len/2 * sizeof(*s->analysis_buf));
         av_rdft_calc(s->rdft, rdft_buf);
 
         for (k = 0; k < s->rdft_len; k++) {
@@ -548,6 +547,11 @@  static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
             }
         }
 
+        rdft_buf[s->rdft_len-1] = rdft_buf[1];
+        for (k = 0; k < s->rdft_len/2; k++)
+            rdft_buf[k] = rdft_buf[2*k];
+        rdft_buf[s->rdft_len/2] = rdft_buf[s->rdft_len-1];
+
         if (dump_fp)
             dump_fir(ctx, dump_fp, ch);