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