changeset 404:a37687c6ff22

libtwamr: integrate spstproc.c
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 06 May 2024 23:17:09 +0000
parents 7e0aeab69b10
children 8fff74ca83e8
files libtwamr/Makefile libtwamr/namespace.list libtwamr/spstproc.c libtwamr/spstproc.h
diffstat 4 files changed, 220 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Mon May 06 23:11:34 2024 +0000
+++ b/libtwamr/Makefile	Mon May 06 23:17:09 2024 +0000
@@ -14,7 +14,8 @@
 	prmno.o pstfilt.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 residu.o s10_8pf.o set_sign.o sid_sync.o \
-	spreproc.o sqrt_l.o syn_filt.o tls_flags.o weight_a.o window.o
+	spreproc.o spstproc.o sqrt_l.o syn_filt.o tls_flags.o weight_a.o \
+	window.o
 HDRS=	namespace.h
 LIB=	libtwamr.a
 
--- a/libtwamr/namespace.list	Mon May 06 23:11:34 2024 +0000
+++ b/libtwamr/namespace.list	Mon May 06 23:17:09 2024 +0000
@@ -65,7 +65,7 @@
 
 Cb_gain_average Cb_gain_average_reset
 MR475_update_unq_pred MR475_gain_quant MR795_gain_quant
-subframePreProc
+subframePreProc subframePostProc
 
 calc_unfilt_energies calc_filt_energies calc_target_energy
 code_2i40_9bits code_2i40_11bits code_3i40_14bits code_4i40_17bits
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/spstproc.c	Mon May 06 23:17:09 2024 +0000
@@ -0,0 +1,160 @@
+/*
+********************************************************************************
+*
+*      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             : subframePostProc.c
+*      Purpose          : Subframe post processing
+*
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+*                         MODULE INCLUDE FILE AND VERSION ID
+********************************************************************************
+*/
+#include "namespace.h"
+#include "spstproc.h"
+
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "basic_op.h"
+#include "oper_32b.h"
+#include "no_count.h"
+#include "syn_filt.h"
+#include "cnst.h"
+
+/*
+********************************************************************************
+*                         LOCAL VARIABLES AND TABLES
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+*                         PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+int subframePostProc(
+    Word16 *speech,   /* i   : speech segment                        */
+    enum Mode mode,   /* i   : coder mode                            */
+    Word16 i_subfr,   /* i   : Subframe nr                           */
+    Word16 gain_pit,  /* i   : Pitch gain                       Q14  */
+    Word16 gain_code, /* i   : Decoded innovation gain               */
+    Word16 *Aq,       /* i   : A(z) quantized for the 4 subframes    */
+    Word16 synth[],   /* i   : Local snthesis                        */
+    Word16 xn[],      /* i   : Target vector for pitch search        */
+    Word16 code[],    /* i   : Fixed codebook exitation              */
+    Word16 y1[],      /* i   : Filtered adaptive exitation           */
+    Word16 y2[],      /* i   : Filtered fixed codebook excitation    */
+    Word16 *mem_syn,  /* i/o : memory of synthesis filter            */
+    Word16 *mem_err,  /* o   : pointer to error signal               */
+    Word16 *mem_w0,   /* o   : memory of weighting filter            */
+    Word16 *exc,      /* o   : long term prediction residual         */
+    Word16 *sharp     /* o   : pitch sharpening value                */
+)
+{
+   Word16 i, j, k;
+   Word16 temp;
+   Word32 L_temp;
+   Word16 tempShift;
+   Word16 kShift;
+   Word16 pitch_fac;
+
+   test ();
+   if (sub(mode, MR122) != 0)
+   {
+      tempShift = 1;                     move16 ();
+      kShift = 2;                        move16 ();
+      pitch_fac = gain_pit;              move16 ();
+   }
+   else
+   {
+      tempShift = 2;                     move16 ();
+      kShift = 4;                        move16 ();
+      pitch_fac = shr (gain_pit, 1);
+   }
+   
+   /*------------------------------------------------------------*
+    * - Update pitch sharpening "sharp" with quantized gain_pit  *
+    *------------------------------------------------------------*/
+   
+   *sharp = gain_pit;                    move16 ();
+   test ();
+   if (sub(*sharp, SHARPMAX) > 0)
+   {
+      *sharp = SHARPMAX;                 move16 ();
+   }
+   /*------------------------------------------------------*
+    * - Find the total excitation                          *
+    * - find synthesis speech corresponding to exc[]       *
+    * - update filters memories for finding the target     *
+    *   vector in the next subframe                        *
+    *   (update error[-m..-1] and mem_w_err[])             *
+    *------------------------------------------------------*/
+
+   for (i = 0; i < L_SUBFR; i++) {
+      /* exc[i] = gain_pit*exc[i] + gain_code*code[i]; */
+
+      /*
+       *                      12k2  others
+       * ---------------------------------
+       * exc                   Q0      Q0
+       * gain_pit              Q14     Q14
+       * pitch_fac             Q13     Q14
+       *    product:           Q14     Q15
+       *                               
+       * code                  Q12     Q13
+       * gain_code             Q1      Q1
+       *    product            Q14     Q15
+       *    sum                Q14     Q15
+       *                               
+       * tempShift             2       1
+       *    sum<<tempShift     Q16     Q16
+       * result -> exc         Q0      Q0
+       */
+      L_temp = L_mult (exc[i + i_subfr], pitch_fac);
+      L_temp = L_mac (L_temp, code[i], gain_code);
+      L_temp = L_shl (L_temp, tempShift);
+      exc[i + i_subfr] = round (L_temp);              move16 ();
+   }
+
+   Syn_filt(Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR,
+            mem_syn, 1);
+
+   for (i = L_SUBFR - M, j = 0; i < L_SUBFR; i++, j++) {
+       mem_err[j] = sub(speech[i_subfr + i],
+                        synth[i_subfr + i]);          move16 ();
+      /*
+       *                      12k2  others
+       * ---------------------------------
+       * y1                    Q0      Q0
+       * gain_pit              Q14     Q14
+       *    product            Q15     Q15
+       *    shifted prod.      Q16     Q16
+       * temp                  Q0      Q0
+       *                                
+       * y2                    Q10     Q12
+       * gain_code             Q1      Q1
+       *    product            Q12     Q14
+       * kshift                 4       2
+       *    shifted prod.      Q16     Q16
+       * k                     Q0      Q0
+       * mem_w0,xn,sum         Q0      Q0
+       */
+      temp = extract_h(L_shl(L_mult(y1[i], gain_pit), 1));
+      k = extract_h(L_shl(L_mult(y2[i], gain_code), kShift));
+      mem_w0[j] = sub(xn[i], add(temp, k));          move16 ();
+   }
+
+   return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/spstproc.h	Mon May 06 23:17:09 2024 +0000
@@ -0,0 +1,57 @@
+/*
+********************************************************************************
+*
+*      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             : subframePostProc.h
+*      Purpose          : Subframe post processing
+*
+********************************************************************************
+*/
+#ifndef spstproc_h
+#define spstproc_h "$Id $"
+
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "tw_amr.h"
+#include "typedef.h"
+
+/*
+********************************************************************************
+*                         LOCAL VARIABLES AND TABLES
+********************************************************************************
+*/
+
+/*
+********************************************************************************
+*                         PUBLIC PROGRAM CODE
+********************************************************************************
+*/
+
+int subframePostProc(
+    Word16 *speech,   /* i   : speech segment                        */
+    enum Mode mode,   /* i   : coder mode                            */
+    Word16 i_subfr,   /* i   : Subframe nr                           */
+    Word16 gain_pit,  /* i   : Pitch gain                       Q14  */
+    Word16 gain_code, /* i   : Decoded innovation gain               */
+    Word16 *Aq,       /* i   : A(z) quantized for the 4 subframes    */
+    Word16 synth[],   /* i   : Local snthesis                        */
+    Word16 xn[],      /* i   : Target vector for pitch search        */
+    Word16 code[],    /* i   : Fixed codebook exitation              */
+    Word16 y1[],      /* i   : Filtered adaptive exitation           */
+    Word16 y2[],      /* i   : Filtered fixed codebook excitation    */
+    Word16 *mem_syn,  /* i/o : memory of synthesis filter            */
+    Word16 *mem_err,  /* o   : pointer to error signal               */
+    Word16 *mem_w0,   /* o   : memory of weighting filter            */
+    Word16 *exc,      /* o   : long term prediction residual         */
+    Word16 *sharp     /* o   : pitch sharpening value                */
+);
+
+#endif