[09/10] dcadsp: Add a new method, qmf_32_subbands

Message ID 1374085586-9721-9-git-send-email-martin@martin.st
State Superseded
Headers show

Commit Message

Martin Storsjö July 17, 2013, 6:26 p.m.
From: Ben Avison <bavison@riscosopen.org>

This does most of the work formerly carried out by
the static function qmf_32_subbands() in dcadec.c.
---
 libavcodec/dcadec.c |   32 ++++++++------------------------
 libavcodec/dcadsp.c |   32 ++++++++++++++++++++++++++++++++
 libavcodec/dcadsp.h |    6 ++++++
 3 files changed, 46 insertions(+), 24 deletions(-)

Comments

Martin Storsjö July 17, 2013, 7 p.m. | #1
On Wed, 17 Jul 2013, Martin Storsjö wrote:

> From: Ben Avison <bavison@riscosopen.org>
>
> This does most of the work formerly carried out by
> the static function qmf_32_subbands() in dcadec.c.
> ---
> libavcodec/dcadec.c |   32 ++++++++------------------------
> libavcodec/dcadsp.c |   32 ++++++++++++++++++++++++++++++++
> libavcodec/dcadsp.h |    6 ++++++
> 3 files changed, 46 insertions(+), 24 deletions(-)
>
> diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
> index b53f46b..7118177 100644
> --- a/libavcodec/dcadec.c
> +++ b/libavcodec/dcadec.c
> @@ -945,39 +945,23 @@ static void qmf_32_subbands(DCAContext *s, int chans,
>                             float samples_in[32][8], float *samples_out,
>                             float scale)
> {
> -    const float *prCoeff;
> -    int i;
> +    const float (*prCoeff)[512];
>
>     int sb_act = s->subband_activity[chans];
> -    int subindex;
>
>     scale *= sqrt(1 / 8.0);
>
>     /* Select filter */
>     if (!s->multirate_inter)    /* Non-perfect reconstruction */
> -        prCoeff = fir_32bands_nonperfect;
> +        prCoeff = &fir_32bands_nonperfect;
>     else                        /* Perfect reconstruction */
> -        prCoeff = fir_32bands_perfect;

Since there doesn't seem to be all that much benefit (with current 
compilers) of keeping the array length declared in the intermediate 
pointer, I've amended this locally (and in the branch on github) to keep 
this part as it is currently, shrinking the diff a little.

> -    for (i = sb_act; i < 32; i++)
> -        s->raXin[i] = 0.0;
> -
> -    /* Reconstructed channel sample index */
> -    for (subindex = 0; subindex < 8; subindex++) {
> -        /* Load in one sample from each subband and clear inactive subbands */
> -        for (i = 0; i < sb_act; i++) {
> -            unsigned sign = (i - 1) & 2;
> -            uint32_t v    = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
> -            AV_WN32A(&s->raXin[i], v);
> -        }
> +        prCoeff = &fir_32bands_perfect;
>
> -        s->synth.synth_filter_float(&s->imdct,
> -                                    s->subband_fir_hist[chans],
> -                                    &s->hist_index[chans],
> -                                    s->subband_fir_noidea[chans], prCoeff,
> -                                    samples_out, s->raXin, scale);
> -        samples_out += 32;
> -    }
> +    s->dcadsp.qmf_32_subbands(samples_in, sb_act, &s->synth, &s->imdct,
> +                              s->subband_fir_hist[chans],
> +                              &s->hist_index[chans],
> +                              s->subband_fir_noidea[chans], *prCoeff,
> +                              samples_out, s->raXin, scale);
> }
>
> static void lfe_interpolation_fir(DCAContext *s, int decimation_select,
> diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
> index 8b2dd42..7c067e3 100644
> --- a/libavcodec/dcadsp.c
> +++ b/libavcodec/dcadsp.c
> @@ -21,7 +21,10 @@
>
> #include "config.h"
> #include "libavutil/attributes.h"
> +#include "avfft.h"
> +#include "synth_filter.h"

I amended the patch locally moving these two includes to dcadsp.h (making 
the headers self-contained, so that "make checkheaders" still passes)

> #include "dcadsp.h"
> +#include "libavutil/intreadwrite.h"

... and moved this up next to the other libavutil include.

// Martin
Luca Barbato July 17, 2013, 7:10 p.m. | #2
On 07/17/2013 09:00 PM, Martin Storsjö wrote:
> Since there doesn't seem to be all that much benefit (with current
> compilers) of keeping the array length declared in the intermediate
> pointer, I've amended this locally (and in the branch on github) to keep
> this part as it is currently, shrinking the diff a little.

I like this way better, thanks.

> I amended the patch locally moving these two includes to dcadsp.h
> (making the headers self-contained, so that "make checkheaders" still
> passes)

> ... and moved this up next to the other libavutil include.

Thanks a lot.

lu

Patch

diff --git a/libavcodec/dcadec.c b/libavcodec/dcadec.c
index b53f46b..7118177 100644
--- a/libavcodec/dcadec.c
+++ b/libavcodec/dcadec.c
@@ -945,39 +945,23 @@  static void qmf_32_subbands(DCAContext *s, int chans,
                             float samples_in[32][8], float *samples_out,
                             float scale)
 {
-    const float *prCoeff;
-    int i;
+    const float (*prCoeff)[512];
 
     int sb_act = s->subband_activity[chans];
-    int subindex;
 
     scale *= sqrt(1 / 8.0);
 
     /* Select filter */
     if (!s->multirate_inter)    /* Non-perfect reconstruction */
-        prCoeff = fir_32bands_nonperfect;
+        prCoeff = &fir_32bands_nonperfect;
     else                        /* Perfect reconstruction */
-        prCoeff = fir_32bands_perfect;
-
-    for (i = sb_act; i < 32; i++)
-        s->raXin[i] = 0.0;
-
-    /* Reconstructed channel sample index */
-    for (subindex = 0; subindex < 8; subindex++) {
-        /* Load in one sample from each subband and clear inactive subbands */
-        for (i = 0; i < sb_act; i++) {
-            unsigned sign = (i - 1) & 2;
-            uint32_t v    = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
-            AV_WN32A(&s->raXin[i], v);
-        }
+        prCoeff = &fir_32bands_perfect;
 
-        s->synth.synth_filter_float(&s->imdct,
-                                    s->subband_fir_hist[chans],
-                                    &s->hist_index[chans],
-                                    s->subband_fir_noidea[chans], prCoeff,
-                                    samples_out, s->raXin, scale);
-        samples_out += 32;
-    }
+    s->dcadsp.qmf_32_subbands(samples_in, sb_act, &s->synth, &s->imdct,
+                              s->subband_fir_hist[chans],
+                              &s->hist_index[chans],
+                              s->subband_fir_noidea[chans], *prCoeff,
+                              samples_out, s->raXin, scale);
 }
 
 static void lfe_interpolation_fir(DCAContext *s, int decimation_select,
diff --git a/libavcodec/dcadsp.c b/libavcodec/dcadsp.c
index 8b2dd42..7c067e3 100644
--- a/libavcodec/dcadsp.c
+++ b/libavcodec/dcadsp.c
@@ -21,7 +21,10 @@ 
 
 #include "config.h"
 #include "libavutil/attributes.h"
+#include "avfft.h"
+#include "synth_filter.h"
 #include "dcadsp.h"
+#include "libavutil/intreadwrite.h"
 
 static void dca_lfe_fir_c(float *out, const float *in, const float *coefs,
                           int decifactor, float scale)
@@ -45,8 +48,37 @@  static void dca_lfe_fir_c(float *out, const float *in, const float *coefs,
     }
 }
 
+static void dca_qmf_32_subbands(float samples_in[32][8], int sb_act,
+                                SynthFilterContext *synth, FFTContext *imdct,
+                                float synth_buf_ptr[512],
+                                int *synth_buf_offset, float synth_buf2[32],
+                                const float window[512], float *samples_out,
+                                float raXin[32], float scale)
+{
+    int i;
+    int subindex;
+
+    for (i = sb_act; i < 32; i++)
+        raXin[i] = 0.0;
+
+    /* Reconstructed channel sample index */
+    for (subindex = 0; subindex < 8; subindex++) {
+        /* Load in one sample from each subband and clear inactive subbands */
+        for (i = 0; i < sb_act; i++) {
+            unsigned sign = (i - 1) & 2;
+            uint32_t v    = AV_RN32A(&samples_in[i][subindex]) ^ sign << 30;
+            AV_WN32A(&raXin[i], v);
+        }
+
+        synth->synth_filter_float(imdct, synth_buf_ptr, synth_buf_offset,
+                                  synth_buf2, window, samples_out, raXin, scale);
+        samples_out += 32;
+    }
+}
+
 av_cold void ff_dcadsp_init(DCADSPContext *s)
 {
     s->lfe_fir = dca_lfe_fir_c;
+    s->qmf_32_subbands = dca_qmf_32_subbands;
     if (ARCH_ARM) ff_dcadsp_init_arm(s);
 }
diff --git a/libavcodec/dcadsp.h b/libavcodec/dcadsp.h
index 3c6f1f9..04a5ef2 100644
--- a/libavcodec/dcadsp.h
+++ b/libavcodec/dcadsp.h
@@ -22,6 +22,12 @@ 
 typedef struct DCADSPContext {
     void (*lfe_fir)(float *out, const float *in, const float *coefs,
                     int decifactor, float scale);
+    void (*qmf_32_subbands)(float samples_in[32][8], int sb_act,
+                            SynthFilterContext *synth, FFTContext *imdct,
+                            float synth_buf_ptr[512],
+                            int *synth_buf_offset, float synth_buf2[32],
+                            const float window[512], float *samples_out,
+                            float raXin[32], float scale);
 } DCADSPContext;
 
 void ff_dcadsp_init(DCADSPContext *s);