changeset 111:756605c4850f

libgsmefr: vad.c compiles
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 29 Nov 2022 04:16:33 +0000
parents 913fe3c11890
children 035424a6ca83
files libgsmefr/Makefile libgsmefr/namespace.h libgsmefr/vad.c libgsmefr/vad.h
diffstat 4 files changed, 158 insertions(+), 171 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmefr/Makefile	Tue Nov 29 03:01:38 2022 +0000
+++ b/libgsmefr/Makefile	Tue Nov 29 04:16:33 2022 +0000
@@ -7,7 +7,7 @@
 	inter_6.o inv_sqrt.o lag_wind.o levinson.o log2.o lsp_az.o lsp_lsf.o \
 	oper_32b.o params2frame.o pitch_f6.o pitch_ol.o pow2.o pre_proc.o \
 	pred_lt6.o preemph.o pstfilt2.o q_gains.o q_plsf_5.o reorder.o residu.o\
-	sid_class.o sid_insert.o syn_filt.o tls_flags.o weight_a.o
+	sid_class.o sid_insert.o syn_filt.o tls_flags.o vad.o weight_a.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 memops.h namespace.h no_count.h \
 	oper_32b.h sig_proc.h typedef.h vad.h
--- a/libgsmefr/namespace.h	Tue Nov 29 03:01:38 2022 +0000
+++ b/libgsmefr/namespace.h	Tue Nov 29 04:16:33 2022 +0000
@@ -123,15 +123,4 @@
 
 #define	vad_reset			EFR__vad_reset
 #define	vad_computation			EFR__vad_computation
-#define	energy_computation		EFR__energy_computation
-#define	acf_averaging			EFR__acf_averaging
-#define	predictor_values		EFR__predictor_values
-#define	schur_recursion			EFR__schur_recursion
-#define	step_up				EFR__step_up
-#define	compute_rav1			EFR__compute_rav1
-#define	spectral_comparison		EFR__spectral_comparison
-#define	threshold_adaptation		EFR__threshold_adaptation
-#define	tone_detection			EFR__tone_detection
-#define	vad_decision			EFR__vad_decision
-#define	vad_hangover			EFR__vad_hangover
 #define	periodicity_update		EFR__periodicity_update
--- a/libgsmefr/vad.c	Tue Nov 29 03:01:38 2022 +0000
+++ b/libgsmefr/vad.c	Tue Nov 29 04:16:33 2022 +0000
@@ -40,12 +40,15 @@
  *
  **************************************************************************/
 
+#include "gsm_efr.h"
 #include "typedef.h"
+#include "namespace.h"
 #include "cnst.h"
 #include "basic_op.h"
 #include "oper_32b.h"
-#include "count.h"
+#include "no_count.h"
 #include "vad.h"
+#include "enc_state.h"
 
 /* Constants of VAD hangover addition */
 
@@ -78,19 +81,84 @@
 #define FREQTH 3189
 #define PREDTH 1464
 
-/* Static variables of VAD */
+/* forward declarations for internal functions */
+
+static void energy_computation (
+    Word16 r_h[],
+    Word16 scal_acf,
+    Word16 rvad[],
+    Word16 scal_rvad,
+    Pfloat * acf0,
+    Pfloat * pvad
+);
+
+static void acf_averaging (
+    struct EFR_encoder_state *st,
+    Word16 r_h[],
+    Word16 r_l[],
+    Word16 scal_acf,
+    Word32 L_av0[],
+    Word32 L_av1[]
+);
+
+static void predictor_values (
+    Word32 L_av1[],
+    Word16 rav1[],
+    Word16 *scal_rav1
+);
+
+static void schur_recursion (
+    Word32 L_av1[],
+    Word16 vpar[]
+);
+
+static void step_up (
+    Word16 np,
+    Word16 vpar[],
+    Word16 aav1[]
+);
 
-static Word16 rvad[9], scal_rvad;
-static Pfloat thvad;
-static Word32 L_sacf[27];
-static Word32 L_sav0[36];
-static Word16 pt_sacf, pt_sav0;
-static Word32 L_lastdm;
-static Word16 adaptcount;
-static Word16 burstcount, hangcount;
-static Word16 oldlagcount, veryoldlagcount, oldlag;
+static void compute_rav1 (
+    Word16 aav1[],
+    Word16 rav1[],
+    Word16 *scal_rav1
+);
+
+static Word16 spectral_comparison (
+    struct EFR_encoder_state *st,
+    Word16 rav1[],
+    Word16 scal_rav1,
+    Word32 L_av0[]
+);
 
-Word16 ptch;
+static void threshold_adaptation (
+    struct EFR_encoder_state *st,
+    Word16 stat,
+    Word16 ptch,
+    Word16 tone,
+    Word16 rav1[],
+    Word16 scal_rav1,
+    Pfloat pvad,
+    Pfloat acf0,
+    Word16 rvad[],
+    Word16 *scal_rvad,
+    Pfloat * thvad
+);
+
+static void tone_detection (
+    Word16 rc[],
+    Word16 *tone
+);
+
+static Word16 vad_decision (
+    Pfloat pvad,
+    Pfloat thvad
+);
+
+static Word16 vad_hangover (
+    struct EFR_encoder_state *st,
+    Word16 vvad
+);
 
 /*************************************************************************
  *
@@ -101,50 +169,51 @@
  *
  *************************************************************************/
 
-void vad_reset ()
+void vad_reset (struct EFR_encoder_state *st)
 {
+    struct vad_state *vst = &st->vad;
     Word16 i;
 
     /* Initialize rvad variables */
-    rvad[0] = 0x6000;
+    vst->rvad[0] = 0x6000;
     for (i = 1; i < 9; i++)
     {
-        rvad[i] = 0;
+        vst->rvad[i] = 0;
     }
-    scal_rvad = 7;
+    vst->scal_rvad = 7;
 
     /* Initialize threshold level */
-    thvad.e = 20;               /*** exponent ***/
-    thvad.m = 27083;            /*** mantissa ***/
+    vst->thvad.e = 20;               /*** exponent ***/
+    vst->thvad.m = 27083;            /*** mantissa ***/
 
     /* Initialize ACF averaging variables */
     for (i = 0; i < 27; i++)
     {
-        L_sacf[i] = 0L;
+        vst->L_sacf[i] = 0L;
     }
     for (i = 0; i < 36; i++)
     {
-        L_sav0[i] = 0L;
+        vst->L_sav0[i] = 0L;
     }
-    pt_sacf = 0;
-    pt_sav0 = 0;
+    vst->pt_sacf = 0;
+    vst->pt_sav0 = 0;
 
     /* Initialize spectral comparison variable */
-    L_lastdm = 0L;
+    vst->L_lastdm = 0L;
 
     /* Initialize threshold adaptation variable */
-    adaptcount = 0;
+    vst->adaptcount = 0;
 
     /* Initialize VAD hangover addition variables */
-    burstcount = 0;
-    hangcount = -1;
+    vst->burstcount = 0;
+    vst->hangcount = -1;
 
     /* Initialize periodicity detection variables */
-    oldlagcount = 0;
-    veryoldlagcount = 0;
-    oldlag = 18;
+    vst->oldlagcount = 0;
+    vst->veryoldlagcount = 0;
+    vst->oldlag = 18;
 
-    ptch = 1;
+    st->ptch = 1;
 
     return;
 }
@@ -169,6 +238,7 @@
  ***************************************************************************/
 
 Word16 vad_computation (
+    struct EFR_encoder_state *st,
     Word16 r_h[],
     Word16 r_l[],
     Word16 scal_acf,
@@ -176,19 +246,20 @@
     Word16 ptch
 )
 {
+    struct vad_state *vst = &st->vad;
     Word32 L_av0[9], L_av1[9];
     Word16 vad, vvad, rav1[9], scal_rav1, stat, tone;
     Pfloat acf0, pvad;
 
-    energy_computation (r_h, scal_acf, rvad, scal_rvad, &acf0, &pvad);
-    acf_averaging (r_h, r_l, scal_acf, L_av0, L_av1);
+    energy_computation (r_h, scal_acf, vst->rvad, vst->scal_rvad, &acf0, &pvad);
+    acf_averaging (st, r_h, r_l, scal_acf, L_av0, L_av1);
     predictor_values (L_av1, rav1, &scal_rav1);
-    stat = spectral_comparison (rav1, scal_rav1, L_av0);        move16 (); 
+    stat = spectral_comparison (st, rav1, scal_rav1, L_av0);
     tone_detection (rc, &tone);
-    threshold_adaptation (stat, ptch, tone, rav1, scal_rav1, pvad, acf0,
-                          rvad, &scal_rvad, &thvad);
-    vvad = vad_decision (pvad, thvad);                          move16 (); 
-    vad = vad_hangover (vvad);                                  move16 (); 
+    threshold_adaptation (st, stat, ptch, tone, rav1, scal_rav1, pvad, acf0,
+                          vst->rvad, &vst->scal_rvad, &vst->thvad);
+    vvad = vad_decision (pvad, vst->thvad);
+    vad = vad_hangover (st, vvad);
 
     return vad;
 }
@@ -278,6 +349,7 @@
  ***************************************************************************/
 
 void acf_averaging (
+    struct EFR_encoder_state *st,
     Word16 r_h[],
     Word16 r_l[],
     Word16 scal_acf,
@@ -285,6 +357,7 @@
     Word32 L_av1[]
 )
 {
+    struct vad_state *vst = &st->vad;
     Word32 L_temp;
     Word16 scale;
     Word16 i;
@@ -294,34 +367,32 @@
     for (i = 0; i <= 8; i++)
     {
         L_temp = L_shr (L_Comp (r_h[i], r_l[i]), scale);
-        L_av0[i] = L_add (L_sacf[i], L_temp);           move32 (); 
-        L_av0[i] = L_add (L_sacf[i + 9], L_av0[i]);     move32 (); 
-        L_av0[i] = L_add (L_sacf[i + 18], L_av0[i]);    move32 (); 
-        L_sacf[pt_sacf + i] = L_temp;                   move32 (); 
-        L_av1[i] = L_sav0[pt_sav0 + i];                 move32 (); 
-        L_sav0[pt_sav0 + i] = L_av0[i];                 move32 (); 
+        L_av0[i] = L_add (vst->L_sacf[i], L_temp);
+        L_av0[i] = L_add (vst->L_sacf[i + 9], L_av0[i]);
+        L_av0[i] = L_add (vst->L_sacf[i + 18], L_av0[i]);
+        vst->L_sacf[vst->pt_sacf + i] = L_temp;
+        L_av1[i] = vst->L_sav0[vst->pt_sav0 + i];
+        vst->L_sav0[vst->pt_sav0 + i] = L_av0[i];
     }
 
     /* Update the array pointers */
 
-    test (); 
-    if (sub (pt_sacf, 18) == 0)
+    if (sub (vst->pt_sacf, 18) == 0)
     {
-        pt_sacf = 0;                                    move16 (); 
+        vst->pt_sacf = 0;
     }
     else
     {
-        pt_sacf = add (pt_sacf, 9);
+        vst->pt_sacf = add (vst->pt_sacf, 9);
     }
 
-    test (); 
-    if (sub (pt_sav0, 27) == 0)
+    if (sub (vst->pt_sav0, 27) == 0)
     {
-        pt_sav0 = 0;                                    move16 (); 
+        vst->pt_sav0 = 0;
     }
     else
     {
-        pt_sav0 = add (pt_sav0, 9);
+        vst->pt_sav0 = add (vst->pt_sav0, 9);
     }
 
     return;
@@ -585,11 +656,13 @@
  ***************************************************************************/
 
 Word16 spectral_comparison (
+    struct EFR_encoder_state *st,
     Word16 rav1[],
     Word16 scal_rav1,
     Word32 L_av0[]
 )
 {
+    struct vad_state *vst = &st->vad;
     Word32 L_dm, L_sump, L_temp;
     Word16 stat, sav0[9], shift, divshift, temp;
     Word16 i;
@@ -686,8 +759,8 @@
 
     /*** Compute the difference and save L_dm ***/
 
-    L_temp = L_sub (L_dm, L_lastdm);
-    L_lastdm = L_dm;                                            move32 (); 
+    L_temp = L_sub (L_dm, vst->L_lastdm);
+    vst->L_lastdm = L_dm;
 
     test (); 
     if (L_temp < 0L)
@@ -736,6 +809,7 @@
  ***************************************************************************/
 
 void threshold_adaptation (
+    struct EFR_encoder_state *st,
     Word16 stat,
     Word16 ptch,
     Word16 tone,
@@ -748,6 +822,7 @@
     Pfloat * thvad
 )
 {
+    struct vad_state *vst = &st->vad;
     Word16 comp, comp2;
     Word32 L_temp;
     Word16 temp;
@@ -796,14 +871,13 @@
     test (); 
     if (sub (comp, 1) == 0)
     {
-        adaptcount = 0;                                 move16 (); 
+        vst->adaptcount = 0;
         return;
     }
     /*** Increment adaptcount ***/
 
-    adaptcount = add (adaptcount, 1);
-    test (); 
-    if (sub (adaptcount, 8) <= 0)
+    vst->adaptcount = add (vst->adaptcount, 1);
+    if (sub (vst->adaptcount, 8) <= 0)
     {
         return;
     }
@@ -969,7 +1043,7 @@
 
     /*** Set adaptcount to adp + 1 ***/
 
-    adaptcount = 9;                                     move16 (); 
+    vst->adaptcount = 9;
 
     return;
 }
@@ -1116,29 +1190,29 @@
  ***************************************************************************/
 
 Word16 vad_hangover (
+    struct EFR_encoder_state *st,
     Word16 vvad
 )
 {
-    test (); 
+    struct vad_state *vst = &st->vad;
+
     if (sub (vvad, 1) == 0)
     {
-        burstcount = add (burstcount, 1);
+        vst->burstcount = add (vst->burstcount, 1);
     }
     else
     {
-        burstcount = 0;         move16 (); 
+        vst->burstcount = 0;
     }
 
-    test (); 
-    if (sub (burstcount, BURSTCONST) >= 0)
+    if (sub (vst->burstcount, BURSTCONST) >= 0)
     {
-        hangcount = HANGCONST;  move16 (); 
-        burstcount = BURSTCONST;move16 (); 
+        vst->hangcount = HANGCONST;
+        vst->burstcount = BURSTCONST;
     }
-    test (); 
-    if (hangcount >= 0)
+    if (vst->hangcount >= 0)
     {
-        hangcount = sub (hangcount, 1);
+        vst->hangcount = sub (vst->hangcount, 1);
         return 1;               /* vad = 1 */
     }
     return vvad;                /* vad = vvad */
@@ -1160,63 +1234,60 @@
  ***************************************************************************/
 
 void periodicity_update (
-    Word16 lags[],
-    Word16 *ptch
+    struct EFR_encoder_state *st,
+    Word16 lags[]
 )
 {
+    struct vad_state *vst = &st->vad;
     Word16 minlag, maxlag, lagcount, temp;
     Word16 i;
 
     /*** Run loop for the two halves in the frame ***/
 
-    lagcount = 0;               move16 (); 
+    lagcount = 0;
 
     for (i = 0; i <= 1; i++)
     {
         /*** Search the maximum and minimum of consecutive lags ***/
 
-        test (); 
-        if (sub (oldlag, lags[i]) > 0)
+        if (sub (vst->oldlag, lags[i]) > 0)
         {
-            minlag = lags[i];   move16 (); 
-            maxlag = oldlag;    move16 (); 
+            minlag = lags[i];
+            maxlag = vst->oldlag;
         }
         else
         {
-            minlag = oldlag;    move16 (); 
-            maxlag = lags[i];   move16 (); 
+            minlag = vst->oldlag;
+            maxlag = lags[i];
         }
 
         temp = sub (maxlag, minlag);
 
-        test (); 
         if (sub (temp, LTHRESH) < 0)
         {
             lagcount = add (lagcount, 1);
         }
         /*** Save the current LTP lag ***/
 
-        oldlag = lags[i];       move16 (); 
+        vst->oldlag = lags[i];
     }
 
     /*** Update the veryoldlagcount and oldlagcount ***/
 
-    veryoldlagcount = oldlagcount;
-                                move16 (); 
-    oldlagcount = lagcount;     move16 (); 
+    vst->veryoldlagcount = vst->oldlagcount;
+    vst->oldlagcount = lagcount;
 
     /*** Make ptch decision ready for next frame ***/
 
-    temp = add (oldlagcount, veryoldlagcount);
+    temp = add (vst->oldlagcount, vst->veryoldlagcount);
 
-    test (); 
     if (sub (temp, NTHRESH) >= 0)
     {
-        *ptch = 1;              move16 (); 
+        st->ptch = 1;
     }
     else
     {
-        *ptch = 0;              move16 (); 
+        st->ptch = 0;
     }
 
     return;
--- a/libgsmefr/vad.h	Tue Nov 29 03:01:38 2022 +0000
+++ b/libgsmefr/vad.h	Tue Nov 29 04:16:33 2022 +0000
@@ -19,79 +19,6 @@
     Word16 ptch
 );
 
-void energy_computation (
-    Word16 r_h[],
-    Word16 scal_acf,
-    Word16 rvad[],
-    Word16 scal_rvad,
-    Pfloat * acf0,
-    Pfloat * pvad
-);
-
-void acf_averaging (
-    Word16 r_h[],
-    Word16 r_l[],
-    Word16 scal_acf,
-    Word32 L_av0[],
-    Word32 L_av1[]
-);
-
-void predictor_values (
-    Word32 L_av1[],
-    Word16 rav1[],
-    Word16 *scal_rav1
-);
-
-void schur_recursion (
-    Word32 L_av1[],
-    Word16 vpar[]
-);
-
-void step_up (
-    Word16 np,
-    Word16 vpar[],
-    Word16 aav1[]
-);
-
-void compute_rav1 (
-    Word16 aav1[],
-    Word16 rav1[],
-    Word16 *scal_rav1
-);
-
-Word16 spectral_comparison (
-    Word16 rav1[],
-    Word16 scal_rav1,
-    Word32 L_av0[]
-);
-
-void threshold_adaptation (
-    Word16 stat,
-    Word16 ptch,
-    Word16 tone,
-    Word16 rav1[],
-    Word16 scal_rav1,
-    Pfloat pvad,
-    Pfloat acf0,
-    Word16 rvad[],
-    Word16 *scal_rvad,
-    Pfloat * thvad
-);
-
-void tone_detection (
-    Word16 rc[],
-    Word16 *tone
-);
-
-Word16 vad_decision (
-    Pfloat pvad,
-    Pfloat thvad
-);
-
-Word16 vad_hangover (
-    Word16 vvad
-);
-
 void periodicity_update (
     struct EFR_encoder_state *st,
     Word16 lags[]