FreeCalypso > hg > vband-misc
annotate amrdiff/amrdiff.c @ 8:d5bcfb378049
top Makefile: add dmw
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Apr 2024 07:20:46 +0000 |
parents | b55451463161 |
children |
rev | line source |
---|---|
0
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads two ETSI/3GPP test sequence files, one from |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * the AMR set of 3GPP TS 26.074 and the other from the "EFR2" set of |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * amr122_efr.zip, and performs a diff between them. |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "etsi.h" |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "amr_defs.h" |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
6
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
15 const uint8_t amr122_dhf_bits[244] = { |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
16 0,0,0,0,1,0,0,0,0,1,0,1,0,1,0,0,1,1,0,1,1,0,1,1,1,0,0,1,0,1,1,0,1,0,1,0,1,0,1,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
17 1,0,1,0,1,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
18 0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0,1,0,1,1,0,0,0,0,1,1,1,1,1,1,1,0,1,1,0,0,1,1,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
19 1,0,0,0,0,0,1,1,0,1,1,1,1,0,0,1,0,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,0,1,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
20 0,0,0,1,0,1,0,1,1,0,0,0,0,1,0,1,0,1,0,0,1,1,1,1,0,0,0,1,0,0,0,0,1,1,1,1,0,1,1,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
21 1,0,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,1,1,1,1,1,1,0,1,0,1,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
22 0,0,0,0 |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
23 }; |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
24 |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
25 const uint8_t efr_dhf_bits[244] = { |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
26 0,0,0,0,1,0,0,0,0,1,0,1,1,1,1,0,1,0,1,1,0,1,0,0,1,0,0,1,0,0,0,0,1,1,1,1,1,0,1,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
27 1,0,1,0,1,1,0,1,0,1,1,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,1,1,1,0,1,0,0,0,0,1,1,0,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
28 0,1,1,0,0,0,0,0,0,1,1,1,1,0,1,1,0,0,0,0,1,1,0,0,0,1,0,0,0,0,1,0,1,1,0,0,0,0,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
29 1,0,0,0,0,0,0,0,0,1,0,0,1,0,0,0,0,0,0,0,0,1,0,1,0,1,0,1,1,0,0,0,0,0,0,0,0,0,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
30 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,1,1,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
31 1,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
32 0,0,0,0, |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
33 }; |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
34 |
0
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 main(argc, argv) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 char **argv; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 char *amr_filename, *efr_filename; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int amr_be, efr_be; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 FILE *inf_amr, *inf_efr; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 unsigned frame_no; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 uint8_t amr_bits[COD_FORMAT_NWORDS], efr_bits[ETSI_ENC_NWORDS]; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int rc_amr, rc_efr, amr_sp, efr_sp; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (argc != 5) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 usage: fprintf(stderr, |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 "usage: %s amr-cod-file be|le efr-cod-file be|le\n", |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 argv[0]); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 amr_filename = argv[1]; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!strcmp(argv[2], "be")) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 amr_be = 1; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 else if (!strcmp(argv[2], "le")) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 amr_be = 0; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 else |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 goto usage; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 efr_filename = argv[3]; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (!strcmp(argv[4], "be")) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 efr_be = 1; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 else if (!strcmp(argv[4], "le")) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 efr_be = 0; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 else |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 goto usage; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 inf_amr = fopen(amr_filename, "r"); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 if (!inf_amr) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 perror(amr_filename); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 exit(1); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 inf_efr = fopen(efr_filename, "r"); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (!inf_efr) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 perror(efr_filename); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 exit(1); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 for (frame_no = 0; ; frame_no++) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 rc_amr = read_etsi_bits(inf_amr, amr_be, amr_bits, |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 COD_FORMAT_NWORDS, amr_filename); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 rc_efr = read_etsi_bits(inf_efr, efr_be, efr_bits, |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 ETSI_ENC_NWORDS, efr_filename); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (!rc_amr && !rc_efr) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 break; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (!rc_amr) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 printf("EFR file %s is longer than AMR file %s\n", |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 efr_filename, amr_filename); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 exit(0); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (!rc_efr) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 printf("AMR file %s is longer than EFR file %s\n", |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 amr_filename, efr_filename); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 exit(0); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 /* grok AMR frame type */ |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 switch (amr_bits[0]) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 case TX_SPEECH_GOOD: |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (amr_bits[245] != MR122) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 fprintf(stderr, |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 "error: %s frame #%u is not MR122\n", |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 amr_filename, frame_no); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 exit(1); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 amr_sp = 1; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 break; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 case TX_SID_FIRST: |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 case TX_SID_UPDATE: |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 case TX_NO_DATA: |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 amr_sp = 0; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 break; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 default: |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 fprintf(stderr, |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 "error: %s frame #%u has unknown type %u\n", |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 amr_filename, frame_no, amr_bits[0]); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 exit(1); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 efr_sp = efr_bits[245]; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 if (!amr_sp && !efr_sp) |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 continue; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (!amr_sp || !efr_sp) { |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 printf("frame #%u: AMR SP %d != EFR SP %d\n", frame_no, |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 amr_sp, efr_sp); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 continue; |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
6
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
122 if (!bcmp(amr_bits+1, efr_bits, 244)) |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
123 continue; |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
124 if (!bcmp(amr_bits+1, amr122_dhf_bits, 244) && |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
125 !bcmp(efr_bits, efr_dhf_bits, 244)) |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
126 printf("frame #%u: DHF transform\n", frame_no); |
b55451463161
amrdiff: recognize DHF transform
Mychaela Falconia <falcon@freecalypso.org>
parents:
0
diff
changeset
|
127 else |
0
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 printf("frame #%u: bits differ\n", frame_no); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 exit(0); |
a03c87a2abc6
amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 } |