annotate frtest/cn-debug.c @ 26:40fcd89d8823

frtest: cn-debug utility added
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 20 Nov 2022 18:08:41 +0000
parents frtest/decode.c@b9a842775f40
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
2 * This program has been written as part of the debug investigation,
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
3 * seeking to understand how and why our FR comfort noise generator
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
4 * is currently broken.
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 */
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <gsm.h>
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "../libgsmfrp/gsm_fr_preproc.h"
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "../libtest/binreader.h"
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 main(argc, argv)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char **argv;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 FILE *binf;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 gsm dec_state;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 struct gsmfr_preproc_state *pp_state;
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
20 unsigned frame_index;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 uint8_t frame[BINFILE_MAX_FRAME];
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int16_t pcm[160];
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
23 gsm_signal fr_params[76];
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int rc, bfi, taf;
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
25 int i, j, n;
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
26 unsigned samp_abs, samp_max;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
28 if (argc != 2) {
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
29 fprintf(stderr, "usage: %s bin-stream-file\n", argv[0]);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 binf = fopen(argv[1], "r");
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (!binf) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 perror(argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 dec_state = gsm_create();
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (!dec_state) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 fprintf(stderr, "gsm_create() failed!\n");
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 pp_state = gsmfr_preproc_create();
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (!pp_state) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 fprintf(stderr, "gsmfr_preproc_create() failed!\n");
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
47 for (frame_index = 0; ; frame_index++) {
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 rc = binfile_read_frame(binf, frame);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (rc < 0) {
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 fprintf(stderr, "error: garbage in %s\n", argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 exit(1);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 if (!rc)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 break;
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
55 printf("#%u: ", frame_index);
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
56 switch (frame[0] & 0xF0) {
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
57 case 0xB0:
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 bfi = 1;
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 taf = frame[1] & 1;
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
60 printf("BFI TAF=%u\n", taf);
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
61 break;
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
62 case 0xC0:
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 fprintf(stderr, "error: %s is not in FR codec format\n",
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 argv[1]);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 exit(1);
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
66 case 0xD0:
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
67 bfi = 0;
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
68 fputs("FR", stdout);
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
69 gsm_explode(dec_state, frame, fr_params);
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
70 n = 0;
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
71 for (i = 0; i < 8; i++)
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
72 printf(" %u", fr_params[n++]);
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
73 putchar('\n');
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
74 for (i = 0; i < 4; i++) {
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
75 putchar(' ');
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
76 for (j = 0; j < 17; j++)
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
77 printf(" %u", fr_params[n++]);
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
78 putchar('\n');
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
79 }
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
80 break;
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (bfi)
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 gsmfr_preproc_bfi(pp_state, taf, frame);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 else
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 gsmfr_preproc_good_frame(pp_state, frame);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 gsm_decode(dec_state, frame, pcm);
26
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
87 samp_max = 0;
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
88 for (i = 0; i < 160; i++) {
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
89 if (pcm[i] >= 0)
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
90 samp_abs = pcm[i];
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
91 else
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
92 samp_abs = -pcm[i];
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
93 if (samp_abs > samp_max)
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
94 samp_max = samp_abs;
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
95 }
40fcd89d8823 frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents: 16
diff changeset
96 printf(" MAX=%u\n", samp_max);
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 exit(0);
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }