[FFmpeg-devel] make ff_qcelp_lspf2lpc more general

Kenan Gillet kenan.gillet
Sat Jan 24 04:12:41 CET 2009


the patch split the specific code for QCELP back into qcelpdec.c.
It allows to reuse the code in the amr-nb SOC decoder.
-------------- next part --------------
Index: libavcodec/qcelp_lsp.c
===================================================================
--- libavcodec/qcelp_lsp.c	(revision 16645)
+++ libavcodec/qcelp_lsp.c	(working copy)
@@ -30,15 +30,6 @@
 #include "libavutil/mathematics.h"
 
 /**
- * initial coefficient to perform bandwidth expansion on LPC
- *
- * @note: 0.9883 looks like an approximation of 253/256.
- *
- * TIA/EIA/IS-733 2.4.3.3.6 6
- */
-#define QCELP_BANDWITH_EXPANSION_COEFF 0.9883
-
-/**
  * Computes the Pa / (1 + z(-1)) or Qa / (1 - z(-1)) coefficients
  * needed for LSP to LPC conversion.
  * We only need to calculate the 6 first elements of the polynomial.
@@ -48,16 +39,16 @@
  *
  * TIA/EIA/IS-733 2.4.3.3.5-1/2
  */
-static void lsp2polyf(const float *lspf, double *f, int lp_half_order)
+static void lsp2polyf(const double *lspf, double *f, int lp_half_order)
 {
     int i, j;
 
     f[0] = 1.0;
-    f[1] = -2 * cos(M_PI * lspf[0]);
+    f[1] = -2 * lspf[0];
     lspf -= 2;
     for(i=2; i<=lp_half_order; i++)
     {
-        double val = -2 * cos(M_PI * lspf[2*i]);
+        double val = -2 * lspf[2*i];
         f[i] = val * f[i-1] + 2*f[i-2];
         for(j=i-1; j>1; j--)
             f[j] += f[j-1] * val + f[j-2];
@@ -66,22 +57,17 @@
 }
 
 /**
- * Reconstructs LPC coefficients from the line spectral pair frequencies
- * and performs bandwidth expansion.
+ * Reconstructs LPC coefficients from the line spectral pair frequencies.
  *
  * @param lspf line spectral pair frequencies
  * @param lpc linear predictive coding coefficients
  *
- * @note: bandwith_expansion_coeff could be precalculated into a table
- *        but it seems to be slower on x86
- *
  * TIA/EIA/IS-733 2.4.3.3.5
  */
-void ff_qcelp_lspf2lpc(const float *lspf, float *lpc)
+void ff_qcelp_lspf2lpc(const double *lspf, float *lpc)
 {
     double pa[6], qa[6];
     int   i;
-    double bandwith_expansion_coeff = -QCELP_BANDWITH_EXPANSION_COEFF * 0.5;
 
     lsp2polyf(lspf,     pa, 5);
     lsp2polyf(lspf + 1, qa, 5);
@@ -91,12 +77,7 @@
         double paf = pa[i+1] + pa[i];
         double qaf = qa[i+1] - qa[i];
 
-        lpc[i  ] = paf + qaf;
-        lpc[9-i] = paf - qaf;
+        lpc[i  ] = 0.5 * (paf+qaf);
+        lpc[9-i] = 0.5 * (paf-qaf);
     }
-    for (i=0; i<10; i++)
-    {
-        lpc[i] *= bandwith_expansion_coeff;
-        bandwith_expansion_coeff *= QCELP_BANDWITH_EXPANSION_COEFF;
-    }
 }
Index: libavcodec/qcelpdata.h
===================================================================
--- libavcodec/qcelpdata.h	(revision 16645)
+++ libavcodec/qcelpdata.h	(working copy)
@@ -550,4 +550,13 @@
  */
 #define QCELP_LSP_OCTAVE_PREDICTOR 29.0/32
 
+/**
+ * initial coefficient to perform bandwidth expansion on LPC
+ *
+ * @note: 0.9883 looks like an approximation of 253/256.
+ *
+ * TIA/EIA/IS-733 2.4.3.3.6 6
+ */
+#define QCELP_BANDWITH_EXPANSION_COEFF 0.9883
+
 #endif /* AVCODEC_QCELPDATA_H */
Index: libavcodec/qcelpdec.c
===================================================================
--- libavcodec/qcelpdec.c	(revision 16645)
+++ libavcodec/qcelpdec.c	(working copy)
@@ -79,7 +79,7 @@
  *
  * TIA/EIA/IS-733 2.4.3.3.5
  */
-void ff_qcelp_lspf2lpc(const float *lspf, float *lpc);
+void ff_qcelp_lspf2lpc(const double *lsf, float *lpc);
 
 static void weighted_vector_sumf(float *out, const float *in_a,
                                  const float *in_b, float weight_coeff_a,
@@ -585,6 +585,36 @@
 }
 
 /**
+ * Reconstructs LPC coefficients from the line spectral pair frequencies
+ * and performs bandwidth expansion.
+ *
+ * @param lspf line spectral pair frequencies
+ * @param lpc linear predictive coding coefficients
+ *
+ * @note: bandwith_expansion_coeff could be precalculated into a table
+ *        but it seems to be slower on x86
+ *
+ * TIA/EIA/IS-733 2.4.3.3.5
+ */
+void lspf2lpc(const float *lspf, float *lpc)
+{
+    double lsf[10];
+    double bandwith_expansion_coeff = -QCELP_BANDWITH_EXPANSION_COEFF;
+    int   i;
+
+    for (i=0; i<10; i++)
+        lsf[i] = cos(M_PI * lspf[i]);
+
+    ff_qcelp_lspf2lpc(lsf, lpc);
+
+    for (i=0; i<10; i++)
+    {
+        lpc[i] *= bandwith_expansion_coeff;
+        bandwith_expansion_coeff *= QCELP_BANDWITH_EXPANSION_COEFF;
+    }
+}
+
+/**
  * Interpolates LSP frequencies and computes LPC coefficients
  * for a given bitrate & pitch subframe.
  *
@@ -612,12 +642,12 @@
     {
         weighted_vector_sumf(interpolated_lspf, curr_lspf, q->prev_lspf,
                              weight, 1.0 - weight, 10);
-        ff_qcelp_lspf2lpc(interpolated_lspf, lpc);
+        lspf2lpc(interpolated_lspf, lpc);
     }else if(q->bitrate >= RATE_QUARTER ||
              (q->bitrate == I_F_Q && !subframe_num))
-        ff_qcelp_lspf2lpc(curr_lspf, lpc);
+        lspf2lpc(curr_lspf, lpc);
     else if(q->bitrate == SILENCE && !subframe_num)
-        ff_qcelp_lspf2lpc(q->prev_lspf, lpc);
+        lspf2lpc(q->prev_lspf, lpc);
 }
 
 static qcelp_packet_rate buf_size2bitrate(const int buf_size)



More information about the ffmpeg-devel mailing list