FreeCalypso > hg > gsm-codec-lib
annotate miscutil/tw5a-to-gsmx.c @ 524:ddb2b00d582b
miscutil: new program tw5a-to-gsmx
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 19 Sep 2024 05:02:45 +0000 |
parents | miscutil/tw5a-dump.c@86d4ec69b36c |
children |
rev | line source |
---|---|
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
2 * This program converts FR/EFR speech recordings from TW-TS-005 Annex A |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
3 * hexadecimal format into our older gsmx binary format. |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
471
b5f8ea41362b
gsmrec-dump: report DHF matches
Mychaela Falconia <falcon@freecalypso.org>
parents:
293
diff
changeset
|
9 #include <string.h> |
b5f8ea41362b
gsmrec-dump: report DHF matches
Mychaela Falconia <falcon@freecalypso.org>
parents:
293
diff
changeset
|
10 #include <strings.h> |
281
3816ba89a5a0
gsmrec-dump: use libgsmfr2 instead of old libgsm
Mychaela Falconia <falcon@freecalypso.org>
parents:
128
diff
changeset
|
11 #include "../libgsmfr2/tw_gsmfr.h" |
46
edd2e20e7090
gsmrec-dump: decode EFR frames
Mychaela Falconia <falcon@freecalypso.org>
parents:
23
diff
changeset
|
12 #include "../libgsmefr/gsm_efr.h" |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
13 #include "../libtest/tw5reader.h" |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
14 |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 main(argc, argv) |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char **argv; |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
18 FILE *hexf, *outf; |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
19 unsigned lineno; |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
20 uint8_t frame[TWTS005_MAX_FRAME]; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
21 unsigned frame_len; |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
22 int rc; |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
24 if (argc != 3) { |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
25 fprintf(stderr, "usage: %s input.hex output.gsmx\n", argv[0]); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(1); |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
28 hexf = fopen(argv[1], "r"); |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
29 if (!hexf) { |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 perror(argv[1]); |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 exit(1); |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
33 lineno = 0; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
34 outf = fopen(argv[2], "w"); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
35 if (!outf) { |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
36 perror(argv[2]); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
37 exit(1); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
38 } |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
39 for (;;) { |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
40 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (rc < 0) { |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
42 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
43 argv[1], lineno); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 exit(1); |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (!rc) |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 break; |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
48 switch (frame_len) { |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
49 case 0: |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
50 putc(0xBF, outf); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
51 putc(0, outf); |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
52 break; |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
53 case 1: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
54 if ((frame[0] & 0xF6) != 0xE6) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
55 goto invalid; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
56 putc(0xBF, outf); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
57 putc(frame[0] & 1, outf); |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
58 break; |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
59 case GSMFR_RTP_FRAME_LEN: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
60 if ((frame[0] & 0xF0) != 0xD0) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
61 goto invalid; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
62 fwrite(frame, 1, GSMFR_RTP_FRAME_LEN, outf); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 break; |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
64 case GSMFR_RTP_FRAME_LEN+1: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
65 if ((frame[0] & 0xF4) != 0xE0) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
66 goto invalid; |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
67 if ((frame[1] & 0xF0) != 0xD0) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
68 goto invalid; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
69 if (frame[0] & 0x02) { |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
70 putc(0xBF, outf); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
71 putc(frame[0] & 1, outf); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
72 } else |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
73 fwrite(frame + 1, 1, GSMFR_RTP_FRAME_LEN, outf); |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
74 break; |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
75 case EFR_RTP_FRAME_LEN: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
76 if ((frame[0] & 0xF0) != 0xC0) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
77 goto invalid; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
78 fwrite(frame, 1, EFR_RTP_FRAME_LEN, outf); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 break; |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
80 case EFR_RTP_FRAME_LEN+1: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
81 if ((frame[0] & 0xF4) != 0xE0) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
82 goto invalid; |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
83 if ((frame[1] & 0xF0) != 0xC0) |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
84 goto invalid; |
524
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
85 if (frame[0] & 0x02) { |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
86 putc(0xBF, outf); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
87 putc(frame[0] & 1, outf); |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
88 } else |
ddb2b00d582b
miscutil: new program tw5a-to-gsmx
Mychaela Falconia <falcon@freecalypso.org>
parents:
523
diff
changeset
|
89 fwrite(frame + 1, 1, EFR_RTP_FRAME_LEN, outf); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 break; |
523
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
91 default: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
92 invalid: |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
93 fprintf(stderr, |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
94 "%s line %u: not a valid FR or EFR frame\n", |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
95 argv[1], lineno); |
86d4ec69b36c
miscutil: new program tw5a-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
471
diff
changeset
|
96 exit(1); |
23
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 } |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 exit(0); |
baadb1cb744d
new debug utility gsmrec-dump
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 } |