diff libgsmhr1/enc_state.c @ 610:d18efcba03bc

libgsmhr1: capture speech encoder state
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 05 Mar 2026 00:56:30 +0000
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgsmhr1/enc_state.c	Thu Mar 05 00:56:30 2026 +0000
@@ -0,0 +1,43 @@
+/*
+ * Here we implement gsmhr_encoder_create() and gsmhr_encoder_reset()
+ * functions: allocation and initialization of speech encoder state.
+ */
+
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include "tw_gsmhr.h"
+#include "typedefs.h"
+#include "namespace.h"
+#include "enc_state.h"
+
+struct gsmhr_encoder_state *gsmhr_encoder_create(int dtx)
+{
+	struct gsmhr_encoder_state *st;
+
+	st = malloc(sizeof(struct gsmhr_encoder_state));
+	if (st)
+		gsmhr_encoder_reset(st, dtx);
+	return st;
+}
+
+static void vad_init_nonzero(struct vad_state *vst)
+{
+	vst->pswRvad[0] = 24576;
+	vst->swNormRvad = 7;
+	vst->swE_thvad = 21;
+	vst->swM_thvad = 21875;
+	vst->swHangCount = -1;
+	vst->swOldLag = 21;
+}
+
+void gsmhr_encoder_reset(struct gsmhr_encoder_state *st, int dtx)
+{
+	int i;
+
+	memset(st, 0, sizeof(struct gsmhr_encoder_state));
+	st->dtx_mode = dtx;
+	vad_init_nonzero(&st->vad);
+	st->swPtch = 1;
+	st->swNElapsed = 50;
+}