FreeCalypso > hg > gsm-codec-lib
annotate frtest/decode-tw5.c @ 546:b26df31124a4
frtest: new program gsmfr-tfo-xfrm
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 04 Oct 2024 19:07:52 +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 } |