FreeCalypso > hg > gsm-codec-lib
comparison efrtest/dlcap-dec.c @ 164:5f23cb3f0f8d
gsmefr-dlcap-dec program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 16 Dec 2022 03:05:21 +0000 |
parents | efrtest/dlcap-gsmx.c@3bbb16015a79 |
children |
comparison
equal
deleted
inserted
replaced
163:3bbb16015a79 | 164:5f23cb3f0f8d |
---|---|
1 /* | |
2 * This program reads a TCH/EFS downlink capture produced with FreeCalypso tools | |
3 * (fw version with TCH downlink sniffing feature and fc-shell tch record) | |
4 * and feeds it to our libgsmefr decoder, making our best attempt to | |
5 * replicate the processing steps that must be performed by the original DSP. | |
6 * | |
7 * The output format is "robe" (raw big-endian). | |
8 */ | |
9 | |
10 #include <ctype.h> | |
11 #include <stdio.h> | |
12 #include <stdint.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <strings.h> | |
16 #include "../libgsmefr/gsm_efr.h" | |
17 | |
18 main(argc, argv) | |
19 char **argv; | |
20 { | |
21 FILE *inf, *outf; | |
22 struct EFR_decoder_state *state; | |
23 char linebuf[128]; | |
24 int lineno, rc; | |
25 uint16_t status_words[3]; | |
26 uint8_t tidsp_bytes[33], frame[EFR_RTP_FRAME_LEN]; | |
27 int16_t params[EFR_NUM_PARAMS], pcm[160]; | |
28 unsigned fn_mod_104; | |
29 int bfi, taf, sid; | |
30 | |
31 if (argc != 3) { | |
32 fprintf(stderr, "usage: %s infile outfile\n", argv[0]); | |
33 exit(1); | |
34 } | |
35 inf = fopen(argv[1], "r"); | |
36 if (!inf) { | |
37 perror(argv[1]); | |
38 exit(1); | |
39 } | |
40 outf = fopen(argv[2], "w"); | |
41 if (!outf) { | |
42 perror(argv[2]); | |
43 exit(1); | |
44 } | |
45 state = EFR_decoder_create(); | |
46 if (!state) { | |
47 perror("EFR_decoder_create()"); | |
48 exit(1); | |
49 } | |
50 for (lineno = 1; fgets(linebuf, sizeof linebuf, inf); lineno++) { | |
51 /* support both old and new formats */ | |
52 if (isxdigit(linebuf[0]) && isxdigit(linebuf[1]) && | |
53 isxdigit(linebuf[2]) && isxdigit(linebuf[3])) { | |
54 rc = parse_dlcap_common(linebuf, status_words, | |
55 tidsp_bytes); | |
56 if (rc < 0) { | |
57 invalid: fprintf(stderr, | |
58 "error: %s is not in the expected format\n", | |
59 argv[1]); | |
60 exit(1); | |
61 } | |
62 fn_mod_104 = 0; /* won't have TAF */ | |
63 } else if (!strncmp(linebuf, "EFR ", 4)) { | |
64 rc = parse_dlcap_common(linebuf + 4, status_words, | |
65 tidsp_bytes); | |
66 if (rc < 0) | |
67 goto invalid; | |
68 if (linebuf[85] != ' ') | |
69 goto invalid; | |
70 if (!isdigit(linebuf[86])) | |
71 goto invalid; | |
72 fn_mod_104 = strtoul(linebuf + 86, 0, 10); | |
73 } else | |
74 goto invalid; | |
75 /* processing, hoping to replicate what the DSP does */ | |
76 efr_tidsp_to_std(tidsp_bytes, frame); | |
77 EFR_frame2params(frame, params); | |
78 bfi = (status_words[0] & 0x0204) != 0; | |
79 sid = (status_words[0] & 0x0018) >> 3; | |
80 taf = fn_mod_104 == 60; | |
81 EFR_decode_params(state, params, bfi, sid, taf, pcm); | |
82 write_pcm_to_robe(outf, pcm); | |
83 } | |
84 exit(0); | |
85 } |