annotate efrtest/decode-tw5.c @ 552:6ab066180ec2

doc: new article FR1-Rx-DTX-detail
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 07 Oct 2024 00:25:50 +0000
parents f9535c1fbf70
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
12
f88817a233fb gsmfr-decode test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
547
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
2 * This file is the main module for gsmefr-decode-tw5 utility. It is just
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
3 * like the original gsmefr-decode, but reads the GSM-EFR speech recording
537
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>
547
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
11 #include "../libgsmefr/gsm_efr.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;
547
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
22 struct EFR_decoder_state *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 }
547
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
43 state = EFR_decoder_create();
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
44 if (!state) {
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
45 perror("EFR_decoder_create()");
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;
547
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
57 rc = EFR_decode_rtp(state, frame, frame_len, pcm);
537
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,
547
f9535c1fbf70 efrtest: new program gsmefr-decode-tw5
Mychaela Falconia <falcon@freecalypso.org>
parents: 537
diff changeset
60 "%s line %u: not a valid GSM-EFR frame\n",
537
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 }