changeset 170:a72bbc3ace09

fc-vm2hex utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 22 Mar 2017 08:55:53 +0000
parents 0b4167c0ed52
children f736f3ce8310
files .hgignore miscutil/Makefile miscutil/fc-vm2hex.c
diffstat 3 files changed, 91 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Mon Mar 20 04:24:33 2017 +0000
+++ b/.hgignore	Wed Mar 22 08:55:53 2017 +0000
@@ -23,6 +23,7 @@
 ^miscutil/fc-rgbconv$
 ^miscutil/fc-serterm$
 ^miscutil/fc-tch2fr$
+^miscutil/fc-vm2hex$
 ^miscutil/imei-luhn$
 
 ^ringtools/fc-e1gen$
--- a/miscutil/Makefile	Mon Mar 20 04:24:33 2017 +0000
+++ b/miscutil/Makefile	Wed Mar 22 08:55:53 2017 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	fc-fr2tch fc-rgbconv fc-serterm fc-tch2fr imei-luhn
+PROGS=	fc-fr2tch fc-rgbconv fc-serterm fc-tch2fr fc-vm2hex imei-luhn
 SCRIPTS=c139explore pirexplore
 INSTBIN=/opt/freecalypso/bin
 
@@ -25,6 +25,9 @@
 fc-tch2fr:	${TCH2FR_OBJS}
 	${CC} ${CFLAGS} -o $@ ${TCH2FR_OBJS}
 
+fc-vm2hex:	fc-vm2hex.c
+	${CC} ${CFLAGS} -o $@ $@.c
+
 imei-luhn:	imei-luhn.c
 	${CC} ${CFLAGS} -o $@ $@.c
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/miscutil/fc-vm2hex.c	Wed Mar 22 08:55:53 2017 +0000
@@ -0,0 +1,86 @@
+/*
+ * This utility converts the old-fashioned (non-AMR) voice memo files
+ * read out of FFS into hex strings that can be analyzed by a human
+ * or further fed to fc-tch2fr.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+char *infname;
+FILE *inf, *outf;
+
+static unsigned
+get_word()
+{
+	u_char b[2];
+	int i, c;
+
+	for (i = 0; i < 2; i++) {
+		c = getc(inf);
+		if (c < 0) {
+			fprintf(stderr, "error: premature EOF in %s\n",
+				infname);
+			exit(1);
+		}
+		b[i] = c;
+	}
+	return((b[1] << 8) | b[0]);
+}
+
+convert_speech_sample()
+{
+	u_char bytes[34];
+	int i, dp;
+	unsigned word;
+
+	dp = 0;
+	for (i = 0; i < 17; i++) {
+		word = get_word();
+		bytes[dp++] = word >> 8;
+		bytes[dp++] = word;
+	}
+	for (i = 0; i < 33; i++)
+		fprintf(outf, "%02X", bytes[i]);
+}
+
+main(argc, argv)
+	char **argv;
+{
+	unsigned first_word;
+
+	if (argc < 2 || argc > 3) {
+		fprintf(stderr, "usage: %s infile [outfile]\n", argv[0]);
+		exit(1);
+	}
+	infname = argv[1];
+	inf = fopen(infname, "r");
+	if (!inf) {
+		perror(infname);
+		exit(1);
+	}
+	if (argc > 2) {
+		outf = fopen(argv[2], "w");
+		if (!outf) {
+			perror(argv[2]);
+			exit(1);
+		}
+	} else
+		outf = stdout;
+
+	for (;;) {
+		first_word = get_word();
+		if (first_word == 0xFBFF)	/* SC_VM_END_MASK */
+			break;
+		fprintf(outf, "%04X", first_word);
+		if (first_word & 0x8000) {	/* B_VM_SPEECH */
+			fprintf(outf, " %04X", get_word());
+			fprintf(outf, " %04X", get_word());
+			putc(' ', outf);
+			convert_speech_sample();
+		}
+		putc('\n', outf);
+	}
+	exit(0);
+}