comparison frtest/decode-tw5.c @ 537:f9eefb61fb2f

frtest: new program gsmfr-decode-tw5
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 21 Sep 2024 23:31:25 +0000
parents frtest/decode.c@8d3cfa65a6c2
children
comparison
equal deleted inserted replaced
536:a3300483ae74 537:f9eefb61fb2f
1 /*
2 * This file is the main module for gsmfr-decode-tw5 utility. It is just
3 * like the original gsmfr-decode, but reads the GSM-FR speech recording
4 * from TW-TS-005 Annex A hexadecimal format instead of the old gsmx
5 * binary format.
6 */
7
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include "../libgsmfr2/tw_gsmfr.h"
12 #include "../libtest/tw5reader.h"
13 #include "../libtest/wavwriter.h"
14 #include "../libtest/pcmwrite.h"
15
16 main(argc, argv)
17 char **argv;
18 {
19 FILE *hexf;
20 void *wav;
21 unsigned lineno;
22 struct gsmfr_fulldec_state *fd_state;
23 uint8_t frame[TWTS005_MAX_FRAME];
24 unsigned frame_len;
25 int16_t pcm[160];
26 int rc;
27
28 if (argc != 3) {
29 fprintf(stderr, "usage: %s input.hex output.wav\n", argv[0]);
30 exit(1);
31 }
32 hexf = fopen(argv[1], "r");
33 if (!hexf) {
34 perror(argv[1]);
35 exit(1);
36 }
37 lineno = 0;
38 wav = wav_write_open(argv[2], 8000, 16, 1);
39 if (!wav) {
40 perror(argv[2]);
41 exit(1);
42 }
43 fd_state = gsmfr_fulldec_create();
44 if (!fd_state) {
45 fprintf(stderr, "gsmfr_fulldec_create() failed!\n");
46 exit(1);
47 }
48 for (;;) {
49 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len);
50 if (rc < 0) {
51 fprintf(stderr, "%s line %u: not valid TW-TS-005\n",
52 argv[1], lineno);
53 exit(1);
54 }
55 if (!rc)
56 break;
57 rc = gsmfr_fulldec_rtp_in(fd_state, frame, frame_len, pcm);
58 if (rc < 0) {
59 fprintf(stderr,
60 "%s line %u: not a valid GSM-FR frame\n",
61 argv[1], lineno);
62 exit(1);
63 }
64 write_pcm_to_wav(wav, pcm);
65 }
66 wav_write_close(wav);
67 exit(0);
68 }