changeset 15:528eef871e23

pcmu2efr project started
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 16 Apr 2024 23:30:49 +0000
parents ec642bde2349
children 17d8ff0944a8
files .hgignore pcmu2efr/Makefile pcmu2efr/gen-efr.c pcmu2efr/gen160.c pcmu2efr/seqsyncu.c pcmu2efr/stdefr-out.c pcmu2efr/ulaw-expand.c
diffstat 7 files changed, 180 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/.hgignore	Sun Apr 07 19:44:50 2024 +0000
+++ b/.hgignore	Tue Apr 16 23:30:49 2024 +0000
@@ -9,6 +9,8 @@
 ^dmw/gen-dmw-bin$
 ^dmw/dmw-[au]law\.
 
+^pcmu2efr/stdefr-out$
+
 ^ringing/genring$
 ^ringing/ringing\.
 ^ringing/ringing-efr\.
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/Makefile	Tue Apr 16 23:30:49 2024 +0000
@@ -0,0 +1,13 @@
+CC=	gcc
+CFLAGS=	-O2
+PROGS=	stdefr-out
+
+STDEFR_OBJS=	gen-efr.o gen160.o seqsyncu.o stdefr-out.o ulaw-expand.o
+
+all:	${PROGS}
+
+stdefr-out:	${STDEFR_OBJS}
+	${CC} ${CFLAGS} -o $@ ${STDEFR_OBJS} -lgsmefr
+
+clean:
+	rm -f *.o ${PROGS}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/gen-efr.c	Tue Apr 16 23:30:49 2024 +0000
@@ -0,0 +1,32 @@
+/*
+ * The code in this module takes linear_inputs[][] from gen160.c
+ * and generates standard EFR-encoded frames.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+#include <gsm_efr.h>
+
+extern uint16_t linear_inputs[160][160];
+
+uint8_t standard_efr[160][31];
+
+void
+generate_std_efr(void)
+{
+	struct EFR_encoder_state *st;
+	unsigned m;
+
+	st = EFR_encoder_create(0);
+	if (!st) {
+		fprintf(stderr, "error: EFR_encoder_create() failed\n");
+		exit(1);
+	}
+	for (m = 0; m < 160; m++) {
+		EFR_encoder_reset(st, 0);
+		EFR_encode_frame(st, (const int16_t *) linear_inputs[m],
+				 standard_efr[m], (int *) 0, (int *) 0);
+	}
+	free(st);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/gen160.c	Tue Apr 16 23:30:49 2024 +0000
@@ -0,0 +1,41 @@
+/*
+ * The code in this module generates 160 versions of linearized seqsyncu,
+ * shifted by one sample each, intended for feeding to EFR and AMR encoders.
+ */
+
+#include <stdint.h>
+
+extern const uint8_t seqsyncu_last_frame[160];
+extern const uint16_t pcmu_decode_table[256];
+
+uint16_t linear_inputs[160][160];
+
+static void
+gen_first_seq(void)
+{
+	unsigned n;
+
+	for (n = 0; n < 160; n++)
+		linear_inputs[0][n] = pcmu_decode_table[seqsyncu_last_frame[n]];
+}
+
+static void
+gen_sequence_m(unsigned m)
+{
+	unsigned n, s;
+
+	for (n = 0; n < m; n++)
+		linear_inputs[m][n] = 0x0008;
+	for (s = 0; n < 160; n++, s++)
+		linear_inputs[m][n] = linear_inputs[0][s];
+}
+
+void
+generate_linear_inputs(void)
+{
+	unsigned m;
+
+	gen_first_seq();
+	for (m = 1; m < 160; m++)
+		gen_sequence_m(m);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/seqsyncu.c	Tue Apr 16 23:30:49 2024 +0000
@@ -0,0 +1,20 @@
+/*
+ * The frame of 160 PCMU samples that is captured here in C hex array form
+ * appears in seqsyncu.inp (the last frame after 3 EHFs) inside ZIP archive
+ * ef_syn_u.exe on Disk 7 of GSM-EFR test sequence set.
+ */
+
+#include <stdint.h>
+
+const uint8_t seqsyncu_last_frame[160] = {
+0x1F,0xB3,0x05,0x00,0xA7,0xAF,0x8E,0x14,0x0E,0x03,0x97,0x02,0x83,0x26,0xA8,0x0B,
+0x0F,0x85,0x01,0x07,0x09,0xA1,0x81,0x95,0xA8,0x0F,0x8C,0x43,0x48,0x85,0x03,0x0A,
+0x2B,0x9E,0x0F,0x8B,0x06,0x1E,0x9B,0x18,0x08,0x35,0x98,0x9D,0x9F,0x1B,0x9A,0x8D,
+0x09,0x25,0xA4,0x9F,0x10,0xA3,0x84,0xC8,0x31,0x09,0x2B,0x0B,0xAE,0x5E,0x8B,0x1F,
+0xA5,0x05,0x89,0x07,0x87,0x0E,0x3B,0x87,0xC2,0x0D,0x85,0x33,0x1A,0x23,0x42,0x04,
+0x8C,0x09,0xEE,0x16,0xDC,0xFE,0x30,0x43,0x9F,0x14,0x94,0x82,0x96,0x98,0x82,0x0F,
+0x35,0x00,0x9C,0x01,0x89,0xCF,0x1E,0x18,0x08,0x09,0x82,0x93,0x01,0x81,0x84,0x88,
+0x8A,0x26,0x85,0x16,0x9D,0xC0,0x84,0x97,0x2E,0x05,0x0D,0xA2,0x0A,0x13,0x08,0x87,
+0x99,0x8D,0x12,0x93,0xAF,0x1D,0x82,0xBC,0x8B,0x16,0x19,0x8E,0x17,0x17,0x1E,0xA8,
+0x01,0x99,0x83,0x8B,0x03,0x94,0x0C,0x8A,0x17,0x11,0x1D,0x83,0x86,0x87,0x1A,0x81,
+};
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/stdefr-out.c	Tue Apr 16 23:30:49 2024 +0000
@@ -0,0 +1,31 @@
+/*
+ * This program computes 160 possible EFR encoder outputs using standard EFR,
+ * and writes the result out to a gsmx file.
+ */
+
+#include <stdio.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+extern uint8_t standard_efr[160][31];
+
+main(argc, argv)
+	char **argv;
+{
+	FILE *outf;
+
+	if (argc != 2) {
+		fprintf(stderr, "usage: %s gsmx-out-file\n", argv[0]);
+		exit(1);
+	}
+	generate_linear_inputs();
+	generate_std_efr();
+	outf = fopen(argv[1], "w");
+	if (!outf) {
+		perror(argv[1]);
+		exit(1);
+	}
+	fwrite(standard_efr, 31, 160, outf);
+	fclose(outf);
+	exit(0);
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/pcmu2efr/ulaw-expand.c	Tue Apr 16 23:30:49 2024 +0000
@@ -0,0 +1,41 @@
+/*
+ * This module holds the table for expanding from 8-bit PCMU
+ * to 16-bit linear PCM.
+ */
+
+#include <stdint.h>
+
+const uint16_t pcmu_decode_table[256] = {
+	33412, 34436, 35460, 36484, 37508, 38532, 39556, 40580,
+	41604, 42628, 43652, 44676, 45700, 46724, 47748, 48772,
+	49540, 50052, 50564, 51076, 51588, 52100, 52612, 53124,
+	53636, 54148, 54660, 55172, 55684, 56196, 56708, 57220,
+	57604, 57860, 58116, 58372, 58628, 58884, 59140, 59396,
+	59652, 59908, 60164, 60420, 60676, 60932, 61188, 61444,
+	61636, 61764, 61892, 62020, 62148, 62276, 62404, 62532,
+	62660, 62788, 62916, 63044, 63172, 63300, 63428, 63556,
+	63652, 63716, 63780, 63844, 63908, 63972, 64036, 64100,
+	64164, 64228, 64292, 64356, 64420, 64484, 64548, 64612,
+	64660, 64692, 64724, 64756, 64788, 64820, 64852, 64884,
+	64916, 64948, 64980, 65012, 65044, 65076, 65108, 65140,
+	65164, 65180, 65196, 65212, 65228, 65244, 65260, 65276,
+	65292, 65308, 65324, 65340, 65356, 65372, 65388, 65404,
+	65416, 65424, 65432, 65440, 65448, 65456, 65464, 65472,
+	65480, 65488, 65496, 65504, 65512, 65520, 65528,     0,
+	32124, 31100, 30076, 29052, 28028, 27004, 25980, 24956,
+	23932, 22908, 21884, 20860, 19836, 18812, 17788, 16764,
+	15996, 15484, 14972, 14460, 13948, 13436, 12924, 12412,
+	11900, 11388, 10876, 10364,  9852,  9340,  8828,  8316,
+	 7932,  7676,  7420,  7164,  6908,  6652,  6396,  6140,
+	 5884,  5628,  5372,  5116,  4860,  4604,  4348,  4092,
+	 3900,  3772,  3644,  3516,  3388,  3260,  3132,  3004,
+	 2876,  2748,  2620,  2492,  2364,  2236,  2108,  1980,
+	 1884,  1820,  1756,  1692,  1628,  1564,  1500,  1436,
+	 1372,  1308,  1244,  1180,  1116,  1052,   988,   924,
+	  876,   844,   812,   780,   748,   716,   684,   652,
+	  620,   588,   556,   524,   492,   460,   428,   396,
+	  372,   356,   340,   324,   308,   292,   276,   260,
+	  244,   228,   212,   196,   180,   164,   148,   132,
+	  120,   112,   104,    96,    88,    80,    72,    64,
+	   56,    48,    40,    32,    24,    16,     8,     0,
+};