FreeCalypso > hg > gsm-codec-lib
comparison efrtest/decode-tw5.c @ 547:f9535c1fbf70
efrtest: new program gsmefr-decode-tw5
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 04 Oct 2024 20:17:36 +0000 |
parents | frtest/decode-tw5.c@f9eefb61fb2f |
children |
comparison
equal
deleted
inserted
replaced
546:b26df31124a4 | 547:f9535c1fbf70 |
---|---|
1 /* | |
2 * This file is the main module for gsmefr-decode-tw5 utility. It is just | |
3 * like the original gsmefr-decode, but reads the GSM-EFR 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 "../libgsmefr/gsm_efr.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 EFR_decoder_state *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 state = EFR_decoder_create(); | |
44 if (!state) { | |
45 perror("EFR_decoder_create()"); | |
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 = EFR_decode_rtp(state, frame, frame_len, pcm); | |
58 if (rc < 0) { | |
59 fprintf(stderr, | |
60 "%s line %u: not a valid GSM-EFR 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 } |