FreeCalypso > hg > gsm-codec-lib
annotate frtest/decode-tw5.c @ 581:e2d5cad04cbf
libgsmhr1 RxFE: store CN R0+LPC separately from speech
In the original GSM 06.06 code the ECU for speech mode is entirely
separate from the CN generator, maintaining separate state. (The
main intertie between them is the speech vs CN state variable,
distinguishing between speech and CN BFIs, in addition to the
CN-specific function of distinguishing between initial and update
SIDs.)
In the present RxFE implementation I initially thought that we could
use the same saved_frame buffer for both ECU and CN, overwriting
just the first 4 params (R0 and LPC) when a valid SID comes in.
However, I now realize it was a bad idea: the original code has a
corner case (long sequence of speech-mode BFIs to put the ECU in
state 6, then SID and CN-mode BFIs, then a good speech frame) that
would be broken by that buffer reuse approach. We could eliminate
this corner case by resetting the ECU state when passing through
a CN insertion period, but doing so would needlessly increase
the behavioral diffs between GSM 06.06 and our version.
Solution: use a separate CN-specific buffer for CN R0+LPC parameters,
and match the behavior of GSM 06.06 code in this regard.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 13 Feb 2025 10:02:45 +0000 |
parents | f9eefb61fb2f |
children |
rev | line source |
---|---|
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
2 * This file is the main module for gsmfr-decode-tw5 utility. It is just |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
3 * like the original gsmfr-decode, but reads the GSM-FR speech recording |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
4 * from TW-TS-005 Annex A hexadecimal format instead of the old gsmx |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
5 * binary format. |
12
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 |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
284
8d3cfa65a6c2
gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
11 #include "../libgsmfr2/tw_gsmfr.h" |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
12 #include "../libtest/tw5reader.h" |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../libtest/wavwriter.h" |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include "../libtest/pcmwrite.h" |
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 main(argc, argv) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 char **argv; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 { |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
19 FILE *hexf; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 void *wav; |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
21 unsigned lineno; |
284
8d3cfa65a6c2
gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
22 struct gsmfr_fulldec_state *fd_state; |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
23 uint8_t frame[TWTS005_MAX_FRAME]; |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
24 unsigned frame_len; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int16_t pcm[160]; |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
26 int rc; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (argc != 3) { |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
29 fprintf(stderr, "usage: %s input.hex output.wav\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 } |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
32 hexf = fopen(argv[1], "r"); |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
33 if (!hexf) { |
12
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 } |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
37 lineno = 0; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 wav = wav_write_open(argv[2], 8000, 16, 1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (!wav) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 perror(argv[2]); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
284
8d3cfa65a6c2
gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
43 fd_state = gsmfr_fulldec_create(); |
8d3cfa65a6c2
gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
44 if (!fd_state) { |
8d3cfa65a6c2
gsmfr-decode: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
45 fprintf(stderr, "gsmfr_fulldec_create() failed!\n"); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 for (;;) { |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
49 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) { |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
51 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
52 argv[1], lineno); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 if (!rc) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 break; |
537
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
57 rc = gsmfr_fulldec_rtp_in(fd_state, frame, frame_len, pcm); |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
58 if (rc < 0) { |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
59 fprintf(stderr, |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
60 "%s line %u: not a valid GSM-FR frame\n", |
f9eefb61fb2f
frtest: new program gsmfr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents:
284
diff
changeset
|
61 argv[1], lineno); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 write_pcm_to_wav(wav, pcm); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 wav_write_close(wav); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 exit(0); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |