FreeCalypso > hg > vband-misc
changeset 28:4f47447fd17f
pcma2efr: starting with DHF check
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 13 May 2024 02:45:17 +0000 |
parents | 2095f3c23dad |
children | fc4544e3687b |
files | .hgignore Makefile pcma2efr/Makefile pcma2efr/alaw-expand.c pcma2efr/dhf-check.c pcma2efr/gen-amr-2fr.c pcma2efr/gen-efr.c pcma2efr/gen160.c pcma2efr/seqsynca.c |
diffstat | 9 files changed, 236 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgignore Mon May 13 01:46:25 2024 +0000 +++ b/.hgignore Mon May 13 02:45:17 2024 +0000 @@ -9,6 +9,8 @@ ^dmw/gen-dmw-bin$ ^dmw/dmw-[au]law\. +^pcma2efr/dhf-check$ + ^pcmu2efr/all-outputs\. ^pcmu2efr/amrefr-out$ ^pcmu2efr/comb-diff$
--- a/Makefile Mon May 13 01:46:25 2024 +0000 +++ b/Makefile Mon May 13 02:45:17 2024 +0000 @@ -1,4 +1,4 @@ -SUBDIR= amrdiff dmw pcmu2efr ringing utils +SUBDIR= amrdiff dmw pcma2efr pcmu2efr ringing utils all: ${SUBDIR}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/Makefile Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,14 @@ +CC= gcc +CFLAGS= -O2 +PROGS= dhf-check + +DHF_CHECK_OBJS= alaw-expand.o dhf-check.o gen-amr-2fr.o gen-efr.o gen160.o \ + seqsynca.o + +all: ${PROGS} + +dhf-check: ${DHF_CHECK_OBJS} + ${CC} ${CFLAGS} -o $@ ${DHF_CHECK_OBJS} -lgsmefr -ltwamr + +clean: + rm -f *.o ${PROGS} *.bin *.gsmx *.inc
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/alaw-expand.c Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,41 @@ +/* + * This module holds the table for expanding from 8-bit PCMA + * to 16-bit linear PCM. + */ + +#include <stdint.h> + +const uint16_t pcma_decode_table[256] = { + 60032, 60288, 59520, 59776, 61056, 61312, 60544, 60800, + 57984, 58240, 57472, 57728, 59008, 59264, 58496, 58752, + 62784, 62912, 62528, 62656, 63296, 63424, 63040, 63168, + 61760, 61888, 61504, 61632, 62272, 62400, 62016, 62144, + 43520, 44544, 41472, 42496, 47616, 48640, 45568, 46592, + 35328, 36352, 33280, 34304, 39424, 40448, 37376, 38400, + 54528, 55040, 53504, 54016, 56576, 57088, 55552, 56064, + 50432, 50944, 49408, 49920, 52480, 52992, 51456, 51968, + 65192, 65208, 65160, 65176, 65256, 65272, 65224, 65240, + 65064, 65080, 65032, 65048, 65128, 65144, 65096, 65112, + 65448, 65464, 65416, 65432, 65512, 65528, 65480, 65496, + 65320, 65336, 65288, 65304, 65384, 65400, 65352, 65368, + 64160, 64224, 64032, 64096, 64416, 64480, 64288, 64352, + 63648, 63712, 63520, 63584, 63904, 63968, 63776, 63840, + 64848, 64880, 64784, 64816, 64976, 65008, 64912, 64944, + 64592, 64624, 64528, 64560, 64720, 64752, 64656, 64688, + 5504, 5248, 6016, 5760, 4480, 4224, 4992, 4736, + 7552, 7296, 8064, 7808, 6528, 6272, 7040, 6784, + 2752, 2624, 3008, 2880, 2240, 2112, 2496, 2368, + 3776, 3648, 4032, 3904, 3264, 3136, 3520, 3392, + 22016, 20992, 24064, 23040, 17920, 16896, 19968, 18944, + 30208, 29184, 32256, 31232, 26112, 25088, 28160, 27136, + 11008, 10496, 12032, 11520, 8960, 8448, 9984, 9472, + 15104, 14592, 16128, 15616, 13056, 12544, 14080, 13568, + 344, 328, 376, 360, 280, 264, 312, 296, + 472, 456, 504, 488, 408, 392, 440, 424, + 88, 72, 120, 104, 24, 8, 56, 40, + 216, 200, 248, 232, 152, 136, 184, 168, + 1376, 1312, 1504, 1440, 1120, 1056, 1248, 1184, + 1888, 1824, 2016, 1952, 1632, 1568, 1760, 1696, + 688, 656, 752, 720, 560, 528, 624, 592, + 944, 912, 1008, 976, 816, 784, 880, 848, +};
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/dhf-check.c Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,46 @@ +/* + * This program generates both standard-EFR and AMR-EFR versions of + * sample-shifted first encoder frame, and checks them against + * both EFR and MR122 DHFs. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <gsm_efr.h> +#include <tw_amr.h> + +extern uint8_t standard_efr[160][31]; +extern uint8_t amr_efr[160][31]; + +static void +check_for_dhf(efr_frame, name, num) + uint8_t *efr_frame; + char *name; + unsigned num; +{ + int16_t params[EFR_NUM_PARAMS]; + + EFR_frame2params(efr_frame, params); + if (!bcmp(params, amr_dhf_gsmefr, EFR_NUM_PARAMS * sizeof(int16_t))) + printf("%s frame %u matches EFR DHF\n", name, num); + else if (!bcmp(params, amr_dhf_mr122, EFR_NUM_PARAMS * sizeof(int16_t))) + printf("%s frame %u matches MR122 DHF\n", name, num); +} + +main(argc, argv) + char **argv; +{ + unsigned n; + + generate_linear_inputs(); + generate_std_efr(); + generate_amr_efr(); + for (n = 0; n < 160; n++) + check_for_dhf(standard_efr[n], "std EFR", n); + for (n = 0; n < 160; n++) + check_for_dhf(amr_efr[n], "AMR-EFR", n); + exit(0); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/gen-amr-2fr.c Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,51 @@ +/* + * The code in this module takes linear_input_array[] from gen160.c + * and generates EFR-format frames by way of libtwamr encoder. + * This version does a second frame pass on offsets 120-159. + */ + +#include <stdio.h> +#include <stdint.h> +#include <stdlib.h> +#include <string.h> +#include <strings.h> +#include <gsm_efr.h> +#include <tw_amr.h> + +extern uint16_t linear_input_array[480]; + +uint8_t amr_efr[160][31]; + +void +generate_amr_efr(void) +{ + struct amr_encoder_state *st; + struct amr_param_frame amr_frame; + unsigned m; + + st = amr_encoder_create(0, 0); + if (!st) { + fprintf(stderr, "error: amr_encoder_create() failed\n"); + exit(1); + } + for (m = 0; m < 160; m++) { + amr_encoder_reset(st, 0, 0); + amr_encode_frame(st, MR122, + (const int16_t *) linear_input_array + 160 - m, + &amr_frame); + if (m >= 120) { + if (bcmp(amr_frame.param, amr_dhf_mr122, + EFR_NUM_PARAMS * sizeof(int16_t))) { + fprintf(stderr, + "MR122 DHF check failed on AMR-EFR first frame #%u\n", + m); + exit(1); + } + amr_encode_frame(st, MR122, + (const int16_t *) linear_input_array + 320 - m, + &amr_frame); + } + EFR_params2frame(amr_frame.param, amr_efr[m]); + } + free(st); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/gen-efr.c Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,32 @@ +/* + * The code in this module takes linear_input_array[] 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_input_array[480]; + +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_input_array+160-m, + standard_efr[m], (int *) 0, (int *) 0); + } + free(st); +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/gen160.c Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,29 @@ +/* + * The code in this module generates 160 versions of linearized seqsynca, + * shifted by one sample each, intended for feeding to EFR and AMR encoders. + * + * Update: the new version generates a linear array of 480 16-bit PCM samples, + * where the first 160 are 0x0008, followed by two copies of linearized + * seqsynca. + */ + +#include <stdint.h> + +extern const uint8_t seqsynca_last_frame[160]; +extern const uint16_t pcma_decode_table[256]; + +uint16_t linear_input_array[480]; + +void +generate_linear_inputs(void) +{ + unsigned n; + uint16_t lin; + + for (n = 0; n < 160; n++) { + lin = pcma_decode_table[seqsynca_last_frame[n]]; + linear_input_array[n] = 0x0008; + linear_input_array[160+n] = lin; + linear_input_array[320+n] = lin; + } +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/pcma2efr/seqsynca.c Mon May 13 02:45:17 2024 +0000 @@ -0,0 +1,20 @@ +/* + * The frame of 160 PCMA samples that is captured here in C hex array form + * appears in seqsynca.inp (the last frame after 3 EHFs) inside ZIP archive + * ef_syn_a.exe on Disk 5 of GSM-EFR test sequence set. + */ + +#include <stdint.h> + +const uint8_t seqsynca_last_frame[160] = { +0x35,0x9E,0x2F,0x2A,0x82,0x9A,0xA4,0x3E,0x24,0x29,0xBD,0x28,0xA9,0x0D,0x83,0x21, +0x25,0xAF,0x2B,0x2D,0x23,0x88,0xAB,0xBF,0x83,0x25,0xA6,0x6F,0x60,0xAF,0x29,0x20, +0x06,0xB4,0x25,0xA1,0x2C,0x34,0xB1,0x32,0x22,0x1C,0xB2,0xB7,0x8A,0x31,0xB0,0xA7, +0x23,0x0C,0x8F,0x8A,0x3A,0x8E,0xAE,0xE0,0x18,0x23,0x06,0x21,0x85,0x4F,0xA1,0x35, +0x8C,0x2F,0xA3,0x2D,0xAD,0x24,0x16,0xAD,0xEE,0x27,0xAF,0x1E,0x30,0x0E,0x6E,0x2E, +0xA6,0x23,0xDC,0x3C,0xCA,0xD5,0x1B,0x6F,0xB5,0x3E,0xBE,0xA8,0xBC,0xB2,0xA8,0x25, +0x1C,0x2A,0xB6,0x2B,0xA3,0xF8,0x34,0x32,0x22,0x23,0xA8,0xB9,0x2B,0xAB,0xAE,0xA2, +0xA0,0x0D,0xAF,0x3C,0xB7,0xE8,0xAE,0xBD,0x05,0x2F,0x27,0x89,0x20,0x39,0x22,0xAD, +0xB3,0xA7,0x38,0xB9,0x9A,0x37,0xA8,0x97,0xA1,0x3C,0x33,0xA4,0x3D,0x3D,0x34,0x83, +0x2B,0xB3,0xA9,0xA1,0x29,0xBE,0x26,0xA0,0x3D,0x3B,0x37,0xA9,0xAC,0xAD,0x30,0xAB, +};