FreeCalypso > hg > gsm-codec-lib
annotate efrtest/encode.c @ 242:f081a6850fb5
libgsmfrp: new refined implementation
The previous implementation exhibited the following defects,
which are now fixed:
1) The last received valid SID was cached forever for the purpose of
handling future invalid SIDs - we could have received some valid
SID ages ago, then lots of speech or NO_DATA, and if we then get
an invalid SID, we would resurrect the last valid SID from ancient
history - a bad design. In our new design, we handle invalid SID
based on the current state, much like BFI.
2) GSM 06.11 spec says clearly that after the second lost SID
(received BFI=1 && TAF=1 in CN state) we need to gradually decrease
the output level, rather than jump directly to emitting silence
frames - we previously failed to implement such logic.
3) Per GSM 06.12 section 5.2, Xmaxc should be the same in all 4 subframes
in a SID frame. What should we do if we receive an otherwise valid
SID frame with different Xmaxc? Our previous approach would
replicate this Xmaxc oddity in every subsequent generated CN frame,
which is rather bad. In our new design, the very first CN frame
(which can be seen as a transformation of the SID frame itself)
retains the original 4 distinct Xmaxc, but all subsequent CN frames
are based on the Xmaxc from the last subframe of the most recent SID.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 09 May 2023 05:16:31 +0000 |
parents | b51295fcbbae |
children |
rev | line source |
---|---|
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
2 * This file is the main module for gsmefr-encode utility. |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdint.h> |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdlib.h> |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
8 #include <string.h> |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
9 #include <strings.h> |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
10 #include "../libgsmefr/gsm_efr.h" |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "../libtest/wavreader.h" |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "../libtest/wavrdhelp.h" |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 main(argc, argv) |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
17 char *infname, *outfname; |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 void *wav; |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 FILE *binf; |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
20 struct EFR_encoder_state *state; |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int16_t pcm[160]; |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
22 uint8_t frame[EFR_RTP_FRAME_LEN]; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
23 int dtx, rc; |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
25 if (argc == 3 && argv[1][0] != '-') { |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
26 dtx = 0; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
27 infname = argv[1]; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
28 outfname = argv[2]; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
29 } else if (argc == 4 && !strcmp(argv[1], "-d")) { |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
30 dtx = 1; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
31 infname = argv[2]; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
32 outfname = argv[3]; |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
33 } else { |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
34 fprintf(stderr, "usage: %s [-d] input.wav output.gsmx\n", |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
35 argv[0]); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 exit(1); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 } |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
38 wav = wav_read_open(infname); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 if (!wav) { |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
40 perror(infname); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 exit(1); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 } |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
43 rc = wavrd_check_header(wav, infname); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 exit(1); /* error msg already printed */ |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
46 binf = fopen(outfname, "w"); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 if (!binf) { |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
48 perror(outfname); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(1); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
51 state = EFR_encoder_create(dtx); |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
52 if (!state) { |
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
53 perror("EFR_encoder_create()"); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 for (;;) { |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 rc = wavrd_get_pcm_block(wav, pcm); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!rc) |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 break; |
121
b51295fcbbae
gsmefr-encode utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
60 EFR_encode_frame(state, pcm, frame, (int *) 0, (int *) 0); |
14
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 fwrite(frame, 1, sizeof frame, binf); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fclose(binf); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(0); |
69ed7af28473
gsmfr-encode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |