FreeCalypso > hg > vband-misc
changeset 0:a03c87a2abc6
amrdiff program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 03 Apr 2024 18:44:27 +0000 |
parents | |
children | 33eeeff6ae88 |
files | .hgignore amrdiff/Makefile amrdiff/amr_defs.h amrdiff/amrdiff.c amrdiff/etsi-bit-rd.c amrdiff/etsi.h |
diffstat | 6 files changed, 237 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/.hgignore Wed Apr 03 18:44:27 2024 +0000 @@ -0,0 +1,5 @@ +syntax: regexp + +\.[oa]$ + +^amrdiff/amrdiff$
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrdiff/Makefile Wed Apr 03 18:44:27 2024 +0000 @@ -0,0 +1,12 @@ +CC= gcc +CFLAGS= -O2 +PROG= amrdiff +OBJS= amrdiff.o etsi-bit-rd.o + +all: ${PROG} + +${PROG}: ${OBJS} + ${CC} ${CFLAGS} -o $@ ${OBJS} + +clean: + rm -f *.o ${PROG}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrdiff/amr_defs.h Wed Apr 03 18:44:27 2024 +0000 @@ -0,0 +1,60 @@ +/* + * This header file holds some miscellaneous definitions for AMR, + * to be used by parsing and conversion debug utilities. + */ + +#define MAX_PRM_SIZE 57 /* max. num. of params */ +#define MAX_SERIAL_SIZE 244 /* max. num. of serial bits */ +#define MAX_IF1_BYTES 31 /* max bytes in AMR IF1 packing */ +#define IETF_HDR_LEN 6 /* .amr file header bytes */ + +enum TXFrameType { + TX_SPEECH_GOOD = 0, + TX_SID_FIRST, + TX_SID_UPDATE, + TX_NO_DATA, + TX_SPEECH_DEGRADED, + TX_SPEECH_BAD, + TX_SID_BAD, + TX_ONSET, + TX_N_FRAMETYPES /* number of frame types */ +}; + +enum Mode { + MR475 = 0, + MR515, + MR59, + MR67, + MR74, + MR795, + MR102, + MR122, + MRDTX +}; + +#define MODE_NO_DATA 15 + +/* number of speech bits for all modes */ +#define AMR_NBITS_475 95 +#define AMR_NBITS_515 103 +#define AMR_NBITS_59 118 +#define AMR_NBITS_67 134 +#define AMR_NBITS_74 148 +#define AMR_NBITS_795 159 +#define AMR_NBITS_102 204 +#define AMR_NBITS_122 244 +#define AMR_NBITS_SID 35 + +/* number of distinct parameters for all modes */ +#define PRMNO_MR475 17 +#define PRMNO_MR515 19 +#define PRMNO_MR59 19 +#define PRMNO_MR67 19 +#define PRMNO_MR74 19 +#define PRMNO_MR795 23 +#define PRMNO_MR102 39 +#define PRMNO_MR122 57 +#define PRMNO_MRDTX 5 + +/* ETSI/3GPP test sequence file format */ +#define COD_FORMAT_NWORDS 250
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrdiff/amrdiff.c Wed Apr 03 18:44:27 2024 +0000 @@ -0,0 +1,106 @@ +/* + * This program reads two ETSI/3GPP test sequence files, one from + * the AMR set of 3GPP TS 26.074 and the other from the "EFR2" set of + * amr122_efr.zip, and performs a diff between them. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "etsi.h" +#include "amr_defs.h" + +main(argc, argv) + char **argv; +{ + char *amr_filename, *efr_filename; + int amr_be, efr_be; + FILE *inf_amr, *inf_efr; + unsigned frame_no; + uint8_t amr_bits[COD_FORMAT_NWORDS], efr_bits[ETSI_ENC_NWORDS]; + int rc_amr, rc_efr, amr_sp, efr_sp; + + if (argc != 5) { +usage: fprintf(stderr, + "usage: %s amr-cod-file be|le efr-cod-file be|le\n", + argv[0]); + exit(1); + } + amr_filename = argv[1]; + if (!strcmp(argv[2], "be")) + amr_be = 1; + else if (!strcmp(argv[2], "le")) + amr_be = 0; + else + goto usage; + efr_filename = argv[3]; + if (!strcmp(argv[4], "be")) + efr_be = 1; + else if (!strcmp(argv[4], "le")) + efr_be = 0; + else + goto usage; + inf_amr = fopen(amr_filename, "r"); + if (!inf_amr) { + perror(amr_filename); + exit(1); + } + inf_efr = fopen(efr_filename, "r"); + if (!inf_efr) { + perror(efr_filename); + exit(1); + } + for (frame_no = 0; ; frame_no++) { + rc_amr = read_etsi_bits(inf_amr, amr_be, amr_bits, + COD_FORMAT_NWORDS, amr_filename); + rc_efr = read_etsi_bits(inf_efr, efr_be, efr_bits, + ETSI_ENC_NWORDS, efr_filename); + if (!rc_amr && !rc_efr) + break; + if (!rc_amr) { + printf("EFR file %s is longer than AMR file %s\n", + efr_filename, amr_filename); + exit(0); + } + if (!rc_efr) { + printf("AMR file %s is longer than EFR file %s\n", + amr_filename, efr_filename); + exit(0); + } + /* grok AMR frame type */ + switch (amr_bits[0]) { + case TX_SPEECH_GOOD: + if (amr_bits[245] != MR122) { + fprintf(stderr, + "error: %s frame #%u is not MR122\n", + amr_filename, frame_no); + exit(1); + } + amr_sp = 1; + break; + case TX_SID_FIRST: + case TX_SID_UPDATE: + case TX_NO_DATA: + amr_sp = 0; + break; + default: + fprintf(stderr, + "error: %s frame #%u has unknown type %u\n", + amr_filename, frame_no, amr_bits[0]); + exit(1); + } + efr_sp = efr_bits[245]; + if (!amr_sp && !efr_sp) + continue; + if (!amr_sp || !efr_sp) { + printf("frame #%u: AMR SP %d != EFR SP %d\n", frame_no, + amr_sp, efr_sp); + continue; + } + if (bcmp(amr_bits+1, efr_bits, 244)) + printf("frame #%u: bits differ\n", frame_no); + } + exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrdiff/etsi-bit-rd.c Wed Apr 03 18:44:27 2024 +0000 @@ -0,0 +1,50 @@ +/* + * The utility function in this module reads the bits from ETSI *.cod + * files, both AMR and EFR versions, either LE or BE. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "etsi.h" +#include "amr_defs.h" + +read_etsi_bits(inf, big_endian, bitvec, nwords, filename_for_errs) + FILE *inf; + uint8_t *bitvec; + unsigned nwords; + char *filename_for_errs; +{ + uint8_t file_bytes[COD_FORMAT_NWORDS * 2], *sp; + int cc; + unsigned n, upper; + + cc = fread(file_bytes, 2, nwords, inf); + if (cc == 0) + return 0; + if (cc != nwords) { + fprintf(stderr, "error: short read from %s\n", + filename_for_errs); + exit(1); + } + sp = file_bytes; + for (n = 0; n < nwords; n++) { + if (big_endian) { + upper = sp[0]; + bitvec[n] = sp[1]; + } else { + bitvec[n] = sp[0]; + upper = sp[1]; + } + if (upper && (sp[0] != 0xFF || sp[1] != 0xFF)) { + fprintf(stderr, + "error in %s: non-zero in what should be %s upper byte\n", + filename_for_errs, big_endian ? "BE" : "LE"); + exit(1); + } + sp += 2; + } + return 1; +}