changeset 389:9cd332a94c97

libtwamr: integrate lsp_avg.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 06:49:54 +0000
parents 550d3594c878
children bde9f5804670
files libtwamr/Makefile libtwamr/lsp_avg.c libtwamr/lsp_avg.h libtwamr/namespace.list
diffstat 4 files changed, 170 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Mon May 06 06:43:22 2024 +0000
+++ b/libtwamr/Makefile	Mon May 06 06:49:54 2024 +0000
@@ -8,11 +8,11 @@
 	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 int_lpc.o int_lsf.o inter_36.o \
-	inv_sqrt.o lag_wind.o levinson.o log2.o lpc.o lsfwt.o lsp.o lsp_az.o \
-	lsp_lsf.o lsp_tab.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
+	inv_sqrt.o lag_wind.o levinson.o log2.o lpc.o lsfwt.o lsp.o lsp_avg.o \
+	lsp_az.o lsp_lsf.o lsp_tab.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_avg.c	Mon May 06 06:49:54 2024 +0000
@@ -0,0 +1,90 @@
+/*
+*****************************************************************************
+*
+*      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_avg.c
+*      Purpose:         : LSP averaging and history
+*
+*****************************************************************************
+*/
+
+/*
+*****************************************************************************
+*                         MODULE INCLUDE FILE AND VERSION ID
+*****************************************************************************
+*/
+#include "namespace.h"
+#include "lsp_avg.h"
+ 
+/*
+*****************************************************************************
+*                         INCLUDE FILES
+*****************************************************************************
+*/
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "no_count.h"
+#include "q_plsf5_tab.h"
+#include "memops.h"
+
+/*
+*****************************************************************************
+*                         LOCAL VARIABLES AND TABLES
+*****************************************************************************
+*/
+/*
+*****************************************************************************
+*                         PUBLIC PROGRAM CODE
+*****************************************************************************
+*/
+ 
+/*
+**************************************************************************
+*
+*  Function    : lsp_avg_reset
+*  Purpose     : Resets state memory
+*
+**************************************************************************
+*/
+void lsp_avg_reset (lsp_avgState *st)
+{ 
+  Copy(mean_lsf, &st->lsp_meanSave[0], M);
+}
+ 
+/*
+**************************************************************************
+*
+*  Function    : lsp_avg
+*  Purpose     : Calculate the LSP averages
+*
+**************************************************************************
+*/
+
+void lsp_avg (
+    lsp_avgState *st,         /* i/o : State struct                 Q15 */
+    Word16 *lsp               /* i   : state of the state machine   Q15 */
+)
+{
+    Word16 i;
+    Word32 L_tmp;            /* Q31 */
+
+    for (i = 0; i < M; i++) {
+
+       /* mean = 0.84*mean */
+       L_tmp = L_deposit_h(st->lsp_meanSave[i]);
+       L_tmp = L_msu(L_tmp, EXPCONST, st->lsp_meanSave[i]);
+
+       /* Add 0.16 of newest LSPs to mean */
+       L_tmp = L_mac(L_tmp, EXPCONST, lsp[i]);
+
+       /* Save means */
+       st->lsp_meanSave[i] = round(L_tmp);          move16();   /* Q15 */
+    }
+
+    return;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/lsp_avg.h	Mon May 06 06:49:54 2024 +0000
@@ -0,0 +1,74 @@
+/*
+********************************************************************************
+*
+*      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_avg.h
+*      Purpose:         : LSP averaging and history
+*                         The LSPs are averaged over 8 frames
+*
+********************************************************************************
+*/
+#ifndef lsp_avg_h
+#define lsp_avg_h "$Id $"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "cnst.h"
+
+/*
+********************************************************************************
+*                         LOCAL VARIABLES AND TABLES
+********************************************************************************
+*/
+
+#define EXPCONST          5243               /* 0.16 in Q15 */
+ 
+/*
+********************************************************************************
+*                         DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+typedef struct {
+  Word16 lsp_meanSave[M];          /* Averaged LSPs saved for efficiency  */
+} lsp_avgState;
+ 
+/*
+********************************************************************************
+*                         DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+
+/*
+**************************************************************************
+*
+*  Function    : lsp_history_reset
+*  Purpose     : Resets state memory
+*
+**************************************************************************
+*/
+void lsp_avg_reset (
+    lsp_avgState *state
+);
+ 
+/*
+**************************************************************************
+*
+*  Function    : lsp_avg
+*  Purpose     : Calculate the LSP averages
+*
+**************************************************************************
+*/
+void lsp_avg (
+    lsp_avgState *st,     /* i/o : State struct                 Q15 */
+    Word16 *lsp           /* i   : LSP vector                   Q15 */
+);
+#endif
--- a/libtwamr/namespace.list	Mon May 06 06:43:22 2024 +0000
+++ b/libtwamr/namespace.list	Mon May 06 06:49:54 2024 +0000
@@ -40,7 +40,7 @@
 gainQuant gainQuant_reset
 gc_pred gc_pred_copy gc_pred_reset gc_pred_update gc_pred_average_limited
 gmed_n hp_max
-lpc lpc_reset lsp lsp_reset
+lpc lpc_reset lsp lsp_reset lsp_avg lsp_avg_reset
 q_gain_code q_gain_pitch
 
 Bits2prm Prm2bits