changeset 58:d285877fc4cc

libgsmefr: cod_12k2.c compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 25 Nov 2022 18:50:50 +0000
parents e005e7b91f3c
children 8de2f0f9bd78
files libgsmefr/Makefile libgsmefr/cod_12k2.c libgsmefr/memops.h
diffstat 3 files changed, 112 insertions(+), 353 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmefr/Makefile	Fri Nov 25 17:24:48 2022 +0000
+++ b/libgsmefr/Makefile	Fri Nov 25 18:50:50 2022 +0000
@@ -1,11 +1,11 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	agc.o autocorr.o az_lsp.o basicop2.o c1035pf.o dec_create.o \
+OBJS=	agc.o autocorr.o az_lsp.o basicop2.o c1035pf.o cod_12k2.o dec_create.o \
 	enc_create.o frame2params.o params2frame.o sid_class.o sid_insert.o \
 	tls_flags.o
 HDRS=	basic_op.h cnst.h codec.h d_homing.h dec_state.h dtx.h e_homing.h \
-	enc_state.h gains_tb.h gsm_efr.h namespace.h no_count.h oper_32b.h \
-	sig_proc.h typedef.h vad.h
+	enc_state.h gains_tb.h gsm_efr.h memops.h namespace.h no_count.h \
+	oper_32b.h sig_proc.h typedef.h vad.h
 LIB=	libgsmefr.a
 
 INSTALL_PREFIX=	/usr/local
--- a/libgsmefr/cod_12k2.c	Fri Nov 25 17:24:48 2022 +0000
+++ b/libgsmefr/cod_12k2.c	Fri Nov 25 18:50:50 2022 +0000
@@ -15,12 +15,16 @@
 
 ***************************************************************************/
 
+#include "gsm_efr.h"
 #include "typedef.h"
+#include "namespace.h"
 #include "basic_op.h"
 #include "sig_proc.h"
-#include "count.h"
+#include "memops.h"
+#include "no_count.h"
 #include "codec.h"
 #include "cnst.h"
+#include "enc_state.h"
 
 #include "window2.tab"
 
@@ -42,36 +46,6 @@
  *   L_INTERPOL  : Length of filter for interpolation        *
  *-----------------------------------------------------------*/
 
-/*--------------------------------------------------------*
- *         Static memory allocation.                      *
- *--------------------------------------------------------*/
-
- /* Speech vector */
-
-static Word16 old_speech[L_TOTAL];
-static Word16 *speech, *p_window, *p_window_mid;
-Word16 *new_speech;             /* Global variable */
-
- /* Weight speech vector */
-
-static Word16 old_wsp[L_FRAME + PIT_MAX];
-static Word16 *wsp;
-
- /* Excitation vector */
-
-static Word16 old_exc[L_FRAME + PIT_MAX + L_INTERPOL];
-static Word16 *exc;
-
- /* Zero vector */
-
-static Word16 ai_zero[L_SUBFR + MP1];
-static Word16 *zero;
-
- /* Impulse response vector */
-
-static Word16 *h1;
-static Word16 hvec[L_SUBFR * 2];
-
  /* Spectral expansion factors */
 
 static const Word16 F_gamma1[M] =
@@ -85,16 +59,6 @@
     1529, 917, 550, 330, 198
 };
 
- /* Lsp (Line spectral pairs) */
-
-static Word16 lsp_old[M];
-static Word16 lsp_old_q[M];
-
- /* Filter's memory */
-
-static Word16 mem_syn[M], mem_w0[M], mem_w[M];
-static Word16 mem_err[M + L_SUBFR], *error;
-
 /***************************************************************************
  *  FUNCTION:   Init_Coder_12k2
  *
@@ -107,54 +71,36 @@
  *
  ***************************************************************************/
 
-void Init_Coder_12k2 (void)
+void Init_Coder_12k2 (struct EFR_encoder_state *st)
 {
-
-/*--------------------------------------------------------------------------*
- *          Initialize pointers to speech vector.                           *
- *--------------------------------------------------------------------------*/
-
-    new_speech = old_speech + L_TOTAL - L_FRAME;/* New speech     */
-    speech = new_speech;                        /* Present frame  */
-    p_window = old_speech + L_TOTAL - L_WINDOW; /* For LPC window */
-    p_window_mid = p_window;                    /* For LPC window */
-
-    /* Initialize static pointers */
-
-    wsp = old_wsp + PIT_MAX;
-    exc = old_exc + PIT_MAX + L_INTERPOL;
-    zero = ai_zero + MP1;
-    error = mem_err + M;
-    h1 = &hvec[L_SUBFR];
-
     /* Static vectors to zero */
 
-    Set_zero (old_speech, L_TOTAL);
-    Set_zero (old_exc, PIT_MAX + L_INTERPOL);
-    Set_zero (old_wsp, PIT_MAX);
-    Set_zero (mem_syn, M);
-    Set_zero (mem_w, M);
-    Set_zero (mem_w0, M);
-    Set_zero (mem_err, M);
-    Set_zero (zero, L_SUBFR);
-    Set_zero (hvec, L_SUBFR);   /* set to zero "h1[-L_SUBFR..-1]" */
+    Set_zero (st->old_speech, L_TOTAL);
+    Set_zero (st->old_exc, PIT_MAX + L_INTERPOL);
+    Set_zero (st->old_wsp, PIT_MAX);
+    Set_zero (st->mem_syn, M);
+    Set_zero (st->mem_w, M);
+    Set_zero (st->mem_w0, M);
+    Set_zero (st->mem_err, M);
+    Set_zero (st->ai_zero + MP1, L_SUBFR);
+    Set_zero (st->hvec, L_SUBFR);   /* set to zero "h1[-L_SUBFR..-1]" */
 
     /* Initialize lsp_old [] */
 
-    lsp_old[0] = 30000;
-    lsp_old[1] = 26000;
-    lsp_old[2] = 21000;
-    lsp_old[3] = 15000;
-    lsp_old[4] = 8000;
-    lsp_old[5] = 0;
-    lsp_old[6] = -8000;
-    lsp_old[7] = -15000;
-    lsp_old[8] = -21000;
-    lsp_old[9] = -26000;
+    st->lsp_old[0] = 30000;
+    st->lsp_old[1] = 26000;
+    st->lsp_old[2] = 21000;
+    st->lsp_old[3] = 15000;
+    st->lsp_old[4] = 8000;
+    st->lsp_old[5] = 0;
+    st->lsp_old[6] = -8000;
+    st->lsp_old[7] = -15000;
+    st->lsp_old[8] = -21000;
+    st->lsp_old[9] = -26000;
 
     /* Initialize lsp_old_q[] */
 
-    Copy (lsp_old, lsp_old_q, M);
+    Copy (st->lsp_old, st->lsp_old_q, M);
 
     return;
 }
@@ -184,10 +130,20 @@
  ***************************************************************************/
 
 void Coder_12k2 (
+    struct EFR_encoder_state *st,
     Word16 ana[],    /* output  : Analysis parameters */
     Word16 synth[]   /* output  : Local synthesis     */
 )
 {
+    /* handy pointers that were static vars in the original code */
+    Word16 *speech = st->old_speech + L_TOTAL - L_FRAME;
+    Word16 *p_window = st->old_speech + L_TOTAL - L_WINDOW;
+    Word16 *wsp = st->old_wsp + PIT_MAX;
+    Word16 *exc = st->old_exc + PIT_MAX + L_INTERPOL;
+    Word16 *zero = st->ai_zero + MP1;
+    Word16 *h1 = st->hvec + L_SUBFR;
+    Word16 *error = st->mem_err + M;
+
     /* LPC coefficients */
 
     Word16 r_l[MP1], r_h[MP1];      /* Autocorrelations lo and hi           */
@@ -218,11 +174,6 @@
 
     Word16 scal_acf, VAD_flag, lags[2], rc[4];
 
-    extern Word16 ptch;
-    extern Word16 txdtx_ctrl, CN_excitation_gain;
-    extern Word32 L_pn_seed_tx;
-    extern Word16 dtx_mode;
-
     /*----------------------------------------------------------------------*
      *  - Perform LPC analysis: (twice per frame)                           *
      *       * autocorrelation + lag windowing                              *
@@ -235,82 +186,44 @@
 
     /* LP analysis centered at 2nd subframe */
 
-
-    scal_acf = Autocorr (p_window_mid, M, r_h, r_l, window_160_80);
+    scal_acf = Autocorr (p_window, M, r_h, r_l, window_160_80);
                                 /* Autocorrelations */
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
     Lag_window (M, r_h, r_l);   /* Lag windowing    */
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    Levinson (r_h, r_l, &A_t[MP1], rc); /* Levinson-Durbin  */
+    Levinson (st, r_h, r_l, &A_t[MP1], rc); /* Levinson-Durbin  */
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    Az_lsp (&A_t[MP1], lsp_mid, lsp_old); /* From A(z) to lsp */
-
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
+    Az_lsp (&A_t[MP1], lsp_mid, st->lsp_old); /* From A(z) to lsp */
 
     /* LP analysis centered at 4th subframe */
 
     /* Autocorrelations */
     scal_acf = Autocorr (p_window, M, r_h, r_l, window_232_8);
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
     Lag_window (M, r_h, r_l);   /* Lag windowing    */
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    Levinson (r_h, r_l, &A_t[MP1 * 3], rc); /* Levinson-Durbin  */
-
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
+    Levinson (st, r_h, r_l, &A_t[MP1 * 3], rc); /* Levinson-Durbin  */
 
     Az_lsp (&A_t[MP1 * 3], lsp_new, lsp_mid); /* From A(z) to lsp */
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    if (dtx_mode == 1)
+    if (st->dtx_mode)
     {
         /* DTX enabled, make voice activity decision */
-        VAD_flag = vad_computation (r_h, r_l, scal_acf, rc, ptch);
-                                                                move16 (); 
-
-        tx_dtx (VAD_flag, &txdtx_ctrl); /* TX DTX handler */
+        VAD_flag = vad_computation (st, r_h, r_l, scal_acf, rc, st->ptch);
+        tx_dtx (st, VAD_flag); /* TX DTX handler */
     }
     else
     {
         /* DTX disabled, active speech in every frame */
         VAD_flag = 1;
-        txdtx_ctrl = TX_VAD_FLAG | TX_SP_FLAG;
+        st->txdtx_ctrl = TX_VAD_FLAG | TX_SP_FLAG;
     }
 
     /* LSP quantization (lsp_mid[] and lsp_new[] jointly quantized) */
 
-    Q_plsf_5 (lsp_mid, lsp_new, lsp_mid_q, lsp_new_q, ana, txdtx_ctrl);
+    Q_plsf_5 (st, lsp_mid, lsp_new, lsp_mid_q, lsp_new_q, ana, st->txdtx_ctrl);
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-    ana += 5;                                                   move16 (); 
+    ana += 5;
 
     /*--------------------------------------------------------------------*
      * Find interpolated LPC parameters in all subframes (both quantized  *
@@ -319,23 +232,15 @@
      * and the quantized interpolated parameters are in array Aq_t[]      *
      *--------------------------------------------------------------------*/
 
-    Int_lpc2 (lsp_old, lsp_mid, lsp_new, A_t);
+    Int_lpc2 (st->lsp_old, lsp_mid, lsp_new, A_t);
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    test (); logic16 (); 
-    if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+    if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
     {
-        Int_lpc (lsp_old_q, lsp_mid_q, lsp_new_q, Aq_t);
+        Int_lpc (st->lsp_old_q, lsp_mid_q, lsp_new_q, Aq_t);
 
         /* update the LSPs for the next frame */
-        for (i = 0; i < M; i++)
-        {
-            lsp_old[i] = lsp_new[i];                            move16 (); 
-            lsp_old_q[i] = lsp_new_q[i];                        move16 (); 
-        }
+        Copy (lsp_new, st->lsp_old, M);
+        Copy (lsp_new_q, st->lsp_old_q, M);
     }
     else
     {
@@ -349,17 +254,10 @@
         }
 
         /* update the LSPs for the next frame */
-        for (i = 0; i < M; i++)
-        {
-            lsp_old[i] = lsp_new[i];                            move16 (); 
-            lsp_old_q[i] = lsp_new[i];                          move16 (); 
-        }
+        Copy (lsp_new, st->lsp_old, M);
+        Copy (lsp_new_q, st->lsp_old_q, M);
     }
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
     /*----------------------------------------------------------------------*
      * - Find the weighted input speech wsp[] for the whole speech frame    *
      * - Find the open-loop pitch delay for first 2 subframes               *
@@ -372,27 +270,11 @@
     {
         Weight_Ai (A, F_gamma1, Ap1);
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
-
         Weight_Ai (A, F_gamma2, Ap2);
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
-
         Residu (Ap1, &speech[i], &wsp[i], L_SUBFR);
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
-
-        Syn_filt (Ap2, &wsp[i], &wsp[i], L_SUBFR, mem_w, 1);
-
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
+        Syn_filt (Ap2, &wsp[i], &wsp[i], L_SUBFR, st->mem_w, 1);
 
         A += MP1;                                               move16 (); 
     }
@@ -401,47 +283,32 @@
 
     T_op = Pitch_ol (wsp, PIT_MIN, PIT_MAX, L_FRAME_BY2);       move16 (); 
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
     lags[0] = T_op;                                             move16 (); 
 
-    test (); logic16 (); 
-    if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+    if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
     {
         /* Range for closed loop pitch search in 1st subframe */
 
         T0_min = sub (T_op, 3);
-        test (); 
-        if (sub (T0_min, PIT_MIN) < 0)
+        if (T0_min < PIT_MIN)
         {
             T0_min = PIT_MIN;                                   move16 (); 
         }
         T0_max = add (T0_min, 6);
-        test (); 
-        if (sub (T0_max, PIT_MAX) > 0)
+        if (T0_max > PIT_MAX)
         {
             T0_max = PIT_MAX;                                   move16 (); 
             T0_min = sub (T0_max, 6);
         }
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
     }
     /* Find open loop pitch lag for last two subframes */
 
     T_op = Pitch_ol (&wsp[L_FRAME_BY2], PIT_MIN, PIT_MAX, L_FRAME_BY2);
-                                                                move16 (); 
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    if (dtx_mode == 1)
+    if (st->dtx_mode)
     {
         lags[1] = T_op;                                         move16 (); 
-        periodicity_update (lags, &ptch);
+        periodicity_update (st, lags);
     }
     /*----------------------------------------------------------------------*
      *          Loop for every subframe in the analysis frame               *
@@ -470,9 +337,7 @@
 
     for (i_subfr = 0; i_subfr < L_FRAME; i_subfr += L_SUBFR)
     {
-
-        test (); logic16 (); 
-        if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+        if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
         {
 
             /*---------------------------------------------------------------*
@@ -481,37 +346,18 @@
 
             Weight_Ai (A, F_gamma1, Ap1);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             Weight_Ai (A, F_gamma2, Ap2);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             /*---------------------------------------------------------------*
              * Compute impulse response, h1[], of weighted synthesis filter  *
              *---------------------------------------------------------------*/
 
-            for (i = 0; i <= M; i++)
-            {
-                ai_zero[i] = Ap1[i];                            move16 (); 
-            }
+            Copy (Ap1, st->ai_zero, M+1);
 
-            Syn_filt (Aq, ai_zero, h1, L_SUBFR, zero, 0);
-
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
+            Syn_filt (Aq, st->ai_zero, h1, L_SUBFR, zero, 0);
 
             Syn_filt (Ap2, h1, h1, L_SUBFR, zero, 0);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
         }
         /*---------------------------------------------------------------*
          *          Find the target vector for pitch search:             *
@@ -519,44 +365,23 @@
 
         Residu (Aq, &speech[i_subfr], res2, L_SUBFR);   /* LPC residual */
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
-
-        test (); logic16 (); 
-        if ((txdtx_ctrl & TX_SP_FLAG) == 0)
+        if ((st->txdtx_ctrl & TX_SP_FLAG) == 0)
         {
             /* Compute comfort noise excitation gain based on
             LP residual energy */
 
-            CN_excitation_gain = compute_CN_excitation_gain (res2);
-            move16 (); 
+            st->CN_excitation_gain = compute_CN_excitation_gain (res2);
         }
         else
         {
             Copy (res2, &exc[i_subfr], L_SUBFR);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
-            Syn_filt (Aq, &exc[i_subfr], error, L_SUBFR, mem_err, 0);
-
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
+            Syn_filt (Aq, &exc[i_subfr], error, L_SUBFR, st->mem_err, 0);
 
             Residu (Ap1, error, xn, L_SUBFR);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
-            Syn_filt (Ap2, xn, xn, L_SUBFR, mem_w0, 0); /* target signal xn[]*/
-
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
+            /* target signal xn[] */
+            Syn_filt (Ap2, xn, xn, L_SUBFR, st->mem_w0, 0);
 
             /*--------------------------------------------------------------*
              *                 Closed-loop fractional pitch search          *
@@ -564,52 +389,35 @@
 
             /* flag for first and 3th subframe */            
             pit_flag = i_subfr;                                 move16 (); 
-            test (); 
             /* set t0_min and t0_max for 3th subf.*/
-            if (sub (i_subfr, L_FRAME_BY2) == 0)
+            if (i_subfr == L_FRAME_BY2)
             {
                 T0_min = sub (T_op, 3);
 
-                test (); 
-                if (sub (T0_min, PIT_MIN) < 0)
+                if (T0_min < PIT_MIN)
                 {
                     T0_min = PIT_MIN;                           move16 (); 
                 }
                 T0_max = add (T0_min, 6);
-                test (); 
-                if (sub (T0_max, PIT_MAX) > 0)
+                if (T0_max > PIT_MAX)
                 {
                     T0_max = PIT_MAX;                           move16 (); 
                     T0_min = sub (T0_max, 6);
                 }
                 pit_flag = 0;                                   move16 (); 
             }
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
 
             T0 = Pitch_fr6 (&exc[i_subfr], xn, h1, L_SUBFR, T0_min, T0_max,
                             pit_flag, &T0_frac);                move16 (); 
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             *ana = Enc_lag6 (T0, &T0_frac, &T0_min, &T0_max, PIT_MIN,
                              PIT_MAX, pit_flag);
-            move16 (); 
-
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
         }
         ana++;
         /* Incrementation of ana is done here to work also
         when no speech activity is present */
 
-        test (); logic16 (); 
-
-        if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+        if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
         {
 
             /*---------------------------------------------------------------*
@@ -623,28 +431,12 @@
 
             Pred_lt_6 (&exc[i_subfr], T0, T0_frac, L_SUBFR);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             Convolve (&exc[i_subfr], h1, y1, L_SUBFR);
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             gain_pit = G_pitch (xn, y1, L_SUBFR);      move16 (); 
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             *ana = q_gain_pitch (&gain_pit);                    move16 (); 
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
         }
         else
         {
@@ -654,9 +446,7 @@
         ana++;                  /* Incrementation of ana is done here to work
                                    also when no speech activity is present */
 
-        test (); logic16 (); 
-
-        if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+        if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
         {
             /* xn2[i]   = xn[i] - y1[i] * gain_pit  */
             /* res2[i] -= exc[i+i_subfr] * gain_pit */
@@ -672,10 +462,6 @@
                 res2[i] = sub (res2[i], extract_h (L_temp));    move16 (); 
             }
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             /*-------------------------------------------------------------*
              * - include pitch contribution into impulse resp. h1[]        *
              *-------------------------------------------------------------*/
@@ -691,29 +477,19 @@
                 h1[i] = add (h1[i], temp);                      move16 (); 
             }
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             /*--------------------------------------------------------------*
              * - Innovative codebook search (find index and gain)           *
              *--------------------------------------------------------------*/
 
             code_10i40_35bits (xn2, res2, h1, code, y2, ana);
-
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
         }
         else
         {
-            build_CN_code (code, &L_pn_seed_tx);
+            build_CN_code (code, &st->L_pn_seed_tx);
         }
         ana += 10;                                              move16 (); 
 
-        test (); logic16 (); 
-        if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+        if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
         {
 
             /*-------------------------------------------------------*
@@ -726,27 +502,14 @@
                 code[i] = add (code[i], temp);                  move16 (); 
             }
 
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
             /*------------------------------------------------------*
              * - Quantization of fixed codebook gain.               *
              *------------------------------------------------------*/
 
             gain_code = G_code (xn2, y2);                       move16 (); 
-
-#if (WMOPS)
-            fwc ();             /* function worst case */
-#endif
-
         }
-        *ana++ = q_gain_code (code, L_SUBFR, &gain_code, txdtx_ctrl, i_subfr);
-        move16 (); 
-
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
+        *ana++ = q_gain_code (st, code, L_SUBFR, &gain_code, st->txdtx_ctrl,
+                              i_subfr);
 
         /*------------------------------------------------------*
          * - Find the total excitation                          *
@@ -766,41 +529,25 @@
             exc[i + i_subfr] = round (L_temp);                  move16 (); 
         }
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
-
-        Syn_filt (Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR, mem_syn, 1);
+        Syn_filt (Aq, &exc[i_subfr], &synth[i_subfr], L_SUBFR, st->mem_syn, 1);
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
-
-        test (); logic16 (); 
-        if ((txdtx_ctrl & TX_SP_FLAG) != 0)
+        if ((st->txdtx_ctrl & TX_SP_FLAG) != 0)
         {
 
             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 (); 
+                st->mem_err[j] = sub (speech[i_subfr + i], synth[i_subfr + i]);
                 temp = extract_h (L_shl (L_mult (y1[i], gain_pit), 3));
                 k = extract_h (L_shl (L_mult (y2[i], gain_code), 5));
-                mem_w0[j] = sub (xn[i], add (temp, k));         move16 (); 
+                st->mem_w0[j] = sub (xn[i], add (temp, k));
             }
         }
         else
         {
-            for (j = 0; j < M; j++)
-            {
-                mem_err[j] = 0;                                 move16 (); 
-                mem_w0[j] = 0;                                  move16 (); 
-            }
+            Set_zero (st->mem_err, M);
+            Set_zero (st->mem_w0, M);
         }
 
-#if (WMOPS)
-        fwc ();                 /* function worst case */
-#endif
         /* interpolated LPC parameters for next subframe */
         A += MP1;                                               move16 (); 
         Aq += MP1;                                              move16 (); 
@@ -812,23 +559,11 @@
      *     speech[], wsp[] and  exc[]                   *
      *--------------------------------------------------*/
 
-    Copy (&old_speech[L_FRAME], &old_speech[0], L_TOTAL - L_FRAME);
-
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
-
-    Copy (&old_wsp[L_FRAME], &old_wsp[0], PIT_MAX);
+    Copy (&st->old_speech[L_FRAME], &st->old_speech[0], L_TOTAL - L_FRAME);
 
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
+    Copy (&st->old_wsp[L_FRAME], &st->old_wsp[0], PIT_MAX);
 
-    Copy (&old_exc[L_FRAME], &old_exc[0], PIT_MAX + L_INTERPOL);
-
-#if (WMOPS)
-    fwc ();                     /* function worst case */
-#endif
+    Copy (&st->old_exc[L_FRAME], &st->old_exc[0], PIT_MAX + L_INTERPOL);
 
     return;
 }
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmefr/memops.h	Fri Nov 25 18:50:50 2022 +0000
@@ -0,0 +1,24 @@
+/*
+ * The original code from ETSI uses its own Copy() and Set_zero()
+ * functions, operating on Word16 elements.  Here we implement them
+ * as static inline functions wrapping around memcpy and memset.
+ */
+
+#include <string.h>
+
+static inline void Copy (
+    const Word16 x[],  /* (i)  : input vector                               */
+    Word16 y[],        /* (o)  : output vector                              */
+    Word16 L           /* (i)  : vector length                              */
+)
+{
+	memcpy(y, x, L * 2);
+}
+
+static inline void Set_zero (
+    Word16 x[],        /* (o)  : vector to clear                            */
+    Word16 L           /* (i)  : length of vector                           */
+)
+{
+	memset(x, 0, L * 2);
+}