[FFmpeg-devel] [PATCH] avfilter/af_amix: add double sample format support

Paul B Mahol onemda at gmail.com
Sun Apr 9 23:11:33 EEST 2017


Signed-off-by: Paul B Mahol <onemda at gmail.com>
---
 libavfilter/af_amix.c | 19 +++++++++++++++----
 libavutil/float_dsp.c |  9 +++++++++
 libavutil/float_dsp.h | 16 ++++++++++++++++
 3 files changed, 40 insertions(+), 4 deletions(-)

diff --git a/libavfilter/af_amix.c b/libavfilter/af_amix.c
index a4d1389..2dacb22 100644
--- a/libavfilter/af_amix.c
+++ b/libavfilter/af_amix.c
@@ -336,10 +336,19 @@ static int output_frame(AVFilterLink *outlink)
             plane_size = nb_samples * (s->planar ? 1 : s->nb_channels);
             plane_size = FFALIGN(plane_size, 16);
 
-            for (p = 0; p < planes; p++) {
-                s->fdsp->vector_fmac_scalar((float *)out_buf->extended_data[p],
-                                           (float *) in_buf->extended_data[p],
-                                           s->input_scale[i], plane_size);
+            if (out_buf->format == AV_SAMPLE_FMT_FLT ||
+                out_buf->format == AV_SAMPLE_FMT_FLTP) {
+                for (p = 0; p < planes; p++) {
+                    s->fdsp->vector_fmac_scalar((float *)out_buf->extended_data[p],
+                                               (float *) in_buf->extended_data[p],
+                                               s->input_scale[i], plane_size);
+                }
+            } else {
+                for (p = 0; p < planes; p++) {
+                    s->fdsp->vector_dmac_scalar((double *)out_buf->extended_data[p],
+                                               (double *) in_buf->extended_data[p],
+                                               s->input_scale[i], plane_size);
+                }
             }
         }
     }
@@ -529,6 +538,8 @@ static int query_formats(AVFilterContext *ctx)
 
     if ((ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLT ))          < 0 ||
         (ret = ff_add_format(&formats, AV_SAMPLE_FMT_FLTP))          < 0 ||
+        (ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBL ))          < 0 ||
+        (ret = ff_add_format(&formats, AV_SAMPLE_FMT_DBLP))          < 0 ||
         (ret = ff_set_common_formats        (ctx, formats))          < 0 ||
         (ret = ff_set_common_channel_layouts(ctx, layouts))          < 0 ||
         (ret = ff_set_common_samplerates(ctx, ff_all_samplerates())) < 0)
diff --git a/libavutil/float_dsp.c b/libavutil/float_dsp.c
index c85daff..1d4911d 100644
--- a/libavutil/float_dsp.c
+++ b/libavutil/float_dsp.c
@@ -40,6 +40,14 @@ static void vector_fmac_scalar_c(float *dst, const float *src, float mul,
         dst[i] += src[i] * mul;
 }
 
+static void vector_dmac_scalar_c(double *dst, const double *src, double mul,
+                                 int len)
+{
+    int i;
+    for (i = 0; i < len; i++)
+        dst[i] += src[i] * mul;
+}
+
 static void vector_fmul_scalar_c(float *dst, const float *src, float mul,
                                  int len)
 {
@@ -125,6 +133,7 @@ av_cold AVFloatDSPContext *avpriv_float_dsp_alloc(int bit_exact)
     fdsp->vector_fmul = vector_fmul_c;
     fdsp->vector_fmac_scalar = vector_fmac_scalar_c;
     fdsp->vector_fmul_scalar = vector_fmul_scalar_c;
+    fdsp->vector_dmac_scalar = vector_dmac_scalar_c;
     fdsp->vector_dmul_scalar = vector_dmul_scalar_c;
     fdsp->vector_fmul_window = vector_fmul_window_c;
     fdsp->vector_fmul_add = vector_fmul_add_c;
diff --git a/libavutil/float_dsp.h b/libavutil/float_dsp.h
index d1be38f..2c24d93 100644
--- a/libavutil/float_dsp.h
+++ b/libavutil/float_dsp.h
@@ -55,6 +55,22 @@ typedef struct AVFloatDSPContext {
                                int len);
 
     /**
+     * Multiply a vector of doubles by a scalar double and add to
+     * destination vector.  Source and destination vectors must
+     * overlap exactly or not at all.
+     *
+     * @param dst result vector
+     *            constraints: 32-byte aligned
+     * @param src input vector
+     *            constraints: 32-byte aligned
+     * @param mul scalar value
+     * @param len length of vector
+     *            constraints: multiple of 16
+     */
+    void (*vector_dmac_scalar)(double *dst, const double *src, double mul,
+                               int len);
+
+    /**
      * Multiply a vector of floats by a scalar float.  Source and
      * destination vectors must overlap exactly or not at all.
      *
-- 
2.9.3



More information about the ffmpeg-devel mailing list