changeset 380:2ed325c9a507

libtwamr: integrate lsp_az.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 05:31:47 +0000
parents 176a44ff94a1
children 32bc48faec4b
files libtwamr/Makefile libtwamr/lsp_az.c libtwamr/lsp_az.h libtwamr/namespace.list
diffstat 4 files changed, 206 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Mon May 06 05:10:03 2024 +0000
+++ b/libtwamr/Makefile	Mon May 06 05:31:47 2024 +0000
@@ -8,10 +8,10 @@
 	dec_lag6.o dhf_check.o dhf_tables.o e_homing.o ec_gains.o enc_lag3.o \
 	enc_lag6.o ex_ctrl.o g_adapt.o g_code.o g_pitch.o gain_q.o gains_tab.o \
 	gc_pred.o gmed_n.o graytab.o hp_max.o inv_sqrt.o log2.o lsfwt.o \
-	lsp_lsf.o mac_32.o oper_32b.o pow2.o prmno.o q_gain_c.o q_gain_p.o \
-	q_plsf.o q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o qgain475.o \
-	qgain795.o qua_gain.o qua_gain_tab.o reorder.o s10_8pf.o set_sign.o \
-	sqrt_l.o tls_flags.o window.o
+	lsp_az.o lsp_lsf.o mac_32.o oper_32b.o pow2.o prmno.o q_gain_c.o \
+	q_gain_p.o q_plsf.o q_plsf3_tab.o q_plsf5_tab.o q_plsf_3.o q_plsf_5.o \
+	qgain475.o qgain795.o qua_gain.o qua_gain_tab.o reorder.o s10_8pf.o \
+	set_sign.o sqrt_l.o tls_flags.o window.o
 HDRS=	namespace.h
 LIB=	libtwamr.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/lsp_az.c	Mon May 06 05:31:47 2024 +0000
@@ -0,0 +1,159 @@
+/*
+********************************************************************************
+*
+*      GSM AMR-NB speech codec   R98   Version 7.6.0   December 12, 2001
+*                                R99   Version 3.3.0                
+*                                REL-4 Version 4.1.0                
+*
+********************************************************************************
+*
+*      File             : lsp_az.c
+*      Purpose          : Converts from the line spectral pairs (LSP) to
+*                       : LP coefficients, for a 10th order filter.
+*      Description      : 
+*                 - Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol)
+*                 - Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1}
+*                 - A(z) = ( F1(z) + F2(z) ) / 2
+*
+********************************************************************************
+*/
+/*
+********************************************************************************
+*                         MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+#include "namespace.h"
+#include "lsp_az.h"
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "no_count.h"
+
+/*
+********************************************************************************
+*                         LOCAL VARIABLES AND TABLES
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+*                         LOCAL PROGRAM CODE
+********************************************************************************
+*/
+/*************************************************************************
+ *
+ *  FUNCTION:  Get_lsp_pol
+ *
+ *  PURPOSE:  Find the polynomial F1(z) or F2(z) from the LSPs.
+ *            If the LSP vector is passed at address 0  F1(z) is computed
+ *            and if it is passed at address 1  F2(z) is computed.
+ *
+ *  DESCRIPTION:
+ *       This is performed by expanding the product polynomials:
+ *
+ *           F1(z) =   product   ( 1 - 2 lsp[i] z^-1 + z^-2 )
+ *                   i=0,2,4,6,8
+ *           F2(z) =   product   ( 1 - 2 lsp[i] z^-1 + z^-2 )
+ *                   i=1,3,5,7,9
+ *
+ *       where lsp[] is the LSP vector in the cosine domain.
+ *
+ *       The expansion is performed using the following recursion:
+ *
+ *            f[0] = 1
+ *            b = -2.0 * lsp[0]
+ *            f[1] = b
+ *            for i=2 to 5 do
+ *               b = -2.0 * lsp[2*i-2];
+ *               f[i] = b*f[i-1] + 2.0*f[i-2];
+ *               for j=i-1 down to 2 do
+ *                   f[j] = f[j] + b*f[j-1] + f[j-2];
+ *               f[1] = f[1] + b;
+ *
+ *************************************************************************/
+
+static void Get_lsp_pol (Word16 *lsp, Word32 *f)
+{
+    Word16 i, j, hi, lo;
+    Word32 t0;
+    
+    /* f[0] = 1.0;             */
+    *f = L_mult (4096, 2048);              move32 (); 
+    f++;                                   move32 (); 
+    *f = L_msu ((Word32) 0, *lsp, 512);    /* f[1] =  -2.0 * lsp[0];  */
+    f++;                                   move32 (); 
+    lsp += 2;                              /* Advance lsp pointer     */
+
+    for (i = 2; i <= 5; i++)
+    {
+        *f = f[-2];                        move32 (); 
+
+        for (j = 1; j < i; j++, f--)
+        {
+            L_Extract (f[-1], &hi, &lo);
+            t0 = Mpy_32_16 (hi, lo, *lsp); /* t0 = f[-1] * lsp    */
+            t0 = L_shl (t0, 1);
+            *f = L_add (*f, f[-2]);        move32 (); /* *f += f[-2]      */
+            *f = L_sub (*f, t0);move32 (); /* *f -= t0            */
+        }
+        *f = L_msu (*f, *lsp, 512);        move32 (); /* *f -= lsp<<9     */
+        f += i;                            /* Advance f pointer   */
+        lsp += 2;                          /* Advance lsp pointer */
+    }
+
+    return;
+}
+
+/*
+********************************************************************************
+*                         PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+/*************************************************************************
+ *
+ *  FUNCTION:   Lsp_Az
+ *
+ *  PURPOSE:  Converts from the line spectral pairs (LSP) to
+ *            LP coefficients, for a 10th order filter.
+ *
+ *  DESCRIPTION:
+ *     - Find the coefficients of F1(z) and F2(z) (see Get_lsp_pol)
+ *     - Multiply F1(z) by 1+z^{-1} and F2(z) by 1-z^{-1}
+ *     - A(z) = ( F1(z) + F2(z) ) / 2
+ *
+ *************************************************************************/
+void Lsp_Az (
+    Word16 lsp[],        /* (i)  : line spectral frequencies            */
+    Word16 a[]           /* (o)  : predictor coefficients (order = 10)  */
+)
+{
+    Word16 i, j;
+    Word32 f1[6], f2[6];
+    Word32 t0;
+
+    Get_lsp_pol (&lsp[0], f1);
+    Get_lsp_pol (&lsp[1], f2);
+
+    for (i = 5; i > 0; i--)
+    {
+        f1[i] = L_add (f1[i], f1[i - 1]);    move32 (); /* f1[i] += f1[i-1]; */
+        f2[i] = L_sub (f2[i], f2[i - 1]);    move32 (); /* f2[i] -= f2[i-1]; */
+    }
+
+    a[0] = 4096;                             move16 (); 
+    for (i = 1, j = 10; i <= 5; i++, j--)
+    {
+        t0 = L_add (f1[i], f2[i]);           /* f1[i] + f2[i] */
+        a[i] = extract_l (L_shr_r (t0, 13)); move16 (); 
+        t0 = L_sub (f1[i], f2[i]);           /* f1[i] - f2[i] */
+        a[j] = extract_l (L_shr_r (t0, 13)); move16 (); 
+    }
+
+    return;
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/lsp_az.h	Mon May 06 05:31:47 2024 +0000
@@ -0,0 +1,42 @@
+/*
+********************************************************************************
+*
+*      GSM AMR-NB speech codec   R98   Version 7.6.0   December 12, 2001
+*                                R99   Version 3.3.0                
+*                                REL-4 Version 4.1.0                
+*
+********************************************************************************
+*
+*      File             : lsp_az.h
+*      Purpose          : Converts from the line spectral pairs (LSP) to
+*                       : LP coefficients, for a 10th order filter.
+*
+********************************************************************************
+*/
+#ifndef lsp_az_h
+#define lsp_az_h "$Id $"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+ 
+/*
+********************************************************************************
+*                         DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+ 
+/*
+********************************************************************************
+*                         DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+void Lsp_Az (
+    Word16 lsp[],      /* (i)    : line spectral frequencies                */
+    Word16 a[]         /* (o)    : predictor coefficients (order = 10)      */
+);
+
+#endif
--- a/libtwamr/namespace.list	Mon May 06 05:10:03 2024 +0000
+++ b/libtwamr/namespace.list	Mon May 06 05:31:47 2024 +0000
@@ -23,7 +23,7 @@
 D_plsf_reset D_plsf_5 D_plsf_3 Init_D_plsf_3
 Enc_lag3 Enc_lag6 Ex_ctrl
 G_code G_pitch
-Lsf_lsp Lsp_lsf Reorder_lsf Lsf_wt
+Lsf_lsp Lsp_lsf Reorder_lsf Lsf_wt Lsp_Az
 Q_plsf_reset Q_plsf_3 Q_plsf_5 Qua_gain
 
 agc agc2 agc_reset