From 771bc1414b737475bc42c7263fd7f21b4d9cc9b7 Mon Sep 17 00:00:00 2001 From: Paul B Mahol 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 --- libswresample/rematrix.c | 54 +++++++++++++++++++++++++++-- libswresample/swresample.c | 5 +++ libswresample/swresample_internal.h | 2 ++ 3 files changed, 59 insertions(+), 2 deletions(-) diff --git a/libswresample/rematrix.c b/libswresample/rematrix.c index 79e8a43eac..2133b0f90d 100644 --- a/libswresample/rematrix.c +++ b/libswresample/rematrix.c @@ -652,7 +652,32 @@ 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; iplanar && in->planar) + len1 = len & ~15; + else + len1 = 0; + if ((intptr_t)out->ch[out_i] & 0x1f) + len1 = 0; + for (j = 0; j < s->matrix_ch[out_i][0] && len1 > 0; j++) { + in_i = s->matrix_ch[out_i][1+j]; + if ((intptr_t)in->ch[in_i] & 0x1f) { + len1 = 0; + break; + } + } + 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; jmatrix_ch[out_i][0]; j++){ in_i= s->matrix_ch[out_i][1+j]; @@ -661,7 +686,32 @@ 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; iplanar && in->planar) + len1 = len & ~15; + else + len1 = 0; + if ((intptr_t)out->ch[out_i] & 0x1f) + len1 = 0; + for (j = 0; j < s->matrix_ch[out_i][0] && len1 > 0; j++) { + in_i = s->matrix_ch[out_i][1+j]; + if ((intptr_t)in->ch[in_i] & 0x1f) { + len1 = 0; + break; + } + } + 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; jmatrix_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