changeset 254:f931e704adc5

libtwamr: bits and parameter packing
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 05 Apr 2024 07:41:31 +0000
parents 54f6bc41ed10
children 07f936338de1
files libtwamr/Makefile libtwamr/bitno.c libtwamr/bitno.h libtwamr/bits2prm.c libtwamr/bits2prm.h libtwamr/namespace.h libtwamr/prm2bits.h libtwamr/prmno.c
diffstat 8 files changed, 277 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Fri Apr 05 06:08:15 2024 +0000
+++ b/libtwamr/Makefile	Fri Apr 05 07:41:31 2024 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	a_refl.o agc.o autocorr.o az_lsp.o basicop2.o inv_sqrt.o oper_32b.o \
-	tls_flags.o
+OBJS=	a_refl.o agc.o autocorr.o az_lsp.o basicop2.o bitno.o bits2prm.o \
+	inv_sqrt.o oper_32b.o prmno.o tls_flags.o
 LIB=	libtwamr.a
 
 INSTALL_PREFIX=	/usr/local
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/bitno.c	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,94 @@
+/*
+ * This module holds the bitno[] table (intermodule linkage)
+ * and the set of static per-mode tables referenced from it,
+ * originally in bitno.tab in 3GPP reference source.
+ */
+
+#include "typedef.h"
+#include "namespace.h"
+#include "int_defs.h"
+
+/* parameter sizes (# of bits), one table per mode */
+
+static const Word16 bitno_MR475[PRMNO_MR475] = {
+   8, 8, 7,                                 /* LSP VQ          */
+   8, 7, 2, 8,                              /* first subframe  */
+   4, 7, 2,                                 /* second subframe */
+   4, 7, 2, 8,                              /* third subframe  */
+   4, 7, 2,                                 /* fourth subframe */
+};
+
+static const Word16 bitno_MR515[PRMNO_MR515] = {
+   8, 8, 7,                                 /* LSP VQ          */
+   8, 7, 2, 6,                              /* first subframe  */
+   4, 7, 2, 6,                              /* second subframe */
+   4, 7, 2, 6,                              /* third subframe  */
+   4, 7, 2, 6,                              /* fourth subframe */
+};
+
+static const Word16 bitno_MR59[PRMNO_MR59] = {
+   8, 9, 9,                                 /* LSP VQ          */
+   8, 9, 2, 6,                              /* first subframe  */
+   4, 9, 2, 6,                              /* second subframe */
+   8, 9, 2, 6,                              /* third subframe  */
+   4, 9, 2, 6,                              /* fourth subframe */
+};
+
+static const Word16 bitno_MR67[PRMNO_MR67] = {
+   8, 9, 9,                                 /* LSP VQ          */
+   8, 11, 3, 7,                             /* first subframe  */
+   4, 11, 3, 7,                             /* second subframe */
+   8, 11, 3, 7,                             /* third subframe  */
+   4, 11, 3, 7,                             /* fourth subframe */
+};
+
+static const Word16 bitno_MR74[PRMNO_MR74] = {
+   8, 9, 9,                                 /* LSP VQ          */
+   8, 13, 4, 7,                             /* first subframe  */
+   5, 13, 4, 7,                             /* second subframe */
+   8, 13, 4, 7,                             /* third subframe  */
+   5, 13, 4, 7,                             /* fourth subframe */
+};
+
+static const Word16 bitno_MR795[PRMNO_MR795] = {
+   9, 9, 9,                                 /* LSP VQ          */
+   8, 13, 4, 4, 5,                          /* first subframe  */
+   6, 13, 4, 4, 5,                          /* second subframe */
+   8, 13, 4, 4, 5,                          /* third subframe  */
+   6, 13, 4, 4, 5,                          /* fourth subframe */
+};
+
+static const Word16 bitno_MR102[PRMNO_MR102] = {
+   8, 9, 9,                                 /* LSP VQ          */
+   8, 1, 1, 1, 1, 10, 10, 7, 7,             /* first subframe  */
+   5, 1, 1, 1, 1, 10, 10, 7, 7,             /* second subframe */
+   8, 1, 1, 1, 1, 10, 10, 7, 7,             /* third subframe  */
+   5, 1, 1, 1, 1, 10, 10, 7, 7,             /* fourth subframe */
+};
+
+static const Word16 bitno_MR122[PRMNO_MR122] = {
+   7, 8, 9, 8, 6,                           /* LSP VQ          */
+   9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5,   /* first subframe  */
+   6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5,   /* second subframe */
+   9, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5,   /* third subframe  */
+   6, 4, 4, 4, 4, 4, 4, 3, 3, 3, 3, 3, 5    /* fourth subframe */
+};
+
+static const Word16 bitno_MRDTX[PRMNO_MRDTX] = {
+  3,
+  8, 9, 9,
+  6
+};
+
+/* overall table with all parameter sizes for all modes */
+const Word16 *bitno[9] = {
+   bitno_MR475,
+   bitno_MR515,
+   bitno_MR59,
+   bitno_MR67,
+   bitno_MR74,
+   bitno_MR795,
+   bitno_MR102,
+   bitno_MR122,
+   bitno_MRDTX
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/bitno.h	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,16 @@
+/*
+ * This header file holds extern declarations for the tables
+ * that have been moved from bitno.tab to bitno.c and prmo.c
+ * with intermodule linkage.
+ */
+
+#ifndef	bitno_h
+#define	bitno_h
+
+#include "typedef.h"
+
+extern const Word16 *bitno[9];
+extern const Word16 prmno[9];
+extern const Word16 prmnofsf[8];
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/bits2prm.c	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,28 @@
+/*
+ * A cleaner reimplementation of AMR Bits2prm() function.
+ */
+
+#include "typedef.h"
+#include "namespace.h"
+#include "bitno.h"
+#include "bits2prm.h"
+
+void Bits2prm(enum Mode mode, const Word16 bits[], Word16 prm[])
+{
+	const Word16 *p = bits;
+	const Word16 *t = bitno[mode];
+	unsigned nparam = prmno[mode];
+	unsigned n, m, acc;
+
+	for (n = 0; n < nparam; n++) {
+		acc = 0;
+		for (m = 0; m < *t; m++) {
+			acc <<= 1;
+			if (*p)
+				acc |= 1;
+			p++;
+		}
+		prm[n] = acc;
+		t++;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/bits2prm.h	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,53 @@
+/*
+*****************************************************************************
+*
+*      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             : bits2prm.h
+*      Purpose          : Retrieves the vector of encoder parameters from 
+*                       : the received serial bits in a frame.
+*
+*****************************************************************************
+*/
+#ifndef bits2prm_h
+#define bits2prm_h "$Id $"
+ 
+/*
+*****************************************************************************
+*                         INCLUDE FILES
+*****************************************************************************
+*/
+#include "typedef.h"
+#include "tw_amr.h"	/* for enum Mode */
+/*
+*****************************************************************************
+*                         DEFINITION OF DATA TYPES
+*****************************************************************************
+*/
+ 
+/*
+*****************************************************************************
+*                         DECLARATION OF PROTOTYPES
+*****************************************************************************
+*/
+/*
+**************************************************************************
+*
+*  Function    : Bits2prm
+*  Purpose     : Retrieves the vector of encoder parameters from 
+*                the received serial bits in a frame.
+*  Returns     : void
+*
+**************************************************************************
+*/
+void Bits2prm (
+    enum Mode mode,
+    const Word16 bits[],   /* input : serial bits (max 244)        */
+    Word16 prm[]           /* output: analysis parameters (max 57) */
+);
+ 
+#endif
--- a/libtwamr/namespace.h	Fri Apr 05 06:08:15 2024 +0000
+++ b/libtwamr/namespace.h	Fri Apr 05 07:41:31 2024 +0000
@@ -68,4 +68,11 @@
 #define	agc		AMR__agc
 #define	agc2		AMR__agc2
 
+#define	Bits2prm	AMR__Bits2prm
+#define	Prm2bits	AMR__Prm2bits
+
+#define	bitno		AMR__bitno
+#define	prmno		AMR__prmno
+#define	prmnofs		AMR__prmnofs
+
 #endif	/* include guard */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/prm2bits.h	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,44 @@
+/*
+********************************************************************************
+*
+*      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             : prm2bits.h
+*      Purpose          : Converts the encoder parameter vector into a
+*                       : vector of serial bits.
+*
+********************************************************************************
+*/
+#ifndef prm2bits_h
+#define prm2bits_h "$Id $"
+ 
+/*
+********************************************************************************
+*                         INCLUDE FILES
+********************************************************************************
+*/
+#include "typedef.h"
+#include "tw_amr.h"	/* for enum Mode */
+ 
+/*
+********************************************************************************
+*                         DEFINITION OF DATA TYPES
+********************************************************************************
+*/
+ 
+/*
+********************************************************************************
+*                         DECLARATION OF PROTOTYPES
+********************************************************************************
+*/
+void Prm2bits (
+    enum Mode mode,      /* i : AMR mode */
+    const Word16 prm[],  /* input : analysis parameters                     */
+    Word16 bits[]        /* output: serial bits                             */
+);
+ 
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/prmno.c	Fri Apr 05 07:41:31 2024 +0000
@@ -0,0 +1,33 @@
+/*
+ * This module holds prmno[] and prmnofs[] tables that were
+ * originally in bitno.tab in 3GPP reference source.
+ */
+
+#include "typedef.h"
+#include "namespace.h"
+#include "int_defs.h"
+
+/* number of parameters per modes (values must be <= MAX_PRM_SIZE!) */
+const Word16 prmno[9] = {
+  PRMNO_MR475,
+  PRMNO_MR515,
+  PRMNO_MR59,
+  PRMNO_MR67,
+  PRMNO_MR74,
+  PRMNO_MR795,
+  PRMNO_MR102,
+  PRMNO_MR122,
+  PRMNO_MRDTX
+};
+
+/* number of parameters to first subframe per modes */
+const Word16 prmnofsf[8] = {
+  PRMNOFSF_MR475,
+  PRMNOFSF_MR515,
+  PRMNOFSF_MR59,
+  PRMNOFSF_MR67,
+  PRMNOFSF_MR74,
+  PRMNOFSF_MR795,
+  PRMNOFSF_MR102,
+  PRMNOFSF_MR122
+};