annotate amrdiff/amrdiff.c @ 0:a03c87a2abc6

amrdiff program written
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 03 Apr 2024 18:44:27 +0000
parents
children b55451463161
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 main(argc, argv)
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 char **argv;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 char *amr_filename, *efr_filename;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int amr_be, efr_be;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 FILE *inf_amr, *inf_efr;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 unsigned frame_no;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 uint8_t amr_bits[COD_FORMAT_NWORDS], efr_bits[ETSI_ENC_NWORDS];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 int rc_amr, rc_efr, amr_sp, efr_sp;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 if (argc != 5) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 usage: fprintf(stderr,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 "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
28 argv[0]);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 amr_filename = argv[1];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 if (!strcmp(argv[2], "be"))
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 amr_be = 1;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 else if (!strcmp(argv[2], "le"))
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 amr_be = 0;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 else
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 goto usage;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 efr_filename = argv[3];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 if (!strcmp(argv[4], "be"))
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 efr_be = 1;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 else if (!strcmp(argv[4], "le"))
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 efr_be = 0;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 else
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 goto usage;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 inf_amr = fopen(amr_filename, "r");
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 if (!inf_amr) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 perror(amr_filename);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 inf_efr = fopen(efr_filename, "r");
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 if (!inf_efr) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 perror(efr_filename);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 for (frame_no = 0; ; frame_no++) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 rc_amr = read_etsi_bits(inf_amr, amr_be, amr_bits,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 COD_FORMAT_NWORDS, amr_filename);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 rc_efr = read_etsi_bits(inf_efr, efr_be, efr_bits,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 ETSI_ENC_NWORDS, efr_filename);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 if (!rc_amr && !rc_efr)
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 break;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 if (!rc_amr) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 printf("EFR file %s is longer than AMR file %s\n",
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 efr_filename, amr_filename);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(0);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (!rc_efr) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 printf("AMR file %s is longer than EFR file %s\n",
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 amr_filename, efr_filename);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 exit(0);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 /* grok AMR frame type */
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 switch (amr_bits[0]) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 case TX_SPEECH_GOOD:
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (amr_bits[245] != MR122) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 fprintf(stderr,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 "error: %s frame #%u is not MR122\n",
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 amr_filename, frame_no);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 amr_sp = 1;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 break;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 case TX_SID_FIRST:
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 case TX_SID_UPDATE:
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 case TX_NO_DATA:
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 amr_sp = 0;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 break;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 default:
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 fprintf(stderr,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 "error: %s frame #%u has unknown type %u\n",
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 amr_filename, frame_no, amr_bits[0]);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 exit(1);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 efr_sp = efr_bits[245];
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (!amr_sp && !efr_sp)
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 continue;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (!amr_sp || !efr_sp) {
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 printf("frame #%u: AMR SP %d != EFR SP %d\n", frame_no,
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 amr_sp, efr_sp);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 continue;
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 if (bcmp(amr_bits+1, efr_bits, 244))
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 printf("frame #%u: bits differ\n", frame_no);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 }
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 exit(0);
a03c87a2abc6 amrdiff program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 }