changeset 363:0349de7c45b7

libtwamr: integrate enc_lag[36].c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 02:46:19 +0000
parents 9cbd1b5d061f
children 3f27ca24c620
files libtwamr/Makefile libtwamr/enc_lag3.c libtwamr/enc_lag3.h libtwamr/enc_lag6.c libtwamr/enc_lag6.h libtwamr/namespace.list
diffstat 6 files changed, 367 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Mon May 06 02:08:43 2024 +0000
+++ b/libtwamr/Makefile	Mon May 06 02:46:19 2024 +0000
@@ -5,10 +5,11 @@
 	c8_31pf.o c_g_aver.o calc_cor.o calc_en.o cbsearch.o convolve.o cor_h.o\
 	d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o d8_31pf.o d_gain_c.o \
 	d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o dec_gain.o dec_lag3.o \
-	dec_lag6.o dhf_check.o dhf_tables.o e_homing.o ec_gains.o gains_tab.o \
-	gc_pred.o gmed_n.o graytab.o inv_sqrt.o log2.o lsp_lsf.o oper_32b.o \
-	pow2.o prmno.o q_plsf3_tab.o q_plsf5_tab.o qua_gain_tab.o reorder.o \
-	s10_8pf.o set_sign.o sqrt_l.o tls_flags.o window.o
+	dec_lag6.o dhf_check.o dhf_tables.o e_homing.o ec_gains.o enc_lag3.o \
+	enc_lag6.o gains_tab.o gc_pred.o gmed_n.o graytab.o inv_sqrt.o log2.o \
+	lsp_lsf.o oper_32b.o pow2.o prmno.o q_plsf3_tab.o q_plsf5_tab.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/enc_lag3.c	Mon May 06 02:46:19 2024 +0000
@@ -0,0 +1,155 @@
+/*
+********************************************************************************
+*
+*      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             : enc_lag3.c
+*      Purpose          : Encoding of fractional pitch lag with 1/3 resolution.
+*
+********************************************************************************
+*/
+/*
+********************************************************************************
+*                         MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+#include "namespace.h"
+#include "enc_lag3.h"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "no_count.h"
+#include "cnst.h"
+
+/*
+********************************************************************************
+*                         PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+/*************************************************************************
+ *
+ *   FUNCTION:  Enc_lag3
+ *
+ *   PURPOSE:  Encoding of fractional pitch lag with 1/3 resolution.
+ *
+ *   DESCRIPTION:
+ *                    First and third subframes:
+ *                    --------------------------
+ *   The pitch range is divided as follows:
+ *           19 1/3  to   84 2/3   resolution 1/3
+ *           85      to   143      resolution 1
+ *
+ *   The period is encoded with 8 bits.
+ *   For the range with fractions:
+ *     index = (T-19)*3 + frac - 1;
+ *                         where T=[19..85] and frac=[-1,0,1]
+ *   and for the integer only range
+ *     index = (T - 85) + 197;        where T=[86..143]
+ *
+ *                    Second and fourth subframes:
+ *                    ----------------------------
+ *   For the 2nd and 4th subframes a resolution of 1/3 is always used,
+ *   and the search range is relative to the lag in previous subframe.
+ *   If t0 is the lag in the previous subframe then
+ *   t_min=t0-5   and  t_max=t0+4   and  the range is given by
+ *        t_min - 2/3   to  t_max + 2/3
+ *
+ *   The period in the 2nd (and 4th) subframe is encoded with 5 bits:
+ *     index = (T-(t_min-1))*3 + frac - 1;
+ *                 where T=[t_min-1..t_max+1]
+ *
+ *************************************************************************/
+Word16
+Enc_lag3(                /* o  : Return index of encoding             */
+    Word16 T0,           /* i  : Pitch delay                          */
+    Word16 T0_frac,      /* i  : Fractional pitch delay               */
+    Word16 T0_prev,      /* i  : Integer pitch delay of last subframe */
+    Word16 T0_min,       /* i  : minimum of search range              */
+    Word16 T0_max,       /* i  : maximum of search range              */
+    Word16 delta_flag,   /* i  : Flag for 1st (or 3rd) subframe       */
+    Word16 flag4         /* i  : Flag for encoding with 4 bits        */
+    )
+{
+   Word16 index, i, tmp_ind, uplag;
+   Word16 tmp_lag;
+   
+   test (); 
+   if (delta_flag == 0)
+   {  /* if 1st or 3rd subframe */
+
+      /* encode pitch delay (with fraction) */
+      
+      test (); 
+      if (sub (T0, 85) <= 0)
+      {
+         /* index = T0*3 - 58 + T0_frac   */
+         i = add (add (T0, T0), T0);
+         index = add (sub (i, 58), T0_frac);
+      }
+      else
+      {
+         index = add (T0, 112);
+      }
+   }
+   else
+   {   /* if second or fourth subframe */
+      test (); 
+      if (flag4 == 0) {
+
+         /* 'normal' encoding: either with 5 or 6 bit resolution */
+
+         /* index = 3*(T0 - T0_min) + 2 + T0_frac */
+         i = sub (T0, T0_min);
+         i = add (add (i, i), i);
+         index = add (add (i, 2), T0_frac);
+      }
+      else {
+         
+         /* encoding with 4 bit resolution */
+         
+         tmp_lag = T0_prev;                                   move16 ();
+
+         test ();
+         if ( sub( sub(tmp_lag, T0_min), 5) > 0)
+            tmp_lag = add (T0_min, 5);
+         test ();
+         if ( sub( sub(T0_max, tmp_lag), 4) > 0)
+            tmp_lag = sub (T0_max, 4);
+         
+         uplag = add (add (add (T0, T0), T0), T0_frac);
+         
+         i = sub (tmp_lag, 2);
+         tmp_ind = add (add (i, i), i);
+         
+         test ();
+         if (sub (tmp_ind, uplag) >= 0) { 
+            index = add (sub (T0, tmp_lag), 5);
+         } 
+         else
+         {
+            i = add (tmp_lag, 1);
+            i = add (add (i, i), i);
+
+            test ();
+            if (sub (i, uplag) > 0) {
+                index = add ( sub (uplag, tmp_ind), 3);                
+            }
+            else {
+               index = add (sub (T0, tmp_lag), 11);
+            }
+         }
+         
+      } /* end if (encoding with 4 bit resolution) */
+   }   /* end if (second of fourth subframe) */
+   
+   return index;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/enc_lag3.h	Mon May 06 02:46:19 2024 +0000
@@ -0,0 +1,47 @@
+/*
+********************************************************************************
+*
+*      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             : enc_lag3.h
+*      Purpose          : Encoding of fractional pitch lag with 1/3 resolution.
+*
+********************************************************************************
+*/
+#ifndef enc_lag3_h
+#define enc_lag3_h "$Id $"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+ 
+/*
+********************************************************************************
+*                         DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+ 
+/*
+********************************************************************************
+*                         DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+Word16
+Enc_lag3(                /* o  : Return index of encoding     */
+    Word16 T0,           /* i  : Pitch delay                          */
+    Word16 T0_frac,      /* i  : Fractional pitch delay               */
+    Word16 T0_prev,      /* i  : Integer pitch delay of last subframe */
+    Word16 T0_min,       /* i  : minimum of search range              */
+    Word16 T0_max,       /* i  : maximum of search range              */
+    Word16 delta_flag,   /* i  : Flag for 1st (or 3rd) subframe       */
+    Word16 flag4         /* i  : Flag for encoding with 4 bits        */
+);
+ 
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/enc_lag6.c	Mon May 06 02:46:19 2024 +0000
@@ -0,0 +1,116 @@
+/*
+********************************************************************************
+*
+*      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             : enc_lag6.c
+*      Purpose          : Encoding of fractional pitch lag with 1/6 resolution.
+*
+********************************************************************************
+*/
+/*
+********************************************************************************
+*                         MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+#include "namespace.h"
+#include "enc_lag6.h"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "no_count.h"
+ 
+/*
+********************************************************************************
+*                         LOCAL VARIABLES AND TABLES
+********************************************************************************
+*/
+ 
+/*
+********************************************************************************
+*                         PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+/*************************************************************************
+ *
+ *   FUNCTION:  Enc_lag6
+ *
+ *   PURPOSE:  Encoding of fractional pitch lag with 1/6 resolution.
+ *
+ *   DESCRIPTION:
+ *                    First and third subframes:
+ *                    --------------------------
+ *   The pitch range is divided as follows:
+ *           17 3/6  to   94 3/6   resolution 1/6
+ *           95      to   143      resolution 1
+ *
+ *   The period is encoded with 9 bits.
+ *   For the range with fractions:
+ *     index = (T-17)*6 + frac - 3;
+ *                         where T=[17..94] and frac=[-2,-1,0,1,2,3]
+ *   and for the integer only range
+ *     index = (T - 95) + 463;        where T=[95..143]
+ *
+ *                    Second and fourth subframes:
+ *                    ----------------------------
+ *   For the 2nd and 4th subframes a resolution of 1/6 is always used,
+ *   and the search range is relative to the lag in previous subframe.
+ *   If t0 is the lag in the previous subframe then
+ *   t_min=t0-5   and  t_max=t0+4   and  the range is given by
+ *       (t_min-1) 3/6   to  (t_max) 3/6
+ *
+ *   The period in the 2nd (and 4th) subframe is encoded with 6 bits:
+ *     index = (T-(t_min-1))*6 + frac - 3;
+ *                 where T=[t_min-1..t_max] and frac=[-2,-1,0,1,2,3]
+ *
+ *   Note that only 61 values are used. If the decoder receives 61, 62,
+ *   or 63 as the relative pitch index, it means that a transmission
+ *   error occurred and the pitch from previous subframe should be used.
+ *
+ *************************************************************************/
+Word16 Enc_lag6 (        /* o : Return index of encoding             */
+    Word16 T0,           /* i : Pitch delay                          */
+    Word16 T0_frac,      /* i : Fractional pitch delay               */
+    Word16 T0_min,       /* i : minimum of search range              */
+    Word16 delta_flag    /* i : Flag for 1st (or 3rd) subframe       */
+)
+{
+    Word16 index, i;
+
+    test (); 
+    if (delta_flag == 0)          /* if 1st or 3rd subframe */
+    {
+       /* encode pitch delay (with fraction) */
+       test (); 
+       if (sub (T0, 94) <= 0)
+       {
+          /* index = T0*6 - 105 + T0_frac */
+          i = add (add (T0, T0), T0);
+          index = add (sub (add (i, i), 105), T0_frac);
+       }
+       else
+       {
+          index = add (T0, 368);
+       }
+       
+    }
+    else
+       /* if second or fourth subframe */
+    {
+       /* index = 6*(T0-T0_min) + 3 + T0_frac  */
+       i = sub (T0, T0_min);
+       i = add (add (i, i), i);
+       index = add (add (add (i, i), 3), T0_frac);
+    }
+    
+    return index;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/enc_lag6.h	Mon May 06 02:46:19 2024 +0000
@@ -0,0 +1,43 @@
+/*
+********************************************************************************
+*
+*      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             : enc_lag6.h
+*      Purpose          : Encoding of fractional pitch lag with 1/6 resolution.
+*
+********************************************************************************
+*/
+#ifndef enc_lag6_h
+#define enc_lag6_h "$Id $"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+ 
+/*
+********************************************************************************
+*                         DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+ 
+/*
+********************************************************************************
+*                         DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+Word16 Enc_lag6 (        /* o  : Return index of encoding             */
+    Word16 T0,           /* i  : Pitch delay                          */
+    Word16 T0_frac,      /* i  : Fractional pitch delay               */
+    Word16 T0_min,       /* i  : minimum of search range              */
+    Word16 delta_flag    /* i  : Flag for 1st (or 3rd) subframe       */
+);
+ 
+#endif
--- a/libtwamr/namespace.list	Mon May 06 02:08:43 2024 +0000
+++ b/libtwamr/namespace.list	Mon May 06 02:46:19 2024 +0000
@@ -20,6 +20,7 @@
 Convolve
 Dec_gain Dec_lag3 Dec_lag6
 D_plsf_reset D_plsf_5 D_plsf_3 Init_D_plsf_3
+Enc_lag3 Enc_lag6
 Lsf_lsp Lsp_lsf Reorder_lsf
 
 agc agc2 agc_reset