FreeCalypso > hg > gsm-codec-lib
changeset 184:b092a510141e
tree reorg: move gsm-amr2efr & gsm-efr2amr to amrconv subdir
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 03 Jan 2023 02:33:45 +0000 |
parents | 452c1d5a6268 |
children | a4d1615e2aa4 |
files | .hgignore Makefile amrconv/Makefile amrconv/amr122bits.c amrconv/amr2efr.c amrconv/bitmanip.c amrconv/efr2amr.c miscutil/Makefile miscutil/amr122bits.c miscutil/amr2efr.c miscutil/bitmanip.c miscutil/efr2amr.c |
diffstat | 12 files changed, 264 insertions(+), 248 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Tue Jan 03 00:12:18 2023 +0000 +++ b/.hgignore Tue Jan 03 02:33:45 2023 +0000 @@ -2,6 +2,9 @@ \.[oa]$ +^amrconv/gsm-amr2efr$ +^amrconv/gsm-efr2amr$ + ^dev/efr-bit-packing$ ^dev/efr-bit-packing\.out$ ^dev/efr-sid-insert$ @@ -34,8 +37,6 @@ ^frtest/gsmfr-max-out$ ^frtest/gsmfr-preproc$ -^miscutil/gsm-amr2efr$ -^miscutil/gsm-efr2amr$ ^miscutil/gsmrec-dump$ ^miscutil/pcm16-raw2wav$ ^miscutil/pcm16-wav2raw$
--- a/Makefile Tue Jan 03 00:12:18 2023 +0000 +++ b/Makefile Tue Jan 03 02:33:45 2023 +0000 @@ -2,13 +2,14 @@ CFLAGS= -O2 SUBDIR_LIBPROD= libgsmefr libgsmfrp -SUBDIR_UTILS= efrtest frtest miscutil pcap +SUBDIR_UTILS= amrconv efrtest frtest miscutil pcap SUBDIR_INT= dev libtest SUBDIR= ${SUBDIR_LIBPROD} ${SUBDIR_UTILS} ${SUBDIR_INT} all: ${SUBDIR} +amrconv: libtest efrtest: libgsmefr libtest frtest: libgsmfrp libtest miscutil: libgsmefr libtest
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrconv/Makefile Tue Jan 03 02:33:45 2023 +0000 @@ -0,0 +1,23 @@ +CC= gcc +CFLAGS= -O2 +PROGS= gsm-amr2efr gsm-efr2amr +LIBTEST=../libtest/libtest.a +INSTBIN=/opt/freecalypso/bin + +AMR2EFR_OBJS= amr122bits.o bitmanip.o amr2efr.o +EFR2AMR_OBJS= amr122bits.o bitmanip.o efr2amr.o + +all: ${PROGS} + +gsm-amr2efr: ${AMR2EFR_OBJS} + ${CC} ${CFLAGS} -o $@ ${AMR2EFR_OBJS} + +gsm-efr2amr: ${EFR2AMR_OBJS} ${LIBTEST} + ${CC} ${CFLAGS} -o $@ ${EFR2AMR_OBJS} ${LIBTEST} + +install: + mkdir -p ${INSTBIN} + install -c ${PROGS} ${INSTBIN} + +clean: + rm -f *.o *.out ${PROGS}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrconv/amr122bits.c Tue Jan 03 02:33:45 2023 +0000 @@ -0,0 +1,36 @@ +/* + * This C module provides the bit reordering table to be used for conversion + * between EFR in ETSI TS 101 318 representation and AMR 12k2 in RFC 4867 + * or AMR IF1 representation, which is the table mapping from AMR IF1 bit + * order for 12k2 mode to the "natural" bit order of codec parameters. + */ + +#include <stdint.h> + +const uint8_t amr_122_bit_order[244] = { + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, + 10, 11, 12, 13, 14, 23, 15, 16, 17, 18, + 19, 20, 21, 22, 24, 25, 26, 27, 28, 38, + 141, 39, 142, 40, 143, 41, 144, 42, 145, 43, + 146, 44, 147, 45, 148, 46, 149, 47, 97, 150, + 200, 48, 98, 151, 201, 49, 99, 152, 202, 86, + 136, 189, 239, 87, 137, 190, 240, 88, 138, 191, + 241, 91, 194, 92, 195, 93, 196, 94, 197, 95, + 198, 29, 30, 31, 32, 33, 34, 35, 50, 100, + 153, 203, 89, 139, 192, 242, 51, 101, 154, 204, + 55, 105, 158, 208, 90, 140, 193, 243, 59, 109, + 162, 212, 63, 113, 166, 216, 67, 117, 170, 220, + 36, 37, 54, 53, 52, 58, 57, 56, 62, 61, + 60, 66, 65, 64, 70, 69, 68, 104, 103, 102, + 108, 107, 106, 112, 111, 110, 116, 115, 114, 120, + 119, 118, 157, 156, 155, 161, 160, 159, 165, 164, + 163, 169, 168, 167, 173, 172, 171, 207, 206, 205, + 211, 210, 209, 215, 214, 213, 219, 218, 217, 223, + 222, 221, 73, 72, 71, 76, 75, 74, 79, 78, + 77, 82, 81, 80, 85, 84, 83, 123, 122, 121, + 126, 125, 124, 129, 128, 127, 132, 131, 130, 135, + 134, 133, 176, 175, 174, 179, 178, 177, 182, 181, + 180, 185, 184, 183, 188, 187, 186, 226, 225, 224, + 229, 228, 227, 232, 231, 230, 235, 234, 233, 238, + 237, 236, 96, 199 +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrconv/amr2efr.c Tue Jan 03 02:33:45 2023 +0000 @@ -0,0 +1,80 @@ +/* + * 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]; + +static const char amr_file_hdr[] = "#!AMR\n"; + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + int wrong_flag, hdrb; + uint8_t frm_in[31], frm_out[31]; + unsigned bit_a, bit_n; + + if (argc == 3 && argv[1][0] != '-') { + wrong_flag = 0; + infname = argv[1]; + outfname = argv[2]; + } else if (argc == 4 && !strcmp(argv[1], "-w")) { + wrong_flag = 1; + infname = argv[2]; + outfname = argv[3]; + } else { + fprintf(stderr, "usage: %s [-w] input.amr output.gsmx\n", + argv[0]); + exit(1); + } + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + if (fread(frm_in, 1, 6, inf) != 6 || bcmp(frm_in, amr_file_hdr, 6)) { + fprintf(stderr, "error: %s is not in AMR format\n", infname); + exit(1); + } + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + for (;;) { + hdrb = getc(inf); + if (hdrb < 0) + break; + if ((hdrb & 0x78) != 0x38) { + fprintf(stderr, "error: unexpected content in %s\n", + infname); + exit(1); + } + if (fread(frm_in, 1, 31, inf) != 31) { + fprintf(stderr, "error: short read from %s\n", infname); + exit(1); + } + frm_out[0] = 0xC0; + for (bit_a = 0; bit_a < 244; bit_a++) { + if (wrong_flag) + bit_n = bit_a; + else + 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); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrconv/bitmanip.c Tue Jan 03 02:33:45 2023 +0000 @@ -0,0 +1,27 @@ +/* + * This module provides two utility functions that serve as building blocks + * for frame bit reordering operations. + */ + +#include <stdint.h> + +msb_get_bit(buf, bn) + uint8_t *buf; +{ + int pos_byte = bn >> 3; + int pos_bit = 7 - (bn & 7); + + return (buf[pos_byte] >> pos_bit) & 1; +} + +msb_set_bit(buf, bn, bit) + uint8_t *buf; +{ + int pos_byte = bn >> 3; + int pos_bit = 7 - (bn & 7); + + if (bit) + buf[pos_byte] |= (1 << pos_bit); + else + buf[pos_byte] &= ~(1 << pos_bit); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/amrconv/efr2amr.c Tue Jan 03 02:33:45 2023 +0000 @@ -0,0 +1,92 @@ +/* + * Our gsm-efr2amr utility reads in an EFR speech recording in our + * extended-libgsm file format and converts it to AMR, inserting + * an AMR NO_DATA frame in the place of every BFI in the input + * but NOT performing any special handling or even detection of + * EFR SID frames. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include "../libtest/binreader.h" + +extern const uint8_t amr_122_bit_order[244]; + +static const char amr_file_hdr[] = "#!AMR\n"; + +main(argc, argv) + char **argv; +{ + char *infname, *outfname; + FILE *inf, *outf; + int wrong_flag; + uint8_t frm_in[BINFILE_MAX_FRAME], frm_out[32]; + unsigned bit_a, bit_n, outlen; + int rc, bfi; + + if (argc == 3 && argv[1][0] != '-') { + wrong_flag = 0; + infname = argv[1]; + outfname = argv[2]; + } else if (argc == 4 && !strcmp(argv[1], "-w")) { + wrong_flag = 1; + infname = argv[2]; + outfname = argv[3]; + } else { + fprintf(stderr, "usage: %s [-w] input.gsmx output.amr\n", + argv[0]); + exit(1); + } + inf = fopen(infname, "r"); + if (!inf) { + perror(infname); + exit(1); + } + outf = fopen(outfname, "w"); + if (!outf) { + perror(outfname); + exit(1); + } + fwrite(amr_file_hdr, 1, 6, outf); + for (;;) { + rc = binfile_read_frame(inf, frm_in); + if (rc < 0) { + fprintf(stderr, "error: garbage in %s\n", infname); + exit(1); + } + if (!rc) + break; + if (frm_in[0] == 0xBF) + bfi = 1; + else if ((frm_in[0] & 0xF0) == 0xC0) + bfi = 0; + else { + fprintf(stderr, + "error: %s is not in EFR codec format\n", + infname); + exit(1); + } + if (bfi) { + frm_out[0] = 0x78; + outlen = 1; + } else { + frm_out[0] = 0x3C; + frm_out[31] = 0; + for (bit_a = 0; bit_a < 244; bit_a++) { + if (wrong_flag) + bit_n = bit_a; + else + bit_n = amr_122_bit_order[bit_a]; + msb_set_bit(frm_out + 1, bit_a, + msb_get_bit(frm_in, 4 + bit_n)); + } + outlen = 32; + } + fwrite(frm_out, 1, outlen, outf); + } + fclose(outf); + exit(0); +}
--- a/miscutil/Makefile Tue Jan 03 00:12:18 2023 +0000 +++ b/miscutil/Makefile Tue Jan 03 02:33:45 2023 +0000 @@ -1,21 +1,12 @@ CC= gcc CFLAGS= -O2 -PROGS= gsm-amr2efr gsm-efr2amr gsmrec-dump pcm16-raw2wav pcm16-wav2raw +PROGS= gsmrec-dump pcm16-raw2wav pcm16-wav2raw LIBEFR= ../libgsmefr/libgsmefr.a LIBTEST=../libtest/libtest.a INSTBIN=/opt/freecalypso/bin -AMR2EFR_OBJS= amr122bits.o bitmanip.o amr2efr.o -EFR2AMR_OBJS= amr122bits.o bitmanip.o efr2amr.o - all: ${PROGS} -gsm-amr2efr: ${AMR2EFR_OBJS} - ${CC} ${CFLAGS} -o $@ ${AMR2EFR_OBJS} - -gsm-efr2amr: ${EFR2AMR_OBJS} ${LIBTEST} - ${CC} ${CFLAGS} -o $@ ${EFR2AMR_OBJS} ${LIBTEST} - gsmrec-dump: gsmrec-dump.o ${LIBTEST} ${LIBEFR} ${CC} ${CFLAGS} -o $@ gsmrec-dump.o ${LIBTEST} ${LIBEFR} -lgsm
--- a/miscutil/amr122bits.c Tue Jan 03 00:12:18 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,36 +0,0 @@ -/* - * This C module provides the bit reordering table to be used for conversion - * between EFR in ETSI TS 101 318 representation and AMR 12k2 in RFC 4867 - * or AMR IF1 representation, which is the table mapping from AMR IF1 bit - * order for 12k2 mode to the "natural" bit order of codec parameters. - */ - -#include <stdint.h> - -const uint8_t amr_122_bit_order[244] = { - 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, - 10, 11, 12, 13, 14, 23, 15, 16, 17, 18, - 19, 20, 21, 22, 24, 25, 26, 27, 28, 38, - 141, 39, 142, 40, 143, 41, 144, 42, 145, 43, - 146, 44, 147, 45, 148, 46, 149, 47, 97, 150, - 200, 48, 98, 151, 201, 49, 99, 152, 202, 86, - 136, 189, 239, 87, 137, 190, 240, 88, 138, 191, - 241, 91, 194, 92, 195, 93, 196, 94, 197, 95, - 198, 29, 30, 31, 32, 33, 34, 35, 50, 100, - 153, 203, 89, 139, 192, 242, 51, 101, 154, 204, - 55, 105, 158, 208, 90, 140, 193, 243, 59, 109, - 162, 212, 63, 113, 166, 216, 67, 117, 170, 220, - 36, 37, 54, 53, 52, 58, 57, 56, 62, 61, - 60, 66, 65, 64, 70, 69, 68, 104, 103, 102, - 108, 107, 106, 112, 111, 110, 116, 115, 114, 120, - 119, 118, 157, 156, 155, 161, 160, 159, 165, 164, - 163, 169, 168, 167, 173, 172, 171, 207, 206, 205, - 211, 210, 209, 215, 214, 213, 219, 218, 217, 223, - 222, 221, 73, 72, 71, 76, 75, 74, 79, 78, - 77, 82, 81, 80, 85, 84, 83, 123, 122, 121, - 126, 125, 124, 129, 128, 127, 132, 131, 130, 135, - 134, 133, 176, 175, 174, 179, 178, 177, 182, 181, - 180, 185, 184, 183, 188, 187, 186, 226, 225, 224, - 229, 228, 227, 232, 231, 230, 235, 234, 233, 238, - 237, 236, 96, 199 -};
--- a/miscutil/amr2efr.c Tue Jan 03 00:12:18 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * 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]; - -static const char amr_file_hdr[] = "#!AMR\n"; - -main(argc, argv) - char **argv; -{ - char *infname, *outfname; - FILE *inf, *outf; - int wrong_flag, hdrb; - uint8_t frm_in[31], frm_out[31]; - unsigned bit_a, bit_n; - - if (argc == 3 && argv[1][0] != '-') { - wrong_flag = 0; - infname = argv[1]; - outfname = argv[2]; - } else if (argc == 4 && !strcmp(argv[1], "-w")) { - wrong_flag = 1; - infname = argv[2]; - outfname = argv[3]; - } else { - fprintf(stderr, "usage: %s [-w] input.amr output.gsmx\n", - argv[0]); - exit(1); - } - inf = fopen(infname, "r"); - if (!inf) { - perror(infname); - exit(1); - } - if (fread(frm_in, 1, 6, inf) != 6 || bcmp(frm_in, amr_file_hdr, 6)) { - fprintf(stderr, "error: %s is not in AMR format\n", infname); - exit(1); - } - outf = fopen(outfname, "w"); - if (!outf) { - perror(outfname); - exit(1); - } - for (;;) { - hdrb = getc(inf); - if (hdrb < 0) - break; - if ((hdrb & 0x78) != 0x38) { - fprintf(stderr, "error: unexpected content in %s\n", - infname); - exit(1); - } - if (fread(frm_in, 1, 31, inf) != 31) { - fprintf(stderr, "error: short read from %s\n", infname); - exit(1); - } - frm_out[0] = 0xC0; - for (bit_a = 0; bit_a < 244; bit_a++) { - if (wrong_flag) - bit_n = bit_a; - else - 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); -}
--- a/miscutil/bitmanip.c Tue Jan 03 00:12:18 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,27 +0,0 @@ -/* - * This module provides two utility functions that serve as building blocks - * for frame bit reordering operations. - */ - -#include <stdint.h> - -msb_get_bit(buf, bn) - uint8_t *buf; -{ - int pos_byte = bn >> 3; - int pos_bit = 7 - (bn & 7); - - return (buf[pos_byte] >> pos_bit) & 1; -} - -msb_set_bit(buf, bn, bit) - uint8_t *buf; -{ - int pos_byte = bn >> 3; - int pos_bit = 7 - (bn & 7); - - if (bit) - buf[pos_byte] |= (1 << pos_bit); - else - buf[pos_byte] &= ~(1 << pos_bit); -}
--- a/miscutil/efr2amr.c Tue Jan 03 00:12:18 2023 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,92 +0,0 @@ -/* - * Our gsm-efr2amr utility reads in an EFR speech recording in our - * extended-libgsm file format and converts it to AMR, inserting - * an AMR NO_DATA frame in the place of every BFI in the input - * but NOT performing any special handling or even detection of - * EFR SID frames. - */ - -#include <stdio.h> -#include <stdint.h> -#include <stdlib.h> -#include <string.h> -#include <strings.h> -#include "../libtest/binreader.h" - -extern const uint8_t amr_122_bit_order[244]; - -static const char amr_file_hdr[] = "#!AMR\n"; - -main(argc, argv) - char **argv; -{ - char *infname, *outfname; - FILE *inf, *outf; - int wrong_flag; - uint8_t frm_in[BINFILE_MAX_FRAME], frm_out[32]; - unsigned bit_a, bit_n, outlen; - int rc, bfi; - - if (argc == 3 && argv[1][0] != '-') { - wrong_flag = 0; - infname = argv[1]; - outfname = argv[2]; - } else if (argc == 4 && !strcmp(argv[1], "-w")) { - wrong_flag = 1; - infname = argv[2]; - outfname = argv[3]; - } else { - fprintf(stderr, "usage: %s [-w] input.gsmx output.amr\n", - argv[0]); - exit(1); - } - inf = fopen(infname, "r"); - if (!inf) { - perror(infname); - exit(1); - } - outf = fopen(outfname, "w"); - if (!outf) { - perror(outfname); - exit(1); - } - fwrite(amr_file_hdr, 1, 6, outf); - for (;;) { - rc = binfile_read_frame(inf, frm_in); - if (rc < 0) { - fprintf(stderr, "error: garbage in %s\n", infname); - exit(1); - } - if (!rc) - break; - if (frm_in[0] == 0xBF) - bfi = 1; - else if ((frm_in[0] & 0xF0) == 0xC0) - bfi = 0; - else { - fprintf(stderr, - "error: %s is not in EFR codec format\n", - infname); - exit(1); - } - if (bfi) { - frm_out[0] = 0x78; - outlen = 1; - } else { - frm_out[0] = 0x3C; - frm_out[31] = 0; - for (bit_a = 0; bit_a < 244; bit_a++) { - if (wrong_flag) - bit_n = bit_a; - else - bit_n = amr_122_bit_order[bit_a]; - msb_set_bit(frm_out + 1, bit_a, - msb_get_bit(frm_in, 4 + bit_n)); - } - outlen = 32; - } - fwrite(frm_out, 1, outlen, outf); - } - fclose(outf); - exit(0); -}