changeset 530:96c4ed5529bf

libgsmfr2 preproc: implement support for DTXd
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 19 Sep 2024 20:15:54 +0000
parents 79cd992de3ad
children c7b1e796e91b
files libgsmfr2/pp_bad.c libgsmfr2/pp_good.c libgsmfr2/pp_state.h
diffstat 3 files changed, 33 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/libgsmfr2/pp_bad.c	Thu Sep 19 08:07:26 2024 +0000
+++ b/libgsmfr2/pp_bad.c	Thu Sep 19 20:15:54 2024 +0000
@@ -59,35 +59,49 @@
 	case NO_DATA:
 		memcpy(frame, &gsmfr_preproc_silence_frame,
 			GSMFR_RTP_FRAME_LEN);
+		if (st->dtxd_nodata_count) {
+			st->dtxd_sid_flag = 0;
+			st->dtxd_nodata_count--;
+		} else
+			st->dtxd_sid_flag = 1;
 		return;
 	case SPEECH:
 		memcpy(frame, &st->speech_frame, GSMFR_RTP_FRAME_LEN);
 		st->rx_state = SPEECH_MUTING;
+		st->dtxd_sid_flag = 0;
 		return;
 	case SPEECH_MUTING:
 		mute = reduce_xmaxc(st->speech_frame);
 		memcpy(frame, &st->speech_frame, GSMFR_RTP_FRAME_LEN);
 		random_grid_pos(st, frame);
-		if (mute)
+		if (mute) {
 			st->rx_state = NO_DATA;
+			st->dtxd_nodata_count = 0;
+		}
+		st->dtxd_sid_flag = 0;
 		return;
 	case COMFORT_NOISE:
+		st->dtxd_sid_flag = 1;
 		if (taf)
 			st->rx_state = LOST_SID;
 		gsmfr_preproc_gen_cn(st, frame);
 		return;
 	case LOST_SID:
+		st->dtxd_sid_flag = 1;
 		if (taf) {
 			st->rx_state = CN_MUTING;
 			reduce_xmaxc_sid(st);
+			st->dtxd_sid_flag = 0;
 		}
 		gsmfr_preproc_gen_cn(st, frame);
 		return;
 	case CN_MUTING:
+		st->dtxd_sid_flag = 0;
 		if (reduce_xmaxc_sid(st)) {
 			st->rx_state = NO_DATA;
 			memcpy(frame, &gsmfr_preproc_silence_frame,
 				GSMFR_RTP_FRAME_LEN);
+			st->dtxd_nodata_count = 3;
 		} else
 			gsmfr_preproc_gen_cn(st, frame);
 		return;
@@ -102,6 +116,11 @@
 	case NO_DATA:
 		memcpy(frame, &gsmfr_preproc_silence_frame,
 			GSMFR_RTP_FRAME_LEN);
+		if (st->dtxd_nodata_count) {
+			st->dtxd_sid_flag = 0;
+			st->dtxd_nodata_count--;
+		} else
+			st->dtxd_sid_flag = 1;
 		return;
 	case SPEECH:
 		/*
@@ -109,6 +128,7 @@
 		 * "NOTE" at the end of section 6.1.2 in TS 46.031.
 		 */
 		st->rx_state = COMFORT_NOISE;
+		st->dtxd_sid_flag = 1;
 		memcpy(st->sid_prefix, &st->speech_frame, 5);
 		st->sid_xmaxc = gsmfr_preproc_xmaxc_mean(st->speech_frame);
 		gsmfr_preproc_gen_cn(st, frame);
@@ -118,19 +138,25 @@
 		mute = reduce_xmaxc(st->speech_frame);
 		memcpy(frame, &st->speech_frame, GSMFR_RTP_FRAME_LEN);
 		random_grid_pos(st, frame);
-		if (mute)
+		if (mute) {
 			st->rx_state = NO_DATA;
+			st->dtxd_nodata_count = 0;
+		}
+		st->dtxd_sid_flag = 0;
 		return;
 	case COMFORT_NOISE:
 	case LOST_SID:
 		st->rx_state = COMFORT_NOISE;
+		st->dtxd_sid_flag = 1;
 		gsmfr_preproc_gen_cn(st, frame);
 		return;
 	case CN_MUTING:
+		st->dtxd_sid_flag = 0;
 		if (reduce_xmaxc_sid(st)) {
 			st->rx_state = NO_DATA;
 			memcpy(frame, &gsmfr_preproc_silence_frame,
 				GSMFR_RTP_FRAME_LEN);
+			st->dtxd_nodata_count = 3;
 		} else
 			gsmfr_preproc_gen_cn(st, frame);
 		return;
--- a/libgsmfr2/pp_good.c	Thu Sep 19 08:07:26 2024 +0000
+++ b/libgsmfr2/pp_good.c	Thu Sep 19 20:15:54 2024 +0000
@@ -19,6 +19,7 @@
 	switch (sid) {
 	case 0:		/* good speech frame */
 		st->rx_state = SPEECH;
+		st->dtxd_sid_flag = 0;
 		memcpy(&st->speech_frame, frame, GSMFR_RTP_FRAME_LEN);
 		return;
 	case 1:		/* invalid SID frame */
@@ -27,6 +28,7 @@
 		return;
 	case 2:		/* valid SID frame */
 		st->rx_state = COMFORT_NOISE;
+		st->dtxd_sid_flag = 1;
 		gsmfr_preproc_sid2cn(st, frame);
 		return;
 	}
--- a/libgsmfr2/pp_state.h	Thu Sep 19 08:07:26 2024 +0000
+++ b/libgsmfr2/pp_state.h	Thu Sep 19 20:15:54 2024 +0000
@@ -18,7 +18,9 @@
 	uint8_t		sid_prefix[5];
 	uint8_t		sid_xmaxc;
 	uint32_t	cn_random_lfsr;
-	unsigned	cn_random_6fold;
+	uint8_t		cn_random_6fold;
+	uint8_t		dtxd_nodata_count;
+	uint8_t		dtxd_sid_flag;
 };
 
 /* we use the same LFSR PRNG for CN as ETSI EFR implementation */