From 09ebb5dbefcfa588f4021269438674fab631a60b Mon Sep 17 00:00:00 2001
From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
Date: Sat, 15 Mar 2025 22:26:26 +0100
Subject: [PATCH 2/2] avutil/float_dsp: Unavpriv avpriv_scalarproduct_float_c()

Not worth the overhead of exporting it.

Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
---
 libavcodec/Makefile              |  3 ++-
 libavcodec/acelp_pitch_delay.c   |  2 +-
 libavcodec/acelp_vectors.c       |  4 ++--
 libavcodec/float_scalarproduct.c | 19 ++++++++++++++++++
 libavcodec/qcelpdec.c            |  8 ++++----
 libavcodec/ra288.c               |  4 ++--
 libavcodec/sipr.c                | 12 ++++++------
 libavcodec/sipr16k.c             |  6 +++---
 libavcodec/wmavoice.c            | 16 ++++++++--------
 libavutil/Makefile               |  1 +
 libavutil/float_dsp.c            | 13 +------------
 libavutil/float_dsp.h            |  2 +-
 libavutil/float_scalarproduct.c  | 33 ++++++++++++++++++++++++++++++++
 13 files changed, 83 insertions(+), 40 deletions(-)
 create mode 100644 libavcodec/float_scalarproduct.c
 create mode 100644 libavutil/float_scalarproduct.c

diff --git a/libavcodec/Makefile b/libavcodec/Makefile
index 3c7043a617..3c2c614f1a 100644
--- a/libavcodec/Makefile
+++ b/libavcodec/Makefile
@@ -64,7 +64,8 @@ OBJS = ac3_parser.o                                                     \
        vorbis_parser.o                                                  \
        xiph.o                                                           \
 
-SHLIBOBJS = timecode_internal.o                                         \
+SHLIBOBJS = float_scalarproduct.o                                       \
+            timecode_internal.o                                         \
 
 # subsystems
 include $(SRC_PATH)/libavcodec/aac/Makefile
diff --git a/libavcodec/acelp_pitch_delay.c b/libavcodec/acelp_pitch_delay.c
index 6cf880e4ac..65f659cb2e 100644
--- a/libavcodec/acelp_pitch_delay.c
+++ b/libavcodec/acelp_pitch_delay.c
@@ -90,7 +90,7 @@ float ff_amr_set_fixed_gain(float fixed_gain_factor, float fixed_mean_energy,
     // Note 10^(0.05 * -10log(average x2)) = 1/sqrt((average x2)).
     float val = fixed_gain_factor *
         ff_exp10(0.05 *
-              (avpriv_scalarproduct_float_c(pred_table, prediction_error, 4) +
+              (ff_scalarproduct_float_c(pred_table, prediction_error, 4) +
                energy_mean)) /
         sqrtf(fixed_mean_energy ? fixed_mean_energy : 1.0);
 
diff --git a/libavcodec/acelp_vectors.c b/libavcodec/acelp_vectors.c
index 04cbffd79f..f47da40008 100644
--- a/libavcodec/acelp_vectors.c
+++ b/libavcodec/acelp_vectors.c
@@ -193,7 +193,7 @@ void ff_adaptive_gain_control(float *out, const float *in, float speech_energ,
                               int size, float alpha, float *gain_mem)
 {
     int i;
-    float postfilter_energ = avpriv_scalarproduct_float_c(in, in, size);
+    float postfilter_energ = ff_scalarproduct_float_c(in, in, size);
     float gain_scale_factor = 1.0;
     float mem = *gain_mem;
 
@@ -214,7 +214,7 @@ void ff_scale_vector_to_given_sum_of_squares(float *out, const float *in,
                                              float sum_of_squares, const int n)
 {
     int i;
-    float scalefactor = avpriv_scalarproduct_float_c(in, in, n);
+    float scalefactor = ff_scalarproduct_float_c(in, in, n);
     if (scalefactor)
         scalefactor = sqrt(sum_of_squares / scalefactor);
     for (i = 0; i < n; i++)
diff --git a/libavcodec/float_scalarproduct.c b/libavcodec/float_scalarproduct.c
new file mode 100644
index 0000000000..647f0ec72d
--- /dev/null
+++ b/libavcodec/float_scalarproduct.c
@@ -0,0 +1,19 @@
+/*
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "libavutil/float_scalarproduct.c"
diff --git a/libavcodec/qcelpdec.c b/libavcodec/qcelpdec.c
index 1435fecc2e..7d23a11102 100644
--- a/libavcodec/qcelpdec.c
+++ b/libavcodec/qcelpdec.c
@@ -397,7 +397,7 @@ static void apply_gain_ctrl(float *v_out, const float *v_ref, const float *v_in)
     int i;
 
     for (i = 0; i < 160; i += 40) {
-        float res = avpriv_scalarproduct_float_c(v_ref + i, v_ref + i, 40);
+        float res = ff_scalarproduct_float_c(v_ref + i, v_ref + i, 40);
         ff_scale_vector_to_given_sum_of_squares(v_out + i, v_in + i, res, 40);
     }
 }
@@ -676,9 +676,9 @@ static void postfilter(QCELPContext *q, float *samples, float *lpc)
     ff_tilt_compensation(&q->postfilter_tilt_mem, 0.3, pole_out + 10, 160);
 
     ff_adaptive_gain_control(samples, pole_out + 10,
-                             avpriv_scalarproduct_float_c(q->formant_mem + 10,
-                                                          q->formant_mem + 10,
-                                                          160),
+                             ff_scalarproduct_float_c(q->formant_mem + 10,
+                                                      q->formant_mem + 10,
+                                                      160),
                              160, 0.9375, &q->postfilter_agc_mem);
 }
 
diff --git a/libavcodec/ra288.c b/libavcodec/ra288.c
index 5b186a7a3d..aa499506b7 100644
--- a/libavcodec/ra288.c
+++ b/libavcodec/ra288.c
@@ -90,7 +90,7 @@ static av_cold int ra288_decode_init(AVCodecContext *avctx)
 static void convolve(float *tgt, const float *src, int len, int n)
 {
     for (; n >= 0; n--)
-        tgt[n] = avpriv_scalarproduct_float_c(src, src - n, len);
+        tgt[n] = ff_scalarproduct_float_c(src, src - n, len);
 
 }
 
@@ -119,7 +119,7 @@ static void decode(RA288Context *ractx, float gain, int cb_coef)
     for (i=0; i < 5; i++)
         buffer[i] = codetable[cb_coef][i] * sumsum;
 
-    sum = avpriv_scalarproduct_float_c(buffer, buffer, 5);
+    sum = ff_scalarproduct_float_c(buffer, buffer, 5);
 
     sum = FFMAX(sum, 5.0 / (1<<24));
 
diff --git a/libavcodec/sipr.c b/libavcodec/sipr.c
index 3ddc579f09..ebd7dab03c 100644
--- a/libavcodec/sipr.c
+++ b/libavcodec/sipr.c
@@ -412,9 +412,9 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params,
         convolute_with_sparse(fixed_vector, &fixed_cb, impulse_response,
                               SUBFR_SIZE);
 
-        avg_energy = (0.01 + avpriv_scalarproduct_float_c(fixed_vector,
-                                                          fixed_vector,
-                                                          SUBFR_SIZE)) /
+        avg_energy = (0.01 + ff_scalarproduct_float_c(fixed_vector,
+                                                      fixed_vector,
+                                                      SUBFR_SIZE)) /
                      SUBFR_SIZE;
 
         ctx->past_pitch_gain = pitch_gain = gain_cb[params->gc_index[i]][0];
@@ -456,9 +456,9 @@ static void decode_frame(SiprContext *ctx, SiprParameters *params,
 
     if (ctx->mode == MODE_5k0) {
         for (i = 0; i < subframe_count; i++) {
-            float energy = avpriv_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
-                                                        ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
-                                                        SUBFR_SIZE);
+            float energy = ff_scalarproduct_float_c(ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
+                                                    ctx->postfilter_syn5k0 + LP_FILTER_ORDER + i * SUBFR_SIZE,
+                                                    SUBFR_SIZE);
             ff_adaptive_gain_control(&synth[i * SUBFR_SIZE],
                                      &synth[i * SUBFR_SIZE], energy,
                                      SUBFR_SIZE, 0.9, &ctx->postfilter_agc);
diff --git a/libavcodec/sipr16k.c b/libavcodec/sipr16k.c
index 9c8f684003..ab892d0547 100644
--- a/libavcodec/sipr16k.c
+++ b/libavcodec/sipr16k.c
@@ -163,11 +163,11 @@ static float acelp_decode_gain_codef(float gain_corr_factor, const float *fc_v,
                                      const float *ma_prediction_coeff,
                                      int subframe_size, int ma_pred_order)
 {
-    mr_energy += avpriv_scalarproduct_float_c(quant_energy, ma_prediction_coeff,
-                                              ma_pred_order);
+    mr_energy += ff_scalarproduct_float_c(quant_energy, ma_prediction_coeff,
+                                          ma_pred_order);
 
     mr_energy = gain_corr_factor * exp(M_LN10 / 20. * mr_energy) /
-        sqrt((0.01 + avpriv_scalarproduct_float_c(fc_v, fc_v, subframe_size)));
+        sqrt((0.01 + ff_scalarproduct_float_c(fc_v, fc_v, subframe_size)));
     return mr_energy;
 }
 
diff --git a/libavcodec/wmavoice.c b/libavcodec/wmavoice.c
index a1f89aeb76..e89a5c2bfb 100644
--- a/libavcodec/wmavoice.c
+++ b/libavcodec/wmavoice.c
@@ -559,7 +559,7 @@ static int kalman_smoothen(WMAVoiceContext *s, int pitch,
 
     /* find best fitting point in history */
     do {
-        dot = avpriv_scalarproduct_float_c(in, ptr, size);
+        dot = ff_scalarproduct_float_c(in, ptr, size);
         if (dot > optimal_gain) {
             optimal_gain  = dot;
             best_hist_ptr = ptr;
@@ -568,7 +568,7 @@ static int kalman_smoothen(WMAVoiceContext *s, int pitch,
 
     if (optimal_gain <= 0)
         return -1;
-    dot = avpriv_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);
+    dot = ff_scalarproduct_float_c(best_hist_ptr, best_hist_ptr, size);
     if (dot <= 0) // would be 1.0
         return -1;
 
@@ -598,8 +598,8 @@ static float tilt_factor(const float *lpcs, int n_lpcs)
 {
     float rh0, rh1;
 
-    rh0 = 1.0     + avpriv_scalarproduct_float_c(lpcs,  lpcs,    n_lpcs);
-    rh1 = lpcs[0] + avpriv_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);
+    rh0 = 1.0     + ff_scalarproduct_float_c(lpcs,  lpcs,    n_lpcs);
+    rh1 = lpcs[0] + ff_scalarproduct_float_c(lpcs, &lpcs[1], n_lpcs - 1);
 
     return rh1 / rh0;
 }
@@ -699,8 +699,8 @@ static void calc_input_response(WMAVoiceContext *s, float *lpcs_src,
                              -1.8 * tilt_factor(coeffs_dst, remainder - 1),
                              coeffs_dst, remainder);
     }
-    sq = (1.0 / 64.0) * sqrtf(1 / avpriv_scalarproduct_float_c(coeffs_dst, coeffs_dst,
-                                                               remainder));
+    sq = (1.0 / 64.0) * sqrtf(1 / ff_scalarproduct_float_c(coeffs_dst, coeffs_dst,
+                                                           remainder));
     for (n = 0; n < remainder; n++)
         coeffs_dst[n] *= sq;
 }
@@ -1378,8 +1378,8 @@ static void synth_block_fcb_acb(WMAVoiceContext *s, GetBitContext *gb,
     /* Calculate gain for adaptive & fixed codebook signal.
      * see ff_amr_set_fixed_gain(). */
     idx = get_bits(gb, 7);
-    fcb_gain = expf(avpriv_scalarproduct_float_c(s->gain_pred_err,
-                                                 gain_coeff, 6) -
+    fcb_gain = expf(ff_scalarproduct_float_c(s->gain_pred_err,
+                                             gain_coeff, 6) -
                     5.2409161640 + wmavoice_gain_codebook_fcb[idx]);
     acb_gain = wmavoice_gain_codebook_acb[idx];
     pred_err = av_clipf(wmavoice_gain_codebook_fcb[idx],
diff --git a/libavutil/Makefile b/libavutil/Makefile
index b7ed339ab3..a5a92ea5f7 100644
--- a/libavutil/Makefile
+++ b/libavutil/Makefile
@@ -139,6 +139,7 @@ OBJS = adler32.o                                                        \
        file.o                                                           \
        file_open.o                                                      \
        float_dsp.o                                                      \
+       float_scalarproduct.o                                            \
        film_grain_params.o                                              \
        fixed_dsp.o                                                      \
        frame.o                                                          \
diff --git a/libavutil/float_dsp.c b/libavutil/float_dsp.c
index 08bbc85e3e..f38ad565cf 100644
--- a/libavutil/float_dsp.c
+++ b/libavutil/float_dsp.c
@@ -121,17 +121,6 @@ static void butterflies_float_c(float *restrict v1, float *restrict v2,
     }
 }
 
-float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len)
-{
-    float p = 0.0;
-    int i;
-
-    for (i = 0; i < len; i++)
-        p += v1[i] * v2[i];
-
-    return p;
-}
-
 double ff_scalarproduct_double_c(const double *v1, const double *v2,
                                  size_t len)
 {
@@ -159,7 +148,7 @@ av_cold AVFloatDSPContext *avpriv_float_dsp_alloc(int bit_exact)
     fdsp->vector_fmul_add = vector_fmul_add_c;
     fdsp->vector_fmul_reverse = vector_fmul_reverse_c;
     fdsp->butterflies_float = butterflies_float_c;
-    fdsp->scalarproduct_float = avpriv_scalarproduct_float_c;
+    fdsp->scalarproduct_float = ff_scalarproduct_float_c;
     fdsp->scalarproduct_double = ff_scalarproduct_double_c;
 
 #if ARCH_AARCH64
diff --git a/libavutil/float_dsp.h b/libavutil/float_dsp.h
index a99edc39bb..ab34277c20 100644
--- a/libavutil/float_dsp.h
+++ b/libavutil/float_dsp.h
@@ -215,7 +215,7 @@ typedef struct AVFloatDSPContext {
  *
  * @return sum of elementwise products
  */
-float avpriv_scalarproduct_float_c(const float *v1, const float *v2, int len);
+float ff_scalarproduct_float_c(const float *v1, const float *v2, int len);
 
 /**
  * Return the scalar product of two vectors of doubles.
diff --git a/libavutil/float_scalarproduct.c b/libavutil/float_scalarproduct.c
new file mode 100644
index 0000000000..c7b3b72852
--- /dev/null
+++ b/libavutil/float_scalarproduct.c
@@ -0,0 +1,33 @@
+/*
+ * Copyright 2005 Balatoni Denes
+ * Copyright 2006 Loren Merritt
+ *
+ * This file is part of FFmpeg.
+ *
+ * FFmpeg is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * FFmpeg is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with FFmpeg; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include "float_dsp.h"
+
+float ff_scalarproduct_float_c(const float *v1, const float *v2, int len)
+{
+    float p = 0.0;
+
+    for (int i = 0; i < len; i++)
+        p += v1[i] * v2[i];
+
+    return p;
+}
+
-- 
2.45.2