changeset 45:5c82f2e56d56

hr-sid: hack created
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 09 Jun 2024 08:57:28 +0000
parents 0b1c4960e5e9
children d5f1b7aa76c4
files .hgignore hr-sid/Makefile hr-sid/sidgen.c
diffstat 3 files changed, 95 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Jun 09 06:00:43 2024 +0000
+++ b/.hgignore	Sun Jun 09 08:57:28 2024 +0000
@@ -5,6 +5,7 @@
 \.inc$
 \.gsm$
 \.gsmx$
+\.hrpf$
 \.robe$
 \.[au]l$
 \.tch$
@@ -25,6 +26,7 @@
 ^dmw/dmw-[au]law\.
 
 ^efr-sid/mk-sid-test$
+^hr-sid/sidgen$
 
 ^pcma2efr/all-outputs\.
 ^pcma2efr/comb-diff$
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hr-sid/Makefile	Sun Jun 09 08:57:28 2024 +0000
@@ -0,0 +1,15 @@
+CC=	gcc
+CFLAGS=	-O2
+PROG=	sidgen
+OUTPUT=	hr-sid-test.hrpf
+
+all:	${PROG} ${OUTPUT}
+
+${PROG}:	${PROG}.o
+	${CC} ${CFLAGS} -o $@ $^
+
+${OUTPUT}:	${PROG}
+	./${PROG} ${OUTPUT}
+
+clean:
+	rm -f ${PROG} *.o *.hrpf
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hr-sid/sidgen.c	Sun Jun 09 08:57:28 2024 +0000
@@ -0,0 +1,78 @@
+/*
+ * This program generates a sequence of GSM-HR codec frames in raw packed
+ * format (aka TS 101 318) that aims to reverse-engineer the logic of
+ * the SID detector in TI Calypso DSP, and maybe later in historical
+ * E1 BTS implementations too.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+static const uint8_t perfect_sid[14] = {
+	0x11, 0x22, 0x33, 0x44, 0xFF, 0xFF, 0xFF,
+	0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF
+};
+
+static void
+clear_bit(buf, num)
+	uint8_t *buf;
+	unsigned num;
+{
+	unsigned nbyte = num / 8;
+	unsigned nbit = num % 8;
+	unsigned mask = 0x80 >> nbit;
+
+	buf[nbyte] &= ~mask;
+}
+
+static void
+corrupt_class1_bit(buf, num)
+	uint8_t *buf;
+	unsigned num;
+{
+	clear_bit(buf, num + 36);
+}
+
+static void
+corrupt_class2_bit(buf, num)
+	uint8_t *buf;
+	unsigned num;
+{
+	if (num < 8)
+		clear_bit(buf, num + 81);
+	else
+		clear_bit(buf, (num - 8) + 98);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *outf;
+	uint8_t class1[14], class2[14];
+	unsigned n1, n2;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s outfile\n", argv[0]);
+		exit(1);
+	}
+	outf = fopen(argv[1], "w");
+	if (!outf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	bcopy(perfect_sid, class1, 14);
+	for (n1 = 0; n1 < 20; n1++) {
+		bcopy(class1, class2, 14);
+		for (n2 = 0; n2 < 17; n2++) {
+			fwrite(class2, 1, 14, outf);
+			corrupt_class2_bit(class2, n2);
+		}
+		fwrite(class2, 1, 14, outf);
+		corrupt_class1_bit(class1, n1);
+	}
+	fclose(outf);
+	exit(0);
+}