diff hrutil/cod-out-endian.c @ 609:a2b2ca082dd7 default tip

hrutil: new program gsmhr-tfo-xfrm-dc
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 24 Feb 2026 04:16:57 +0000
parents hrutil/tw5b-out-cod.c@129c895a0564
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hrutil/cod-out-endian.c	Tue Feb 24 04:16:57 2026 +0000
@@ -0,0 +1,34 @@
+/*
+ * The helper function implemented in this module emits an encoder output
+ * array of params (*.cod format) in either BE or LE format.  This helper
+ * function will be used for gsmhr-etsi-enc and gsmhr-tfo-xfrm-dc utilities,
+ * which need to both read and write ETSI-format files that are subject to
+ * endian concerns.
+ */
+
+#include <stdint.h>
+#include <stdio.h>
+#include "../libgsmhr1/tw_gsmhr.h"
+
+void
+emit_cod_to_endian(outf, params, big_endian)
+	FILE *outf;
+	int16_t *params;
+{
+	uint8_t file_bytes[GSMHR_NUM_PARAMS_ENC * 2], *dp;
+	unsigned n;
+	uint16_t val;
+
+	dp = file_bytes;
+	for (n = 0; n < GSMHR_NUM_PARAMS_ENC; n++) {
+		val = params[n];
+		if (big_endian) {
+			*dp++ = val >> 8;
+			*dp++ = val;
+		} else {
+			*dp++ = val;
+			*dp++ = val >> 8;
+		}
+	}
+	fwrite(file_bytes, 2, GSMHR_NUM_PARAMS_ENC, outf);
+}