changeset 43:8bfc517fda3b

efr-sid: hack created
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 05:57:48 +0000
parents 982169986a14
children 0b1c4960e5e9
files .hgignore efr-sid/Makefile efr-sid/etsi-bit-rd.c efr-sid/etsi.h efr-sid/mk-sid-test.c efr-sid/sidbits.c
diffstat 6 files changed, 180 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Jun 09 05:28:22 2024 +0000
+++ b/.hgignore	Sun Jun 09 05:57:48 2024 +0000
@@ -24,6 +24,8 @@
 ^dmw/gen-dmw-bin$
 ^dmw/dmw-[au]law\.
 
+^efr-sid/mk-sid-test$
+
 ^pcma2efr/all-outputs\.
 ^pcma2efr/comb-diff$
 ^pcma2efr/comb-out$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efr-sid/Makefile	Sun Jun 09 05:57:48 2024 +0000
@@ -0,0 +1,16 @@
+CC=	gcc
+CFLAGS=	-O2
+PROG=	mk-sid-test
+INPUT=	dtx01-frame71.cod
+OUTPUT=	efr-sid-test.gsmx
+
+all:	${PROG} ${OUTPUT}
+
+${PROG}:	${PROG}.o etsi-bit-rd.o sidbits.o
+	${CC} ${CFLAGS} -o $@ $^
+
+${OUTPUT}:	${PROG} ${INPUT}
+	./${PROG} ${INPUT} ${OUTPUT}
+
+clean:
+	rm -f ${PROG} *.o *.gsmx
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efr-sid/etsi-bit-rd.c	Sun Jun 09 05:57:48 2024 +0000
@@ -0,0 +1,83 @@
+/*
+ * In this module we implement utility functions for reading ETSI *.cod
+ * and *.dec files in either LE or BE format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include <gsm_efr.h>
+#include "etsi.h"
+
+read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs)
+	FILE *inf;
+	uint8_t *bitvec;
+	unsigned nwords;
+	char *filename_for_errs;
+{
+	uint8_t file_bytes[ETSI_DEC_NWORDS * 2], *sp;
+	int cc;
+	unsigned n, upper;
+
+	cc = fread(file_bytes, 2, nwords, inf);
+	if (cc == 0)
+		return 0;
+	if (cc != nwords) {
+		fprintf(stderr, "error: short read from %s\n",
+			filename_for_errs);
+		exit(1);
+	}
+	sp = file_bytes;
+	for (n = 0; n < nwords; n++) {
+		if (big_endian) {
+			upper = sp[0];
+			bitvec[n] = sp[1];
+		} else {
+			bitvec[n] = sp[0];
+			upper = sp[1];
+		}
+		if (upper) {
+			fprintf(stderr,
+		"error in %s: non-zero in what should be %s upper byte\n",
+				filename_for_errs, big_endian ? "BE" : "LE");
+			exit(1);
+		}
+		sp += 2;
+	}
+	return 1;
+}
+
+void
+bits2frame(input_bits, frame, filename_for_errs, frame_no)
+	uint8_t *input_bits, *frame;
+	char *filename_for_errs;
+	unsigned frame_no;
+{
+	uint8_t bits[248], *sp, *dp;
+	unsigned nb, byte, mask;
+
+	bits[0] = 1;
+	bits[1] = 1;
+	bits[2] = 0;
+	bits[3] = 0;
+	bcopy(input_bits, bits + 4, 244);
+	sp = bits;
+	dp = frame;
+	for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) {
+		byte = 0;
+		for (mask = 0x80; mask; mask >>= 1) {
+			if (*sp > 1) {
+				fprintf(stderr,
+					"error in %s frame #%u: data bit > 1\n",
+					filename_for_errs, frame_no);
+				exit(1);
+			}
+			if (*sp)
+				byte |= mask;
+			sp++;
+		}
+		*dp++ = byte;
+	}
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efr-sid/etsi.h	Sun Jun 09 05:57:48 2024 +0000
@@ -0,0 +1,4 @@
+/* definitions for ETSI *.cod and *.dec files */
+
+#define	ETSI_ENC_NWORDS	246
+#define	ETSI_DEC_NWORDS	247
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efr-sid/mk-sid-test.c	Sun Jun 09 05:57:48 2024 +0000
@@ -0,0 +1,55 @@
+/*
+ * This program generates a sequence of 95 EFR codec frames that starts
+ * with a perfect SID and is degraded by one bit in the SID field
+ * on every output frame.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <gsm_efr.h>
+#include "etsi.h"
+
+extern const uint8_t SID_codeword_bit_idx[95];
+
+static void
+read_input_file(filename, cod_frame)
+	char *filename;
+	uint8_t *cod_frame;
+{
+	FILE *inf;
+
+	inf = fopen(filename, "r");
+	if (!inf) {
+		perror(filename);
+		exit(1);
+	}
+	read_etsi_bits(inf, 0, cod_frame, ETSI_ENC_NWORDS, filename);
+	fclose(inf);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	uint8_t cod_frame[ETSI_ENC_NWORDS], packed_frame[EFR_RTP_FRAME_LEN];
+	FILE *outf;
+	unsigned nf;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s input.cod output.gsmx\n", argv[0]);
+		exit(1);
+	}
+	read_input_file(argv[1], cod_frame);
+	outf = fopen(argv[2], "w");
+	if (!outf) {
+		perror(argv[2]);
+		exit(1);
+	}
+	for (nf = 0; nf < 95; nf++) {
+		bits2frame(cod_frame, packed_frame, argv[1], 0);
+		fwrite(packed_frame, 1, EFR_RTP_FRAME_LEN, outf);
+		cod_frame[SID_codeword_bit_idx[nf]] = 0;
+	}
+	fclose(outf);
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/efr-sid/sidbits.c	Sun Jun 09 05:57:48 2024 +0000
@@ -0,0 +1,20 @@
+/*
+ * This module (made from gsm-codec-lib/libgsmefr/sid_class.c)
+ * holds the table of SID codeword bit numbers.
+ */
+
+#include <stdint.h>
+
+const uint8_t SID_codeword_bit_idx[95] =
+{
+     45,  46,  48,  49,  50,  51,  52,  53,  54,  55,
+     56,  57,  58,  59,  60,  61,  62,  63,  64,  65,
+     66,  67,  68,  94,  95,  96,  98,  99, 100, 101,
+    102, 103, 104, 105, 106, 107, 108, 109, 110, 111,
+    112, 113, 114, 115, 116, 117, 118, 148, 149, 150,
+    151, 152, 153, 154, 155, 156, 157, 158, 159, 160,
+    161, 162, 163, 164, 165, 166, 167, 168, 169, 170,
+    171, 196, 197, 198, 199, 200, 201, 202, 203, 204,
+    205, 206, 207, 208, 209, 212, 213, 214, 215, 216,
+    217, 218, 219, 220, 221
+};