comparison frtest/max-out.c @ 27:896ce7f1d271

frtest: cn-debug is now gsmfr-max-out
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 20 Nov 2022 23:04:27 +0000
parents frtest/cn-debug.c@40fcd89d8823
children a8fd4ff6b013
comparison
equal deleted inserted replaced
26:40fcd89d8823 27:896ce7f1d271
1 /*
2 * This program reads an extended-libgsm binary file, dumps every frame in
3 * human-readable form just like gsmrec-dump, but then also passes it through
4 * our GSM FR decoder (libgsmfrp+libgsm) and looks for the highest-magnitude
5 * PCM sample in the decoder output. This maximum output sample magnitude is
6 * reported after the dump of each input frame. This program is intended to
7 * serve as a debug aid, for troubleshooting of our libgsmfrp+libgsm stack.
8 */
9
10 #include <stdio.h>
11 #include <stdint.h>
12 #include <stdlib.h>
13 #include <gsm.h>
14 #include "../libgsmfrp/gsm_fr_preproc.h"
15 #include "../libtest/binreader.h"
16
17 main(argc, argv)
18 char **argv;
19 {
20 FILE *binf;
21 gsm dec_state;
22 struct gsmfr_preproc_state *pp_state;
23 unsigned frame_index;
24 uint8_t frame[BINFILE_MAX_FRAME];
25 int16_t pcm[160];
26 gsm_signal fr_params[76];
27 int rc, bfi, taf;
28 int i, j, n;
29 unsigned samp_abs, samp_max;
30
31 if (argc != 2) {
32 fprintf(stderr, "usage: %s bin-stream-file\n", argv[0]);
33 exit(1);
34 }
35 binf = fopen(argv[1], "r");
36 if (!binf) {
37 perror(argv[1]);
38 exit(1);
39 }
40 dec_state = gsm_create();
41 if (!dec_state) {
42 fprintf(stderr, "gsm_create() failed!\n");
43 exit(1);
44 }
45 pp_state = gsmfr_preproc_create();
46 if (!pp_state) {
47 fprintf(stderr, "gsmfr_preproc_create() failed!\n");
48 exit(1);
49 }
50 for (frame_index = 0; ; frame_index++) {
51 rc = binfile_read_frame(binf, frame);
52 if (rc < 0) {
53 fprintf(stderr, "error: garbage in %s\n", argv[1]);
54 exit(1);
55 }
56 if (!rc)
57 break;
58 printf("#%u: ", frame_index);
59 switch (frame[0] & 0xF0) {
60 case 0xB0:
61 bfi = 1;
62 taf = frame[1] & 1;
63 printf("BFI TAF=%u\n", taf);
64 break;
65 case 0xD0:
66 bfi = 0;
67 fputs("FR", stdout);
68 gsm_explode(dec_state, frame, fr_params);
69 n = 0;
70 for (i = 0; i < 8; i++)
71 printf(" %u", fr_params[n++]);
72 putchar('\n');
73 for (i = 0; i < 4; i++) {
74 putchar(' ');
75 for (j = 0; j < 17; j++)
76 printf(" %u", fr_params[n++]);
77 putchar('\n');
78 }
79 break;
80 default:
81 fprintf(stderr, "error: %s is not in FR codec format\n",
82 argv[1]);
83 exit(1);
84 }
85 if (bfi)
86 gsmfr_preproc_bfi(pp_state, taf, frame);
87 else
88 gsmfr_preproc_good_frame(pp_state, frame);
89 gsm_decode(dec_state, frame, pcm);
90 samp_max = 0;
91 for (i = 0; i < 160; i++) {
92 if (pcm[i] >= 0)
93 samp_abs = pcm[i];
94 else
95 samp_abs = -pcm[i];
96 if (samp_abs > samp_max)
97 samp_max = samp_abs;
98 }
99 printf(" MAX=%u\n", samp_max);
100 }
101 exit(0);
102 }