changeset 620:8aacb33fb767

libgsmhr1: integrate sp_sfrm.c
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 05 Mar 2026 21:47:27 +0000
parents 8fadd238642b
children d04015a2e076
files libgsmhr1/Makefile libgsmhr1/namespace.list libgsmhr1/sp_sfrm.c libgsmhr1/sp_sfrm.h
diffstat 4 files changed, 35 insertions(+), 60 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmhr1/Makefile	Thu Mar 05 20:43:50 2026 +0000
+++ b/libgsmhr1/Makefile	Thu Mar 05 21:47:27 2026 +0000
@@ -2,11 +2,12 @@
 	dtx_rxfe.o enc_out_order.o enc_state.o err_conc.o mathdp31.o mathhalf.o\
 	pack_frame.o paramval_cod.o paramval_common.o paramval_dec.o rtp_in.o \
 	rtp_in_direct.o rxfe.o rxfe_create.o sid_cw_params.o sid_detect.o \
-	sid_reset.o sp_dec.o sp_frm.o sp_rom.o tfo.o twts002_in.o twts002_out.o\
-	unpack_frame.o vad.o
+	sid_reset.o sp_dec.o sp_frm.o sp_rom.o sp_sfrm.o tfo.o twts002_in.o \
+	twts002_out.o unpack_frame.o vad.o
 HDRS=	dec_func.h dec_state.h dtx_const.h dtx_dec.h dtx_enc.h dtx_rxfe.h \
 	enc_out_order.h enc_state.h err_conc.h mathdp31.h mathhalf.h \
-	namespace.h rxfe.h sp_frm.h sp_rom.h tw_gsmhr.h typedefs.h vad.h
+	namespace.h rxfe.h sp_frm.h sp_rom.h sp_sfrm.h tw_gsmhr.h typedefs.h \
+	vad.h
 LIB=	libgsmhr1.a
 
 include ../config.defs
--- a/libgsmhr1/namespace.list	Thu Mar 05 20:43:50 2026 +0000
+++ b/libgsmhr1/namespace.list	Thu Mar 05 21:47:27 2026 +0000
@@ -44,3 +44,6 @@
 weightSpeechFrame getSfrmLpcTx fnBest_CG compResidEnergy r0Quant cov32 flat
 openLoopLagSearch getCCThreshold pitchLags CGInterpValid CGInterp quantLag
 findBestInQuantList findPeak bestDelta maxCCOverGWithSign getNWCoefs
+
+g_corr2 closedLoopLagSearch decorr g_quant_vl gainTweak hnwFilt sfrmAnalysis
+v_srch
--- a/libgsmhr1/sp_sfrm.c	Thu Mar 05 20:43:50 2026 +0000
+++ b/libgsmhr1/sp_sfrm.c	Thu Mar 05 21:47:27 2026 +0000
@@ -30,10 +30,13 @@
  |_________________________________________________________________________|
 */
 
-#include <stdio.h>
+#include <stddef.h>
+#include "typedefs.h"
+#include "namespace.h"
 #include "mathhalf.h"
 #include "sp_rom.h"
-#include "sp_dec.h"
+#include "dec_func.h"
+#include "enc_state.h"
 #include "sp_frm.h"
 #include "sp_sfrm.h"
 
@@ -60,16 +63,6 @@
 #define MAX_CANDIDATE   6              /* maximum number of lag candidates */
 
 
-/*_________________________________________________________________________
- |                                                                         |
- |                     State variables (globals)                           |
- |_________________________________________________________________________|
-*/
-
-Shortword pswLtpStateBase[LTP_LEN + S_LEN];
-Shortword pswHState[NP];
-Shortword pswHNWState[HNW_BUFF_LEN];
-
 /***************************************************************************
  *
  *   FUNCTION NAME: closedLoopLagSearch
@@ -1396,31 +1389,16 @@
  *
  **************************************************************************/
 
-void   sfrmAnalysis(Shortword *pswWSpeech,
-                           Shortword swVoicingMode,
-                           struct NormSw snsSqrtRs,
-                           Shortword *pswHCoefs,
-                           Shortword *pswLagList,
-                           short siNumLags,
-                           Shortword swPitch,
-                           Shortword swHNWCoef,
-                           short *psiLagCode,
-                           short *psiVSCode1,
-                           short *psiVSCode2,
-                           short *psiGsp0Code,
-                           Shortword swSP)
+void sfrmAnalysis(struct gsmhr_encoder_state *st, Shortword *pswWSpeech,
+		  Shortword swVoicingMode, struct NormSw snsSqrtRs,
+		  Shortword *pswHCoefs, Shortword *pswLagList, short siNumLags,
+		  Shortword swPitch, Shortword swHNWCoef, short *psiLagCode,
+		  short *psiVSCode1, short *psiVSCode2, short *psiGsp0Code,
+		  Shortword swSP, int giSfrmCnt, short *psiPrevLagCode)
 {
 
 /*_________________________________________________________________________
  |                                                                         |
- |                            Static Variables                             |
- |_________________________________________________________________________|
-*/
-
-  static short siPrevLagCode;
-
-/*_________________________________________________________________________
- |                                                                         |
  |                            Automatic Variables                          |
  |_________________________________________________________________________|
 */
@@ -1464,7 +1442,7 @@
  |_________________________________________________________________________|
 */
 
-  pswLtpStateOut = pswLtpStateBase + LTP_LEN;
+  pswLtpStateOut = st->pswLtpStateBase + LTP_LEN;
 
   if (swSP == 1)                                             /* DTX mode */ 
   {                                                          /* DTX mode */   
@@ -1475,7 +1453,7 @@
     /* Get the zero-input response of H(z) */
     /*-------------------------------------*/
 
-    lpcZiIir(pswHCoefs, pswHState, pswTempVec);
+    lpcZiIir(pswHCoefs, st->pswHState, pswTempVec);
 
     /* Subtract the zero-input response of H(z) from W(z)-weighted speech. */
     /* The result is the vector to match for the adaptive codebook (long-  */
@@ -1541,7 +1519,7 @@
       /*---------------------------------------------------------------*/
 
       siCode = closedLoopLagSearch(pswLagList, siNumLags,
-                                   pswLtpStateBase, pswHCoefs, pswWSVec,
+                                   st->pswLtpStateBase, pswHCoefs, pswWSVec,
                                    &swLag, &swLtpShift);
 
       /* Construct frame-lag code if this is the first subframe, */
@@ -1553,14 +1531,14 @@
 
         if (giSfrmCnt == 0)
         {
-          siPrevLagCode = siCode;
+          *psiPrevLagCode = siCode;
           *psiLagCode = siCode;
         }
         else
         {
 
-          *psiLagCode = add(sub(siCode, siPrevLagCode), DELTA_LEVELS / 2);
-          siPrevLagCode = siCode;
+          *psiLagCode = add(sub(siCode, *psiPrevLagCode), DELTA_LEVELS / 2);
+          *psiPrevLagCode = siCode;
         }
       }
 
@@ -1600,7 +1578,7 @@
       hnwFilt(pswWSpeech, pswWSVec, &pswWSpeech[-1], pswHNWCoefs,
               siHnwOffset, 1, S_LEN);
 
-      hnwFilt(pswTempVec, pswTempVec, &pswHNWState[HNW_BUFF_LEN - 1],
+      hnwFilt(pswTempVec, pswTempVec, &st->pswHNWState[HNW_BUFF_LEN - 1],
               pswHNWCoefs, siHnwOffset, 1, S_LEN);
 
       for (i = 0; i < S_LEN; i++)
@@ -1888,14 +1866,14 @@
   /*----------------------------------------------------------------*/
 
   for (i = 0; i < HNW_BUFF_LEN - S_LEN; i++)
-    pswHNWState[i] = pswHNWState[i + S_LEN];
+    st->pswHNWState[i] = st->pswHNWState[i + S_LEN];
 
   /* Second, perform H(z) filter on excitation, output goes into */
   /* C(z) state                                                  */
   /*-------------------------------------------------------------*/
 
-  lpcIir(pswTempVec, pswHCoefs, pswHState,
-         &pswHNWState[HNW_BUFF_LEN - S_LEN]);
+  lpcIir(pswTempVec, pswHCoefs, st->pswHState,
+         &st->pswHNWState[HNW_BUFF_LEN - S_LEN]);
 
 }                                      /* end of sfrmAnalysis() */
 
--- a/libgsmhr1/sp_sfrm.h	Thu Mar 05 20:43:50 2026 +0000
+++ b/libgsmhr1/sp_sfrm.h	Thu Mar 05 21:47:27 2026 +0000
@@ -9,6 +9,13 @@
  |_________________________________________________________________________|
 */
 
+void sfrmAnalysis(struct gsmhr_encoder_state *st, Shortword *pswWSpeech,
+		  Shortword swVoicingMode, struct NormSw snsSqrtRs,
+		  Shortword *pswHCoefs, Shortword *pswLagList, short siNumLags,
+		  Shortword swPitch, Shortword swHNWCoef, short *psiLagCode,
+		  short *psiVSCode1, short *psiVSCode2, short *psiGsp0Code,
+		  Shortword swSP, int giSfrmCnt, short *psiPrevLagCode);
+
 Shortword g_corr2(Shortword *pswIn, Shortword *pswIn2,
                          Longword *pL_out);
 
@@ -44,20 +51,6 @@
                         Shortword swZeroState,
                         int iNumSamples);
 
-  void   sfrmAnalysis(Shortword *pswWSpeech,
-                             Shortword swVoicingMode,
-                             struct NormSw snsSqrtRs,
-                             Shortword *pswHCoefs,
-                             Shortword *pswLagList,
-                             short siNumLags,
-                             Shortword swPitch,
-                             Shortword swHNWCoef,
-                             short *psiLagCode,
-                             short *psiVSCode1,
-                             short *psiVSCode2,
-                             short *psiGsp0Code,
-                             Shortword swSP);
-
   Shortword v_srch(Shortword pswWInput[],
                           Shortword pswWBasisVecs[],
                           short int siNumBasis);