FreeCalypso > hg > gsm-codec-lib
annotate efrtest/etsi-dec.c @ 148:bbe5669f0f29
gsmefr-cod-parse: add BE support
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 14 Dec 2022 17:21:05 +0000 |
parents | 8ed838709897 |
children | da17c7f02c6c |
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 * |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 * ETSI input and output files are read and written in LE byte order, |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * matching the official test sequences in ts_100725v050200p0.zip. |
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 static void |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 write_pcm_le(outf, pcm) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 FILE *outf; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int16_t *pcm; |
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 uint8_t bytes[320], *dp; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int16_t samp; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 unsigned n; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 dp = bytes; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 for (n = 0; n < 160; n++) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 samp = pcm[n]; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 *dp++ = samp & 0xFF; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 *dp++ = (samp >> 8) & 0xFF; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fwrite(bytes, 2, 160, outf); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 main(argc, argv) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 char **argv; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 FILE *inf, *outf; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 struct EFR_decoder_state *state; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 unsigned frame_no; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 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
|
44 int16_t pcm[160]; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int rc; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (argc != 3) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 fprintf(stderr, "usage: %s input.dec output.out\n", argv[0]); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 inf = fopen(argv[1], "r"); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!inf) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 perror(argv[1]); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 outf = fopen(argv[2], "w"); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (!outf) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 perror(argv[2]); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 state = EFR_decoder_create(); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (!state) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 perror("EFR_decoder_create()"); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 for (frame_no = 0; ; frame_no++) { |
145
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
67 rc = read_etsi_bits(inf, 0, input_bits, ETSI_DEC_NWORDS, |
8ed838709897
efrtest: ETSI bit reading factored out of gsmefr-etsi-dec
Mychaela Falconia <falcon@freecalypso.org>
parents:
97
diff
changeset
|
68 argv[1]); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (!rc) |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 break; |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (input_bits[0] > 1) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fprintf(stderr, "error in %s frame #%u: BFI > 1\n", |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 argv[1], frame_no); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
97
e5ee684c6d29
efrtest/etsi-dec.c: off-by-1 error in frame bit packing
Mychaela Falconia <falcon@freecalypso.org>
parents:
96
diff
changeset
|
76 bits2frame(input_bits + 1, frame, argv[1], frame_no); |
96
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (input_bits[245] > 2) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fprintf(stderr, "error in %s frame #%u: SID > 2\n", |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 argv[1], frame_no); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (input_bits[246] > 1) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 fprintf(stderr, "error in %s frame #%u: TAF > 1\n", |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 argv[1], frame_no); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(1); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 rc = EFR_sid_classify(frame); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (input_bits[245] != rc) { |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 fprintf(stderr, |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 "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
|
91 frame_no, input_bits[245], rc); |
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 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
|
94 pcm); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 write_pcm_le(outf, pcm); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fclose(outf); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 exit(0); |
9cf1355bc071
gsmefr-etsi-dec test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 } |