Attached.
From 1f6aded57aab1fd8c6c7ba6fa5261d7979666f66 Mon Sep 17 00:00:00 2001
From: Paul B Mahol <one...@gmail.com>
Date: Wed, 10 May 2023 15:41:01 +0200
Subject: [PATCH] swresample: reuse DSP functions from avutil

Improves generic mixing dramatically.

Signed-off-by: Paul B Mahol <one...@gmail.com>
---
 libswresample/rematrix.c            | 30 +++++++++++++++++++++++++++--
 libswresample/swresample.c          |  5 +++++
 libswresample/swresample_internal.h |  2 ++
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c
index 79e8a43eac..0d234bc97e 100644
--- a/libswresample/rematrix.c
+++ b/libswresample/rematrix.c
@@ -652,7 +652,20 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
             break;}
         default:
             if(s->int_sample_fmt == AV_SAMPLE_FMT_FLTP){
-                for(i=0; i<len; i++){
+                len1 = len & ~15;
+                if (len1 > 0) {
+                    in_i = s->matrix_ch[out_i][1+0];
+                    s->fdsp->vector_fmul_scalar((float *)out->ch[out_i],
+                                                (const float *)in->ch[in_i],
+                                                s->matrix_flt[out_i][in_i], len1);
+                    for (j = 1; j < s->matrix_ch[out_i][0]; j++) {
+                        in_i = s->matrix_ch[out_i][1+j];
+                        s->fdsp->vector_fmac_scalar((float *)out->ch[out_i],
+                                                    (const float *)in->ch[in_i],
+                                                    s->matrix_flt[out_i][in_i], len1);
+                    }
+                }
+                for (i = len1; i < len; i++) {
                     float v=0;
                     for(j=0; j<s->matrix_ch[out_i][0]; j++){
                         in_i= s->matrix_ch[out_i][1+j];
@@ -661,7 +674,20 @@ int swri_rematrix(SwrContext *s, AudioData *out, AudioData *in, int len, int mus
                     ((float*)out->ch[out_i])[i]= v;
                 }
             }else if(s->int_sample_fmt == AV_SAMPLE_FMT_DBLP){
-                for(i=0; i<len; i++){
+                len1 = len & ~15;
+                if (len1 > 0) {
+                    in_i = s->matrix_ch[out_i][1+0];
+                    s->fdsp->vector_dmul_scalar((double *)out->ch[out_i],
+                                                (const double *)in->ch[in_i],
+                                                s->matrix[out_i][in_i], len1);
+                    for (j = 1; j < s->matrix_ch[out_i][0]; j++) {
+                        in_i = s->matrix_ch[out_i][1+j];
+                        s->fdsp->vector_dmac_scalar((double *)out->ch[out_i],
+                                                    (const double *)in->ch[in_i],
+                                                    s->matrix[out_i][in_i], len1);
+                    }
+                }
+                for (i = len1; i < len; i++) {
                     double v=0;
                     for(j=0; j<s->matrix_ch[out_i][0]; j++){
                         in_i= s->matrix_ch[out_i][1+j];
diff --git a/libswresample/swresample.c b/libswresample/swresample.c
index 6dc329a9d0..b0b6f6a5c5 100644
--- a/libswresample/swresample.c
+++ b/libswresample/swresample.c
@@ -181,6 +181,7 @@ av_cold void swr_free(SwrContext **ss){
 
         if (s->resampler)
             s->resampler->free(&s->resample);
+        av_freep(&s->fdsp);
     }
 
     av_freep(ss);
@@ -504,6 +505,10 @@ av_assert0(s->out.ch_count);
             goto fail;
     }
 
+    s->fdsp = avpriv_float_dsp_alloc(0);
+    if (!s->fdsp)
+        goto fail;
+
     return 0;
 fail:
     swr_close(s);
diff --git a/libswresample/swresample_internal.h b/libswresample/swresample_internal.h
index ad902d73fa..dba678c502 100644
--- a/libswresample/swresample_internal.h
+++ b/libswresample/swresample_internal.h
@@ -22,6 +22,7 @@
 #define SWRESAMPLE_SWRESAMPLE_INTERNAL_H
 
 #include "swresample.h"
+#include "libavutil/float_dsp.h"
 #include "libavutil/channel_layout.h"
 #include "config.h"
 
@@ -189,6 +190,7 @@ struct SwrContext {
 
     mix_any_func_type *mix_any_f;
 
+    AVFloatDSPContext *fdsp;
     /* TODO: callbacks for ASM optimizations */
 };
 
-- 
2.39.1

_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel

To unsubscribe, visit link above, or email
ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".

Reply via email to