diff mbox series

[FFmpeg-devel,v2,3/5] ac3enc: halve the MDCT window size by using vector_fmul_reverse

Message ID MQrnJPj--3-2@lynne.ee
State New
Headers show
Series [FFmpeg-devel,v2,1/5] ac3enc_fixed: convert to 32-bit sample format
Related show

Checks

Context Check Description
andriy/x86_make success Make finished
andriy/x86_make_fate success Make fate finished
andriy/PPC64_make success Make finished
andriy/PPC64_make_fate success Make fate finished

Commit Message

Lynne Jan. 12, 2021, 6:13 p.m. UTC
This brings the encoder in-line with the rest of ours and saves 
on a bit of memory.

Patch attached.
Subject: [PATCH v2 3/5] ac3enc: halve the MDCT window size by using
 vector_fmul_reverse

This brings the encoder in-line with the rest of ours and saves
on a bit of memory.
---
 libavcodec/ac3enc_fixed.c    |  9 ++++-----
 libavcodec/ac3enc_float.c    | 15 ++++-----------
 libavcodec/ac3enc_template.c |  5 ++++-
 3 files changed, 12 insertions(+), 17 deletions(-)
diff mbox series

Patch

diff --git a/libavcodec/ac3enc_fixed.c b/libavcodec/ac3enc_fixed.c
index 3b302d40df..7a8a77fb93 100644
--- a/libavcodec/ac3enc_fixed.c
+++ b/libavcodec/ac3enc_fixed.c
@@ -101,14 +101,13 @@  static av_cold int ac3_fixed_mdct_init(AC3EncodeContext *s)
 {
     float fwin[AC3_BLOCK_SIZE];
 
-    int32_t *iwin = av_malloc_array(AC3_WINDOW_SIZE, sizeof(*iwin));
+    int32_t *iwin = av_malloc_array(AC3_BLOCK_SIZE, sizeof(*iwin));
     if (!iwin)
         return AVERROR(ENOMEM);
 
-    ff_kbd_window_init(fwin, 5.0, AC3_WINDOW_SIZE/2);
-
-    for (int i = 0; i < AC3_WINDOW_SIZE/2; i++)
-        iwin[AC3_WINDOW_SIZE-1-i] = lrintf(fwin[i] * (1 << 22));
+    ff_kbd_window_init(fwin, 5.0, AC3_BLOCK_SIZE);
+    for (int i = 0; i < AC3_BLOCK_SIZE; i++)
+        iwin[i] = lrintf(fwin[i] * (1 << 22));
 
     s->mdct_window = iwin;
 
diff --git a/libavcodec/ac3enc_float.c b/libavcodec/ac3enc_float.c
index b17b3a2365..74f3ab8d86 100644
--- a/libavcodec/ac3enc_float.c
+++ b/libavcodec/ac3enc_float.c
@@ -108,23 +108,16 @@  static av_cold void ac3_float_mdct_end(AC3EncodeContext *s)
  */
 static av_cold int ac3_float_mdct_init(AC3EncodeContext *s)
 {
-    float *window;
-    int i, n, n2;
-
-    n  = 1 << 9;
-    n2 = n >> 1;
-
-    window = av_malloc_array(n, sizeof(*window));
+    float *window = av_malloc_array(AC3_BLOCK_SIZE, sizeof(*window));
     if (!window) {
         av_log(s->avctx, AV_LOG_ERROR, "Cannot allocate memory.\n");
         return AVERROR(ENOMEM);
     }
-    ff_kbd_window_init(window, 5.0, n2);
-    for (i = 0; i < n2; i++)
-        window[n-1-i] = window[i];
+
+    ff_kbd_window_init(window, 5.0, AC3_BLOCK_SIZE);
     s->mdct_window = window;
 
-    return ff_mdct_init(&s->mdct, 9, 0, -2.0 / n);
+    return ff_mdct_init(&s->mdct, 9, 0, -2.0 / AC3_WINDOW_SIZE);
 }
 
 
diff --git a/libavcodec/ac3enc_template.c b/libavcodec/ac3enc_template.c
index 4f1e181e0b..5ecef3b178 100644
--- a/libavcodec/ac3enc_template.c
+++ b/libavcodec/ac3enc_template.c
@@ -92,7 +92,10 @@  static void apply_mdct(AC3EncodeContext *s)
             const SampleType *input_samples = &s->planar_samples[ch][blk * AC3_BLOCK_SIZE];
 
             s->fdsp->vector_fmul(s->windowed_samples, input_samples,
-                                 s->mdct_window, AC3_WINDOW_SIZE);
+                                 s->mdct_window, AC3_BLOCK_SIZE);
+            s->fdsp->vector_fmul_reverse(s->windowed_samples + AC3_BLOCK_SIZE,
+                                         &input_samples[AC3_BLOCK_SIZE],
+                                         s->mdct_window, AC3_BLOCK_SIZE);
 
             s->mdct.mdct_calc(&s->mdct, block->mdct_coef[ch+1],
                               s->windowed_samples);