FreeCalypso > hg > gsm-codec-lib
annotate frtest/max-out.c @ 183:452c1d5a6268
libgsmefr BFI w/o data: emit zero output after decoder reset
In real-life usage, each EFR decoder session will most likely begin
with lots of BFI frames before the first real frame arrives. However,
because the spec-defined home state of the decoder is speech rather
than CN, our regular logic for BFI w/o data would have to feed
pseudorandom noise to the decoder (in the "fixed codebook excitation
pulses" part), which is silly to do at the beginning of the decoder
session right out of reset. Therefore, let's check reset_flag_old,
and if we are still in the reset state, simply emit zero output.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 03 Jan 2023 00:12:18 +0000 |
parents | a5ffec18e4cd |
children |
rev | line source |
---|---|
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
28
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
2 * This program reads an extended-libgsm binary file (which must be in FR |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
3 * codec format, not EFR) and performs the following processing, in this |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
4 * order: |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
5 * |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
6 * 1) dumps every frame in human-readable form just like gsmrec-dump; |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
7 * 2) passes the frame stream through our DTX Rx preprocessor; |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
8 * 3) dumps the output from the preprocessor; |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
9 * 4) feeds this output to the standard 06.10 decoder (libgsm); |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
10 * 5) finds the highest-magnitude PCM sample in the decoder output and |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
11 * reports this maximum output magnitude. |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
12 * |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
13 * This program is intended to serve as a debug aid, for troubleshooting |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
14 * of our libgsmfrp+libgsm stack. |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 */ |
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 #include <stdio.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 #include <stdint.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 #include <stdlib.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 #include <gsm.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 #include "../libgsmfrp/gsm_fr_preproc.h" |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 #include "../libtest/binreader.h" |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 main(argc, argv) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 char **argv; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 FILE *binf; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 gsm dec_state; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 struct gsmfr_preproc_state *pp_state; |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
30 unsigned frame_index; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 uint8_t frame[BINFILE_MAX_FRAME]; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 int16_t pcm[160]; |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
33 gsm_signal fr_params[76]; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 int rc, bfi, taf; |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
35 int i, j, n; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
36 unsigned samp_abs, samp_max; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
38 if (argc != 2) { |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
39 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
|
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 binf = fopen(argv[1], "r"); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (!binf) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 perror(argv[1]); |
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 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 dec_state = gsm_create(); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if (!dec_state) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, "gsm_create() failed!\n"); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 pp_state = gsmfr_preproc_create(); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (!pp_state) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, "gsmfr_preproc_create() failed!\n"); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
57 for (frame_index = 0; ; frame_index++) { |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 rc = binfile_read_frame(binf, frame); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (rc < 0) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 fprintf(stderr, "error: garbage in %s\n", argv[1]); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (!rc) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 break; |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
65 printf("#%u: ", frame_index); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
66 switch (frame[0] & 0xF0) { |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
67 case 0xB0: |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 bfi = 1; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 taf = frame[1] & 1; |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
70 printf("BFI TAF=%u\n", taf); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
71 break; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
72 case 0xD0: |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
73 bfi = 0; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
74 fputs("FR", stdout); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
75 gsm_explode(dec_state, frame, fr_params); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
76 n = 0; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
77 for (i = 0; i < 8; i++) |
128
a5ffec18e4cd
test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
78 printf(" %d", fr_params[n++]); |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
79 putchar('\n'); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
80 for (i = 0; i < 4; i++) { |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
81 putchar(' '); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
82 for (j = 0; j < 17; j++) |
128
a5ffec18e4cd
test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
83 printf(" %d", fr_params[n++]); |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
84 putchar('\n'); |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
85 } |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
86 break; |
27
896ce7f1d271
frtest: cn-debug is now gsmfr-max-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
87 default: |
896ce7f1d271
frtest: cn-debug is now gsmfr-max-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
88 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
|
89 argv[1]); |
896ce7f1d271
frtest: cn-debug is now gsmfr-max-out
Mychaela Falconia <falcon@freecalypso.org>
parents:
26
diff
changeset
|
90 exit(1); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (bfi) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 gsmfr_preproc_bfi(pp_state, taf, frame); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 else |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 gsmfr_preproc_good_frame(pp_state, frame); |
28
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
96 fputs("Xform:", stdout); |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
97 gsm_explode(dec_state, frame, fr_params); |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
98 n = 0; |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
99 for (i = 0; i < 8; i++) |
128
a5ffec18e4cd
test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
100 printf(" %d", fr_params[n++]); |
28
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
101 putchar('\n'); |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
102 for (i = 0; i < 4; i++) { |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
103 putchar(' '); |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
104 for (j = 0; j < 17; j++) |
128
a5ffec18e4cd
test programs: use printf %d format for codec parameters
Mychaela Falconia <falcon@freecalypso.org>
parents:
28
diff
changeset
|
105 printf(" %d", fr_params[n++]); |
28
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
106 putchar('\n'); |
a8fd4ff6b013
gsmfr-max-out: dump transformed codec parameters too
Mychaela Falconia <falcon@freecalypso.org>
parents:
27
diff
changeset
|
107 } |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 gsm_decode(dec_state, frame, pcm); |
26
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
109 samp_max = 0; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
110 for (i = 0; i < 160; i++) { |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
111 if (pcm[i] >= 0) |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
112 samp_abs = pcm[i]; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
113 else |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
114 samp_abs = -pcm[i]; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
115 if (samp_abs > samp_max) |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
116 samp_max = samp_abs; |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
117 } |
40fcd89d8823
frtest: cn-debug utility added
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
118 printf(" MAX=%u\n", samp_max); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 exit(0); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |