comparison 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
comparison
equal deleted inserted replaced
-1:000000000000 0:a03c87a2abc6
1 /*
2 * This program reads two ETSI/3GPP test sequence files, one from
3 * the AMR set of 3GPP TS 26.074 and the other from the "EFR2" set of
4 * amr122_efr.zip, and performs a diff between them.
5 */
6
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include "etsi.h"
13 #include "amr_defs.h"
14
15 main(argc, argv)
16 char **argv;
17 {
18 char *amr_filename, *efr_filename;
19 int amr_be, efr_be;
20 FILE *inf_amr, *inf_efr;
21 unsigned frame_no;
22 uint8_t amr_bits[COD_FORMAT_NWORDS], efr_bits[ETSI_ENC_NWORDS];
23 int rc_amr, rc_efr, amr_sp, efr_sp;
24
25 if (argc != 5) {
26 usage: fprintf(stderr,
27 "usage: %s amr-cod-file be|le efr-cod-file be|le\n",
28 argv[0]);
29 exit(1);
30 }
31 amr_filename = argv[1];
32 if (!strcmp(argv[2], "be"))
33 amr_be = 1;
34 else if (!strcmp(argv[2], "le"))
35 amr_be = 0;
36 else
37 goto usage;
38 efr_filename = argv[3];
39 if (!strcmp(argv[4], "be"))
40 efr_be = 1;
41 else if (!strcmp(argv[4], "le"))
42 efr_be = 0;
43 else
44 goto usage;
45 inf_amr = fopen(amr_filename, "r");
46 if (!inf_amr) {
47 perror(amr_filename);
48 exit(1);
49 }
50 inf_efr = fopen(efr_filename, "r");
51 if (!inf_efr) {
52 perror(efr_filename);
53 exit(1);
54 }
55 for (frame_no = 0; ; frame_no++) {
56 rc_amr = read_etsi_bits(inf_amr, amr_be, amr_bits,
57 COD_FORMAT_NWORDS, amr_filename);
58 rc_efr = read_etsi_bits(inf_efr, efr_be, efr_bits,
59 ETSI_ENC_NWORDS, efr_filename);
60 if (!rc_amr && !rc_efr)
61 break;
62 if (!rc_amr) {
63 printf("EFR file %s is longer than AMR file %s\n",
64 efr_filename, amr_filename);
65 exit(0);
66 }
67 if (!rc_efr) {
68 printf("AMR file %s is longer than EFR file %s\n",
69 amr_filename, efr_filename);
70 exit(0);
71 }
72 /* grok AMR frame type */
73 switch (amr_bits[0]) {
74 case TX_SPEECH_GOOD:
75 if (amr_bits[245] != MR122) {
76 fprintf(stderr,
77 "error: %s frame #%u is not MR122\n",
78 amr_filename, frame_no);
79 exit(1);
80 }
81 amr_sp = 1;
82 break;
83 case TX_SID_FIRST:
84 case TX_SID_UPDATE:
85 case TX_NO_DATA:
86 amr_sp = 0;
87 break;
88 default:
89 fprintf(stderr,
90 "error: %s frame #%u has unknown type %u\n",
91 amr_filename, frame_no, amr_bits[0]);
92 exit(1);
93 }
94 efr_sp = efr_bits[245];
95 if (!amr_sp && !efr_sp)
96 continue;
97 if (!amr_sp || !efr_sp) {
98 printf("frame #%u: AMR SP %d != EFR SP %d\n", frame_no,
99 amr_sp, efr_sp);
100 continue;
101 }
102 if (bcmp(amr_bits+1, efr_bits, 244))
103 printf("frame #%u: bits differ\n", frame_no);
104 }
105 exit(0);
106 }