Browse code

avfilter/firequalizer: use zero phase kernel

this makes real-valued kernel

Signed-off-by: Muhammad Faiz <mfcc64@gmail.com>

Muhammad Faiz authored on 2016/10/20 00:22:36
Showing 1 changed files
... ...
@@ -198,20 +198,19 @@ static void fast_convolute(FIREqualizerContext *s, const float *kernel_buf, floa
198 198
     if (nsamples <= s->nsamples_max) {
199 199
         float *buf = conv_buf + idx->buf_idx * s->rdft_len;
200 200
         float *obuf = conv_buf + !idx->buf_idx * s->rdft_len + idx->overlap_idx;
201
+        int center = s->fir_len/2;
201 202
         int k;
202 203
 
203
-        memcpy(buf, data, nsamples * sizeof(*data));
204
-        memset(buf + nsamples, 0, (s->rdft_len - nsamples) * sizeof(*data));
204
+        memset(buf, 0, center * sizeof(*data));
205
+        memcpy(buf + center, data, nsamples * sizeof(*data));
206
+        memset(buf + center + nsamples, 0, (s->rdft_len - nsamples - center) * sizeof(*data));
205 207
         av_rdft_calc(s->rdft, buf);
206 208
 
207 209
         buf[0] *= kernel_buf[0];
208
-        buf[1] *= kernel_buf[1];
209
-        for (k = 2; k < s->rdft_len; k += 2) {
210
-            float re, im;
211
-            re = buf[k] * kernel_buf[k] - buf[k+1] * kernel_buf[k+1];
212
-            im = buf[k] * kernel_buf[k+1] + buf[k+1] * kernel_buf[k];
213
-            buf[k] = re;
214
-            buf[k+1] = im;
210
+        buf[1] *= kernel_buf[s->rdft_len/2];
211
+        for (k = 1; k < s->rdft_len/2; k++) {
212
+            buf[2*k] *= kernel_buf[k];
213
+            buf[2*k+1] *= kernel_buf[k];
215 214
         }
216 215
 
217 216
         av_rdft_calc(s->irdft, buf);
... ...
@@ -534,8 +533,8 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
534 534
         }
535 535
 
536 536
         memset(s->analysis_buf + center + 1, 0, (s->analysis_rdft_len - s->fir_len) * sizeof(*s->analysis_buf));
537
-        memcpy(rdft_buf, s->analysis_buf + s->analysis_rdft_len - center, center * sizeof(*s->analysis_buf));
538
-        memcpy(rdft_buf + center, s->analysis_buf, (s->rdft_len - center) * sizeof(*s->analysis_buf));
537
+        memcpy(rdft_buf, s->analysis_buf, s->rdft_len/2 * sizeof(*s->analysis_buf));
538
+        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));
539 539
         av_rdft_calc(s->rdft, rdft_buf);
540 540
 
541 541
         for (k = 0; k < s->rdft_len; k++) {
... ...
@@ -548,6 +547,11 @@ static int generate_kernel(AVFilterContext *ctx, const char *gain, const char *g
548 548
             }
549 549
         }
550 550
 
551
+        rdft_buf[s->rdft_len-1] = rdft_buf[1];
552
+        for (k = 0; k < s->rdft_len/2; k++)
553
+            rdft_buf[k] = rdft_buf[2*k];
554
+        rdft_buf[s->rdft_len/2] = rdft_buf[s->rdft_len-1];
555
+
551 556
         if (dump_fp)
552 557
             dump_fir(ctx, dump_fp, ch);
553 558