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