[FFmpeg-devel] [PATCH] extract and share weighted_vector_sumf for QCELP and AMRNB SoC

Kenan Gillet kenan.gillet
Fri Feb 20 00:10:07 CET 2009


Hi all,

while working on the AMR SoC code, I stumble on some code
that could shared with the QCELP decoder.

Here is the first patches to extract and share weighted_vector_sumf.

Kenan
-------------- next part --------------
Index: libavcodec/qcelpdec.c
===================================================================
--- libavcodec/qcelpdec.c	(revision 17461)
+++ libavcodec/qcelpdec.c	(working copy)
@@ -37,6 +37,7 @@
 
 #include "celp_math.h"
 #include "celp_filters.h"
+#include "acelp_vectors.h"
 
 #undef NDEBUG
 #include <assert.h>
@@ -81,17 +82,6 @@
  */
 void ff_qcelp_lspf2lpc(const float *lspf, float *lpc);
 
-static void weighted_vector_sumf(float *out, const float *in_a,
-                                 const float *in_b, float weight_coeff_a,
-                                 float weight_coeff_b, int length)
-{
-    int i;
-
-    for(i=0; i<length; i++)
-        out[i] = weight_coeff_a * in_a[i]
-               + weight_coeff_b * in_b[i];
-}
-
 /**
  * Initialize the speech codec according to the specification.
  *
@@ -174,7 +164,7 @@
             lspf[i-1] = FFMIN(lspf[i-1], (lspf[i] - QCELP_LSP_SPREAD_FACTOR));
 
         // Low-pass filter the LSP frequencies.
-        weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10);
+        ff_weighted_vector_sumf(lspf, lspf, q->prev_lspf, smooth, 1.0-smooth, 10);
     }else
     {
         q->octave_count = 0;
@@ -610,7 +600,7 @@
 
     if(weight != 1.0)
     {
-        weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
+        ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
                              weight, 1.0 - weight, 10);
         ff_qcelp_lspf2lpc(interpolated_lspf, lpc);
     }else if(q->bitrate >= RATE_QUARTER ||
Index: libavcodec/acelp_vectors.c
===================================================================
--- libavcodec/acelp_vectors.c	(revision 17461)
+++ libavcodec/acelp_vectors.c	(working copy)
@@ -145,3 +145,13 @@
                  in_b[i] * weight_coeff_b +
                  rounder) >> shift);
 }
+
+void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
+                             float weight_coeff_a, float weight_coeff_b, int length)
+{
+    int i;
+
+    for(i=0; i<length; i++)
+        out[i] = weight_coeff_a * in_a[i]
+               + weight_coeff_b * in_b[i];
+}
Index: libavcodec/acelp_vectors.h
===================================================================
--- libavcodec/acelp_vectors.h	(revision 17461)
+++ libavcodec/acelp_vectors.h	(working copy)
@@ -150,4 +150,18 @@
         int shift,
         int length);
 
+/**
+ * float implementation of weighted sum of two vectors.
+ * @param out [out] result of addition
+ * @param in_a first vector
+ * @param in_b second vector
+ * @param weight_coeff_a first vector weight coefficient
+ * @param weight_coeff_a second vector weight coefficient
+ * @param length vectors length
+ *
+ * @note It is safe to pass the same buffer for out and in_a or in_b.
+ */
+void ff_weighted_vector_sumf(float *out, const float *in_a, const float *in_b,
+                             float weight_coeff_a, float weight_coeff_b, int length);
+
 #endif /* AVCODEC_ACELP_VECTORS_H */
Index: libavcodec/Makefile
===================================================================
--- libavcodec/Makefile	(revision 17461)
+++ libavcodec/Makefile	(working copy)
@@ -166,7 +166,7 @@
 OBJS-$(CONFIG_PNG_ENCODER)             += png.o pngenc.o
 OBJS-$(CONFIG_PPM_ENCODER)             += pnmenc.o pnm.o
 OBJS-$(CONFIG_PTX_DECODER)             += ptx.o
-OBJS-$(CONFIG_QCELP_DECODER)           += qcelpdec.o qcelp_lsp.o celp_math.o celp_filters.o
+OBJS-$(CONFIG_QCELP_DECODER)           += qcelpdec.o qcelp_lsp.o celp_math.o celp_filters.o acelp_vectors.o
 OBJS-$(CONFIG_QDM2_DECODER)            += qdm2.o mpegaudiodec.o mpegaudiodecheader.o mpegaudio.o mpegaudiodata.o
 OBJS-$(CONFIG_QDRAW_DECODER)           += qdrw.o
 OBJS-$(CONFIG_QPEG_DECODER)            += qpeg.o
-------------- next part --------------
--- libavcodec/qcelpdec-w-ff_weighted_vector_sumf.c	2009-02-19 14:27:02.000000000 -0800
+++ libavcodec/qcelpdec.c	2009-02-19 14:27:10.000000000 -0800
@@ -601,7 +601,7 @@
     if(weight != 1.0)
     {
         ff_weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
-                             weight, 1.0 - weight, 10);
+                                weight, 1.0 - weight, 10);
         ff_qcelp_lspf2lpc(interpolated_lspf, lpc);
     }else if(q->bitrate >= RATE_QUARTER ||
              (q->bitrate == I_F_Q && !subframe_num))



More information about the ffmpeg-devel mailing list