changeset 153:14b627682458

gsmfr-decode-r utility put together
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 14 Dec 2022 23:11:20 +0000
parents a217a6eacbad
children 01ce75ea1c8e
files .hgignore frtest/Makefile frtest/decode-r.c libtest/Makefile libtest/robewrite.c libtest/robewrite.h
diffstat 6 files changed, 111 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Dec 14 22:40:31 2022 +0000
+++ b/.hgignore	Wed Dec 14 23:11:20 2022 +0000
@@ -22,6 +22,7 @@
 
 ^frtest/gsmfr-cvt-dlcap$
 ^frtest/gsmfr-decode$
+^frtest/gsmfr-decode-r$
 ^frtest/gsmfr-encode$
 ^frtest/gsmfr-hand-test$
 ^frtest/gsmfr-max-out$
--- a/frtest/Makefile	Wed Dec 14 22:40:31 2022 +0000
+++ b/frtest/Makefile	Wed Dec 14 23:11:20 2022 +0000
@@ -1,7 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	gsmfr-cvt-dlcap gsmfr-decode gsmfr-encode gsmfr-hand-test gsmfr-max-out\
-	gsmfr-preproc
+PROGS=	gsmfr-cvt-dlcap gsmfr-decode gsmfr-decode-r gsmfr-encode \
+	gsmfr-hand-test gsmfr-max-out gsmfr-preproc
 LIBPP=	../libgsmfrp/libgsmfrp.a
 LIBTEST=../libtest/libtest.a
 LIBDEC=	${LIBTEST} ${LIBPP}
@@ -17,6 +17,9 @@
 gsmfr-decode:	decode.o ${LIBDEC}
 	${CC} ${CFLAGS} -o $@ decode.o ${LIBDEC} -lgsm
 
+gsmfr-decode-r:	decode-r.o ${LIBDEC}
+	${CC} ${CFLAGS} -o $@ decode-r.o ${LIBDEC} -lgsm
+
 gsmfr-encode:	encode.o ${LIBTEST}
 	${CC} ${CFLAGS} -o $@ encode.o ${LIBTEST} -lgsm
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/frtest/decode-r.c	Wed Dec 14 23:11:20 2022 +0000
@@ -0,0 +1,75 @@
+/*
+ * gsmfr-decode-r is like gsmfr-decode, but writes the decoded PCM
+ * output in our "robe" format instead of WAV.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <gsm.h>
+#include "../libgsmfrp/gsm_fr_preproc.h"
+#include "../libtest/binreader.h"
+#include "../libtest/robewrite.h"
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *binf, *outf;
+	gsm dec_state;
+	struct gsmfr_preproc_state *pp_state;
+	uint8_t frame[BINFILE_MAX_FRAME];
+	int16_t pcm[160];
+	int rc, bfi, taf;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s input.gsm output.robe\n", argv[0]);
+		exit(1);
+	}
+	binf = fopen(argv[1], "r");
+	if (!binf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	outf = fopen(argv[2], "w");
+	if (!outf) {
+		perror(argv[2]);
+		exit(1);
+	}
+	dec_state = gsm_create();
+	if (!dec_state) {
+		fprintf(stderr, "gsm_create() failed!\n");
+		exit(1);
+	}
+	pp_state = gsmfr_preproc_create();
+	if (!pp_state) {
+		fprintf(stderr, "gsmfr_preproc_create() failed!\n");
+		exit(1);
+	}
+	for (;;) {
+		rc = binfile_read_frame(binf, frame);
+		if (rc < 0) {
+			fprintf(stderr, "error: garbage in %s\n", argv[1]);
+			exit(1);
+		}
+		if (!rc)
+			break;
+		if (frame[0] == 0xBF) {
+			bfi = 1;
+			taf = frame[1] & 1;
+		} else if ((frame[0] & 0xF0) == 0xD0)
+			bfi = 0;
+		else {
+			fprintf(stderr, "error: %s is not in FR codec format\n",
+				argv[1]);
+			exit(1);
+		}
+		if (bfi)
+			gsmfr_preproc_bfi(pp_state, taf, frame);
+		else
+			gsmfr_preproc_good_frame(pp_state, frame);
+		gsm_decode(dec_state, frame, pcm);
+		write_pcm_to_robe(outf, pcm);
+	}
+	fclose(outf);
+	exit(0);
+}
--- a/libtest/Makefile	Wed Dec 14 22:40:31 2022 +0000
+++ b/libtest/Makefile	Wed Dec 14 23:11:20 2022 +0000
@@ -1,6 +1,7 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	binreader.o parse_dlcap.o pcmwrite.o wavrdhelp.o wavreader.o wavwriter.o
+OBJS=	binreader.o parse_dlcap.o pcmwrite.o robewrite.o wavrdhelp.o \
+	wavreader.o wavwriter.o
 LIB=	libtest.a
 
 all:	${LIB}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtest/robewrite.c	Wed Dec 14 23:11:20 2022 +0000
@@ -0,0 +1,22 @@
+/*
+ * Here we implement our PCM write helper function for "robe" format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include "robewrite.h"
+
+void write_pcm_to_robe(FILE *outf, const int16_t *pcm)
+{
+	uint8_t bytes[320], *dp;
+	int16_t samp;
+	unsigned n;
+
+	dp = bytes;
+	for (n = 0; n < 160; n++) {
+		samp = pcm[n];
+		*dp++ = (samp >> 8) & 0xFF;
+		*dp++ = samp & 0xFF;
+	}
+	fwrite(bytes, 2, 160, outf);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtest/robewrite.h	Wed Dec 14 23:11:20 2022 +0000
@@ -0,0 +1,6 @@
+/*
+ * This header file declares the interface to our helper function
+ * for writing 16-bit linear PCM samples to a "robe" output file.
+ */
+
+extern void write_pcm_to_robe(FILE *outf, const int16_t *pcm);