changeset 414:028ed5114e52

libtwamr: implement run-time VAD selection scheme
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 07 May 2024 02:06:47 +0000
parents c1bb166f768e
children 01c4becb9fda
files libtwamr/Makefile libtwamr/namespace.list libtwamr/tw_amr.h libtwamr/vad.h libtwamr/vad_reset.c
diffstat 5 files changed, 50 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libtwamr/Makefile	Tue May 07 01:48:28 2024 +0000
+++ b/libtwamr/Makefile	Tue May 07 02:06:47 2024 +0000
@@ -16,7 +16,7 @@
 	q_plsf_3.o q_plsf_5.o qgain475.o qgain795.o qua_gain.o qua_gain_tab.o \
 	r_fft.o reorder.o residu.o s10_8pf.o set_sign.o sid_sync.o spreproc.o \
 	spstproc.o sqrt_l.o syn_filt.o tls_flags.o ton_stab.o vad1.o vad2.o \
-	weight_a.o window.o
+	vad_reset.o weight_a.o window.o
 HDRS=	a_refl.h agc.h autocorr.h az_lsp.h b_cn_cod.h basic_op.h bgnscd.h \
 	bitno.h bits2prm.h c1035pf.h c2_11pf.h c2_9pf.h c3_14pf.h c4_17pf.h \
 	c8_31pf.h c_g_aver.h calc_cor.h calc_en.h cbsearch.h cl_ltp.h cnst.h \
@@ -32,7 +32,7 @@
 	pstfilt.h q_gain_c.h q_gain_p.h q_plsf.h q_plsf3_tab.h q_plsf5_tab.h \
 	qgain475.h qgain795.h qua_gain.h qua_gain_tab.h reorder.h residu.h \
 	s10_8pf.h set_sign.h sid_sync.h spreproc.h spstproc.h sqrt_l.h \
-	syn_filt.h ton_stab.h tw_amr.h typedef.h vad1.h vad2.h weight_a.h \
+	syn_filt.h ton_stab.h tw_amr.h typedef.h vad.h vad1.h vad2.h weight_a.h\
 	window.h
 LIB=	libtwamr.a
 
--- a/libtwamr/namespace.list	Tue May 07 01:48:28 2024 +0000
+++ b/libtwamr/namespace.list	Tue May 07 02:06:47 2024 +0000
@@ -55,7 +55,7 @@
 dtx_enc dtx_enc_reset dtx_buffer tx_dtx_handler
 vad1 vad1_reset vad_complex_detection_update vad_tone_detection
 vad_tone_detection_update vad_pitch_detection
-vad2 vad2_reset r_fft LTP_flag_update
+vad2 vad2_reset r_fft LTP_flag_update vad_reset
 
 Bits2prm Prm2bits
 
--- a/libtwamr/tw_amr.h	Tue May 07 01:48:28 2024 +0000
+++ b/libtwamr/tw_amr.h	Tue May 07 02:06:47 2024 +0000
@@ -59,11 +59,11 @@
 struct amr_encoder_state;	/* opaque to external users */
 struct amr_decoder_state;	/* ditto */
 
-struct amr_encoder_state *amr_encoder_create(int dtx);
+struct amr_encoder_state *amr_encoder_create(int dtx, int use_vad2);
 struct amr_decoder_state *amr_decoder_create(void);
 
 /* reset state to initial */
-void amr_encoder_reset(struct amr_encoder_state *st, int dtx);
+void amr_encoder_reset(struct amr_encoder_state *st, int dtx, int use_vad2);
 void amr_decoder_reset(struct amr_decoder_state *st);
 
 /* interface structure for passing frames of codec parameters */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/vad.h	Tue May 07 02:06:47 2024 +0000
@@ -0,0 +1,26 @@
+/*
+ * In the original 3GPP code, the selection between VAD1 and VAD2 is made
+ * only at compile time.  In libtwamr we support run-time selection between
+ * these two VAD algorithms for tinkering and investigation work; this
+ * header file implements the logic that fits this run-time selection
+ * into the existing code structure from 3GPP.
+ */
+
+#ifndef	vad_h
+#define	vad_h
+
+#include "typedef.h"
+#include "vad1.h"
+#include "vad2.h"
+
+typedef struct {
+	Flag	use_vad2;
+	union {
+		vadState1	v1;
+		vadState2	v2;
+	} u;
+} vadState;
+
+void vad_reset(vadState *st, Flag use_vad2);
+
+#endif	/* include guard */
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtwamr/vad_reset.c	Tue May 07 02:06:47 2024 +0000
@@ -0,0 +1,19 @@
+/*
+ * The vad_reset() function implemented in this module is new with libtwamr,
+ * i.e., it does not originate from 3GPP, even though it is styled after
+ * 3GPP AMR code.  This function initializes our unified vadState structure,
+ * which is a union of vadState1 and vadState2, plus a selection flag.
+ */
+
+#include "typedef.h"
+#include "namespace.h"
+#include "vad.h"
+
+void vad_reset(vadState *st, Flag use_vad2)
+{
+	st->use_vad2 = use_vad2;
+	if (st->use_vad2)
+		vad2_reset(&st->u.v2);
+	else
+		vad1_reset(&st->u.v1);
+}