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