changeset 355:9beb01439a90

libtwamr: implement DHF check function
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 05 May 2024 21:59:18 +0000
parents e4ce7972737f
children 5ccfe176bae1
files libtwamr/Makefile libtwamr/bitno.c libtwamr/bitno.h libtwamr/dhf_check.c
diffstat 4 files changed, 48 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Sun May 05 21:34:23 2024 +0000
+++ b/libtwamr/Makefile	Sun May 05 21:59:18 2024 +0000
@@ -4,10 +4,10 @@
 	bitno.o bits2prm.o c1035pf.o c2_11pf.o c2_9pf.o c3_14pf.o c4_17pf.o \
 	c8_31pf.o c_g_aver.o calc_cor.o calc_en.o cbsearch.o convolve.o cor_h.o\
 	d1035pf.o d2_11pf.o d2_9pf.o d3_14pf.o d4_17pf.o d8_31pf.o d_gain_c.o \
-	d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o dhf_tables.o gains_tab.o \
-	gc_pred.o gmed_n.o graytab.o inv_sqrt.o log2.o lsp_lsf.o oper_32b.o \
-	pow2.o prmno.o q_plsf3_tab.o q_plsf5_tab.o reorder.o s10_8pf.o \
-	set_sign.o sqrt_l.o tls_flags.o window.o
+	d_gain_p.o d_plsf.o d_plsf_3.o d_plsf_5.o dhf_check.o dhf_tables.o \
+	gains_tab.o gc_pred.o gmed_n.o graytab.o inv_sqrt.o log2.o lsp_lsf.o \
+	oper_32b.o pow2.o prmno.o q_plsf3_tab.o q_plsf5_tab.o reorder.o \
+	s10_8pf.o set_sign.o sqrt_l.o tls_flags.o window.o
 HDRS=	namespace.h
 LIB=	libtwamr.a
 
--- a/libtwamr/bitno.c	Sun May 05 21:34:23 2024 +0000
+++ b/libtwamr/bitno.c	Sun May 05 21:59:18 2024 +0000
@@ -81,7 +81,7 @@
 };
 
 /* overall table with all parameter sizes for all modes */
-const Word16 *bitno[9] = {
+const Word16 * const bitno[9] = {
    bitno_MR475,
    bitno_MR515,
    bitno_MR59,
--- a/libtwamr/bitno.h	Sun May 05 21:34:23 2024 +0000
+++ b/libtwamr/bitno.h	Sun May 05 21:59:18 2024 +0000
@@ -9,7 +9,7 @@
 
 #include "typedef.h"
 
-extern const Word16 *bitno[9];
+extern const Word16 * const bitno[9];
 extern const Word16 prmno[9];
 extern const Word16 prmnofsf[8];
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/dhf_check.c	Sun May 05 21:59:18 2024 +0000
@@ -0,0 +1,42 @@
+/*
+ * This module implements the DHF checking function.
+ */
+
+#include <stdint.h>
+#include <string.h>
+#include "tw_amr.h"
+#include "typedef.h"
+#include "namespace.h"
+#include "bitno.h"
+
+static const Word16 * const dhf_per_mode[8] = {
+	amr_dhf_mr475,
+	amr_dhf_mr515,
+	amr_dhf_mr59,
+	amr_dhf_mr67,
+	amr_dhf_mr74,
+	amr_dhf_mr795,
+	amr_dhf_mr102,
+	amr_dhf_mr122
+};
+
+int amr_check_dhf(const struct amr_param_frame *frame, int first_sub_only)
+{
+	const Word16 *table;
+	Word16 nparam;
+
+	if (frame->type != RX_SPEECH_GOOD)
+		return 0;
+	if ((frame->mode & 0x87) == 0x87)
+		table = amr_dhf_gsmefr;
+	else
+		table = dhf_per_mode[frame->mode & 7];
+	if (first_sub_only)
+		nparam = prmnofsf[frame->mode & 7];
+	else
+		nparam = prmno[frame->mode & 7];
+	if (memcmp(frame->param, table, nparam * sizeof(int16_t)))
+		return 0;
+	else
+		return 1;
+}