FreeCalypso > hg > gsm-codec-lib
annotate efrtest/decode-r.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 | 01ce75ea1c8e |
children |
rev | line source |
---|---|
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
2 * gsmefr-decode-r is like gsmefr-decode, but writes the decoded PCM |
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
3 * output in our "robe" format instead of WAV. |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
9 #include "../libgsmefr/gsm_efr.h" |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "../libtest/binreader.h" |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
11 #include "../libtest/robewrite.h" |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 main(argc, argv) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 char **argv; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 { |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
16 FILE *binf, *outf; |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
17 struct EFR_decoder_state *state; |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 uint8_t frame[BINFILE_MAX_FRAME]; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int16_t pcm[160]; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 int rc, bfi, taf; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 if (argc != 3) { |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
23 fprintf(stderr, "usage: %s input.gsmx output.robe\n", argv[0]); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 binf = fopen(argv[1], "r"); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (!binf) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 perror(argv[1]); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
31 outf = fopen(argv[2], "w"); |
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
32 if (!outf) { |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 perror(argv[2]); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 } |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
36 state = EFR_decoder_create(); |
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
37 if (!state) { |
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
38 perror("EFR_decoder_create()"); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 for (;;) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 rc = binfile_read_frame(binf, frame); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (rc < 0) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fprintf(stderr, "error: garbage in %s\n", 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 if (!rc) |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 break; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (frame[0] == 0xBF) { |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 bfi = 1; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 taf = frame[1] & 1; |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
52 } else if ((frame[0] & 0xF0) == 0xC0) |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 bfi = 0; |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 else { |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
55 fprintf(stderr, |
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
56 "error: %s is not in EFR codec format\n", |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 argv[1]); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 exit(1); |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (bfi) |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
61 EFR_decode_bfi_nodata(state, taf, pcm); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 else |
100
d5bab777865a
gsmefr-decode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
16
diff
changeset
|
63 EFR_decode_frame(state, frame, 0, 0, pcm); |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
64 write_pcm_to_robe(outf, pcm); |
12
f88817a233fb
gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
154
01ce75ea1c8e
gsmefr-decode-r utility put together
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
66 fclose(outf); |
12
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 } |