FreeCalypso > hg > gsm-codec-lib
annotate efrtest/etsi-dec.c @ 436:e80632ccb745
simplify test program Makefiles
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 08 May 2024 05:32:27 +0000 |
parents | 9f354d2aea13 |
children |
rev | line source |
---|---|
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * gsmefr-etsi-dec is a test program for our EFR decoder: it reads ETSI's |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * .dec format as input and writes raw 16-bit PCM (same as ETSI's *.out) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * as output, allowing our decoder to be tested with ETSI's official test |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * sequences. |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 * |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
7 * ETSI input and output files are read and written in LE byte order |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
8 * by default, or in BE byte order if -b option is given. |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <string.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <strings.h> |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 #include "../libgsmefr/gsm_efr.h" |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
17 #include "etsi.h" |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 main(argc, argv) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char **argv; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
22 int big_endian; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
23 char *infname, *outfname; |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 FILE *inf, *outf; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 struct EFR_decoder_state *state; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 unsigned frame_no; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 uint8_t input_bits[ETSI_DEC_NWORDS], frame[EFR_RTP_FRAME_LEN]; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int16_t pcm[160]; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 int rc; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
31 if (argc == 3 && argv[1][0] != '-') { |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
32 big_endian = 0; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
33 infname = argv[1]; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
34 outfname = argv[2]; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
35 } else if (argc == 4 && !strcmp(argv[1], "-b")) { |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
36 big_endian = 1; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
37 infname = argv[2]; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
38 outfname = argv[3]; |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
39 } else { |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
40 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
|
41 argv[0]); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
44 inf = fopen(infname, "r"); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!inf) { |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
46 perror(infname); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
49 outf = fopen(outfname, "w"); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (!outf) { |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
51 perror(outfname); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 state = EFR_decoder_create(); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (!state) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 perror("EFR_decoder_create()"); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 for (frame_no = 0; ; frame_no++) { |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
60 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
|
61 ETSI_DEC_NWORDS, infname); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (!rc) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 break; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (input_bits[0] > 1) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fprintf(stderr, "error in %s frame #%u: BFI > 1\n", |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
66 infname, frame_no); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
69 bits2frame(input_bits + 1, frame, infname, frame_no); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (input_bits[245] > 2) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 fprintf(stderr, "error in %s frame #%u: SID > 2\n", |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
72 infname, frame_no); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (input_bits[246] > 1) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fprintf(stderr, "error in %s frame #%u: TAF > 1\n", |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
77 infname, frame_no); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 rc = EFR_sid_classify(frame); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 if (input_bits[245] != rc) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 fprintf(stderr, |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 "warning: frame #%u has mismatching SID (file says %u, analysis yields %d)\n", |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 frame_no, input_bits[245], rc); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 EFR_decode_frame(state, frame, input_bits[0], input_bits[246], |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 pcm); |
150
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
88 if (big_endian) |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
89 write_pcm_be(outf, pcm); |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
90 else |
da17c7f02c6c
gsmefr-etsi-dec: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
145
diff
changeset
|
91 write_pcm_le(outf, pcm); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 fclose(outf); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 exit(0); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |