FreeCalypso > hg > gsm-codec-lib
annotate amrtest/tseq-dec.c @ 471:b5f8ea41362b
gsmrec-dump: report DHF matches
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 14 May 2024 07:25:06 +0000 |
parents | edbbbf1c4ab1 |
children |
rev | line source |
---|---|
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
2 * twamr-tseq-dec is a test program for our AMR decoder: it reads |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
3 * 3GPP AMR *.cod files as input and writes 16-bit linear PCM (raw) |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
4 * files as output, allowing libtwamr decoder to be tested with the |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * official test sequences. |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
7 * Both input and output are read/written in the host machine's |
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
8 * native byte order. |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <string.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <strings.h> |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
16 #include <unistd.h> |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
17 #include "../libtwamr/tw_amr.h" |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 static int |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
20 read_input(inf, cod, filename_for_errs) |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 FILE *inf; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
22 uint16_t *cod; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char *filename_for_errs; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int cc; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
27 cc = fread(cod, 2, AMR_COD_WORDS, inf); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (cc == 0) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return 0; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
30 if (cc != AMR_COD_WORDS) { |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
31 fprintf(stderr, "error: short read from %s\n", |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 filename_for_errs); |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
33 exit(1); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return 1; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 main(argc, argv) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 char **argv; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 { |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
41 char *infname, *outfname; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 FILE *inf, *outf; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
43 struct amr_decoder_state *state; |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
44 uint16_t cod[AMR_COD_WORDS]; |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
45 struct amr_param_frame frame; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 int16_t pcm[160]; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
47 int opt, use_rxtype = 0, rc; |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
48 unsigned frame_no; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
49 extern int optind; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
51 while ((opt = getopt(argc, argv, "r")) != EOF) { |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
52 switch (opt) { |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
53 case 'r': |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
54 use_rxtype = 1; |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
55 continue; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
56 default: |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
57 usage: |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
58 fprintf(stderr, "usage: %s [-r] input.cod output.out\n", |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
59 argv[0]); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
60 exit(1); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
61 } |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
63 if (argc != optind + 2) |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
64 goto usage; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
65 infname = argv[optind]; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
66 outfname = argv[optind+1]; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
67 |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 inf = fopen(infname, "r"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (!inf) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 perror(infname); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 outf = fopen(outfname, "w"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (!outf) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 perror(outfname); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
78 state = amr_decoder_create(); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (!state) { |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
80 perror("amr_decoder_create()"); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 } |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
83 for (frame_no = 0; ; frame_no++) { |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
84 rc = read_input(inf, cod, infname); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (!rc) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 break; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
87 rc = amr_frame_from_tseq(cod, use_rxtype, &frame); |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
88 if (rc < 0) { |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
89 fprintf(stderr, |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
90 "error in %s frame %u: amr_frame_from_tseq() returned %d\n", |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
91 infname, frame_no, rc); |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
92 exit(1); |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
93 } |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
94 amr_decode_frame(state, &frame, pcm); |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
95 fwrite(pcm, 2, 160, outf); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fclose(outf); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 exit(0); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |