diff miscutil/amr2efr.c @ 101:d86f866489e9

gsm-amr2efr utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Nov 2022 05:15:39 +0000
parents
children dd88f9312170
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/miscutil/amr2efr.c	Sun Nov 27 05:15:39 2022 +0000
@@ -0,0 +1,62 @@
+/*
+ * Our gsm-amr2efr utility reads in a speech recording in .amr format
+ * (the mode must be MR122 for every frame, no DTX) and converts it into
+ * our ad hoc .gsmx format for EFR.  The conversion is a bit reshuffling
+ * only, no transcoding takes place.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+
+extern const uint8_t amr_122_bit_order[244];
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *inf, *outf;
+	int hdrb;
+	uint8_t frm_in[31], frm_out[31];
+	unsigned bit_a, bit_n;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s input.amr output.gsmx\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(argv[1], "r");
+	if (!inf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	outf = fopen(argv[2], "w");
+	if (!outf) {
+		perror(argv[2]);
+		exit(1);
+	}
+	for (;;) {
+		hdrb = getc(inf);
+		if (hdrb < 0)
+			break;
+		if ((hdrb & 0x78) != 0x38) {
+			fprintf(stderr, "error: unexpected content in %s\n",
+				argv[1]);
+			exit(1);
+		}
+		if (fread(frm_in, 1, 31, inf) != 31) {
+			fprintf(stderr, "error: short read from %s\n", argv[1]);
+			exit(1);
+		}
+		bzero(frm_out, 31);
+		frm_out[0] = 0xC0;
+		for (bit_a = 0; bit_a < 244; bit_a++) {
+			bit_n = amr_122_bit_order[bit_a];
+			msb_set_bit(frm_out, 4 + bit_n,
+				    msb_get_bit(frm_in, bit_a));
+		}
+		fwrite(frm_out, 1, 31, outf);
+	}
+	fclose(outf);
+	exit(0);
+}