changeset 155:9814041e8096

gsmfr-encode-r utility put together
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 15 Dec 2022 01:30:59 +0000
parents 01ce75ea1c8e
children 3f3674c27840
files .hgignore frtest/Makefile frtest/encode-r.c libtest/Makefile libtest/roberead.c libtest/roberead.h
diffstat 6 files changed, 86 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Wed Dec 14 23:18:18 2022 +0000
+++ b/.hgignore	Thu Dec 15 01:30:59 2022 +0000
@@ -25,6 +25,7 @@
 ^frtest/gsmfr-decode$
 ^frtest/gsmfr-decode-r$
 ^frtest/gsmfr-encode$
+^frtest/gsmfr-encode-r$
 ^frtest/gsmfr-hand-test$
 ^frtest/gsmfr-max-out$
 ^frtest/gsmfr-preproc$
--- a/frtest/Makefile	Wed Dec 14 23:18:18 2022 +0000
+++ b/frtest/Makefile	Thu Dec 15 01:30:59 2022 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-PROGS=	gsmfr-cvt-dlcap gsmfr-decode gsmfr-decode-r gsmfr-encode \
+PROGS=	gsmfr-cvt-dlcap gsmfr-decode gsmfr-decode-r gsmfr-encode gsmfr-encode-r\
 	gsmfr-hand-test gsmfr-max-out gsmfr-preproc
 LIBPP=	../libgsmfrp/libgsmfrp.a
 LIBTEST=../libtest/libtest.a
@@ -23,6 +23,9 @@
 gsmfr-encode:	encode.o ${LIBTEST}
 	${CC} ${CFLAGS} -o $@ encode.o ${LIBTEST} -lgsm
 
+gsmfr-encode-r:	encode-r.o ${LIBTEST}
+	${CC} ${CFLAGS} -o $@ encode-r.o ${LIBTEST} -lgsm
+
 gsmfr-hand-test:	hand-test.o
 	${CC} ${CFLAGS} -o $@ hand-test.o -lgsm
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/frtest/encode-r.c	Thu Dec 15 01:30:59 2022 +0000
@@ -0,0 +1,50 @@
+/*
+ * gsmfr-encode-r is just like gsmfr-encode, but reads the source
+ * linear PCM data to be encoded from a raw BE file ("robe")
+ * instead of WAV.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <gsm.h>
+#include "../libtest/roberead.h"
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *inf, *binf;
+	gsm enc_state;
+	int16_t pcm[160];
+	uint8_t frame[33];
+	int rc;
+
+	if (argc != 3) {
+		fprintf(stderr, "usage: %s input.wav output.gsm\n", argv[0]);
+		exit(1);
+	}
+	inf = fopen(argv[1], "r");
+	if (!inf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	binf = fopen(argv[2], "w");
+	if (!binf) {
+		perror(argv[2]);
+		exit(1);
+	}
+	enc_state = gsm_create();
+	if (!enc_state) {
+		fprintf(stderr, "gsm_create() failed!\n");
+		exit(1);
+	}
+	for (;;) {
+		rc = robe_get_pcm_block(inf, pcm);
+		if (!rc)
+			break;
+		gsm_encode(enc_state, pcm, frame);
+		fwrite(frame, 1, sizeof frame, binf);
+	}
+	fclose(binf);
+	exit(0);
+}
--- a/libtest/Makefile	Wed Dec 14 23:18:18 2022 +0000
+++ b/libtest/Makefile	Thu Dec 15 01:30:59 2022 +0000
@@ -1,6 +1,6 @@
 CC=	gcc
 CFLAGS=	-O2
-OBJS=	binreader.o parse_dlcap.o pcmwrite.o robewrite.o wavrdhelp.o \
+OBJS=	binreader.o parse_dlcap.o pcmwrite.o roberead.o robewrite.o wavrdhelp.o\
 	wavreader.o wavwriter.o
 LIB=	libtest.a
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtest/roberead.c	Thu Dec 15 01:30:59 2022 +0000
@@ -0,0 +1,24 @@
+/*
+ * Here we implement our PCM read helper function for "robe" format.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include "roberead.h"
+
+int robe_get_pcm_block(FILE *inf, int16_t *pcm)
+{
+	uint8_t bytes[320], *dp;
+	int cc, i;
+
+	cc = fread(bytes, 1, 320, inf);
+	cc >>= 1;
+	dp = bytes;
+	for (i = 0; i < cc; i++) {
+		pcm[i] = (dp[0] << 8) | dp[1];
+		dp += 2;
+	}
+	while (i < 160)
+		pcm[i++] = 0;
+	return cc;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libtest/roberead.h	Thu Dec 15 01:30:59 2022 +0000
@@ -0,0 +1,6 @@
+/*
+ * This header file declares the interface to our helper function
+ * for reading 16-bit linear PCM samples from a "robe" input file.
+ */
+
+extern int robe_get_pcm_block(FILE *inf, int16_t *pcmbuf);