FreeCalypso > hg > gsm-codec-lib
comparison amrefr/tseq-dec.c @ 437:3eadaef8b28f
implement amrefr-tseq-dec test program
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Wed, 08 May 2024 23:03:28 +0000 |
| parents | efrtest/etsi-dec.c@9f354d2aea13 |
| children |
comparison
equal
deleted
inserted
replaced
| 436:e80632ccb745 | 437:3eadaef8b28f |
|---|---|
| 1 /* | |
| 2 * amrefr-tseq-dec is a test program for our libtwamr-based "alternative EFR" | |
| 3 * decoder: it functions just like gsmefr-etsi-dec, but uses libtwamr as | |
| 4 * the decoder engine instead of libgsmefr. Libgsmefr functions are still | |
| 5 * used for frame unpacking, but not for actual decoding. Note that there is | |
| 6 * no DTX support in this version, and the *.dec test sequence being decoded | |
| 7 * must have SID=0 in every frame. As a simplification, we also require BFI=0: | |
| 8 * while it is possible to feed BFI=1 frames to libtwamr decoder (convert to | |
| 9 * RX_SPEECH_BAD), such support is not needed for decoding the test sequences | |
| 10 * in amr122_efr.zip, hence we've omitted it for simplicity. | |
| 11 * | |
| 12 * The byte order is LE by default or BE with -b option. | |
| 13 */ | |
| 14 | |
| 15 #include <stdio.h> | |
| 16 #include <stdint.h> | |
| 17 #include <stdlib.h> | |
| 18 #include <string.h> | |
| 19 #include <strings.h> | |
| 20 #include "../libgsmefr/gsm_efr.h" | |
| 21 #include "../libtwamr/tw_amr.h" | |
| 22 #include "../efrtest/etsi.h" | |
| 23 | |
| 24 main(argc, argv) | |
| 25 char **argv; | |
| 26 { | |
| 27 int big_endian; | |
| 28 char *infname, *outfname; | |
| 29 FILE *inf, *outf; | |
| 30 struct amr_decoder_state *state; | |
| 31 unsigned frame_no; | |
| 32 uint8_t input_bits[ETSI_DEC_NWORDS], efr_frame[EFR_RTP_FRAME_LEN]; | |
| 33 struct amr_param_frame amr_frame; | |
| 34 int16_t pcm[160]; | |
| 35 int rc; | |
| 36 | |
| 37 if (argc == 3 && argv[1][0] != '-') { | |
| 38 big_endian = 0; | |
| 39 infname = argv[1]; | |
| 40 outfname = argv[2]; | |
| 41 } else if (argc == 4 && !strcmp(argv[1], "-b")) { | |
| 42 big_endian = 1; | |
| 43 infname = argv[2]; | |
| 44 outfname = argv[3]; | |
| 45 } else { | |
| 46 fprintf(stderr, "usage: %s [-b] input.dec output.out\n", | |
| 47 argv[0]); | |
| 48 exit(1); | |
| 49 } | |
| 50 inf = fopen(infname, "r"); | |
| 51 if (!inf) { | |
| 52 perror(infname); | |
| 53 exit(1); | |
| 54 } | |
| 55 outf = fopen(outfname, "w"); | |
| 56 if (!outf) { | |
| 57 perror(outfname); | |
| 58 exit(1); | |
| 59 } | |
| 60 state = amr_decoder_create(); | |
| 61 if (!state) { | |
| 62 perror("amr_decoder_create()"); | |
| 63 exit(1); | |
| 64 } | |
| 65 amr_frame.type = RX_SPEECH_GOOD; | |
| 66 amr_frame.mode = 0x87; | |
| 67 for (frame_no = 0; ; frame_no++) { | |
| 68 rc = read_etsi_bits(inf, big_endian, input_bits, | |
| 69 ETSI_DEC_NWORDS, infname); | |
| 70 if (!rc) | |
| 71 break; | |
| 72 if (input_bits[0]) { | |
| 73 fprintf(stderr, | |
| 74 "error in %s frame #%u: BFI != 0 not supported\n", | |
| 75 infname, frame_no); | |
| 76 exit(1); | |
| 77 } | |
| 78 bits2frame(input_bits + 1, efr_frame, infname, frame_no); | |
| 79 if (input_bits[245]) { | |
| 80 fprintf(stderr, | |
| 81 "error in %s frame #%u: SID != 0 not supported\n", | |
| 82 infname, frame_no); | |
| 83 exit(1); | |
| 84 } | |
| 85 EFR_frame2params(efr_frame, amr_frame.param); | |
| 86 amr_decode_frame(state, &amr_frame, pcm); | |
| 87 if (big_endian) | |
| 88 write_pcm_be(outf, pcm); | |
| 89 else | |
| 90 write_pcm_le(outf, pcm); | |
| 91 } | |
| 92 fclose(outf); | |
| 93 exit(0); | |
| 94 } |
