FreeCalypso > hg > gsm-codec-lib
annotate frtest/cod2std.c @ 281:3816ba89a5a0
gsmrec-dump: use libgsmfr2 instead of old libgsm
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 14 Apr 2024 05:09:52 +0000 |
parents | 6de564ef70d3 |
children | 25649b3a83e9 |
rev | line source |
---|---|
245
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads an FR codec parameters file in ETSI *.cod test sequence |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * format and converts it into classic libgsm format. |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <gsm.h> |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static void |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 bytes_to_params(bytes, params, big_endian) |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 uint8_t *bytes; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 gsm_signal *params; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 uint8_t *sp; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 unsigned n; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 uint16_t val; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 sp = bytes; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 for (n = 0; n < 76; n++) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (big_endian) |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 val = ((uint16_t) sp[0] << 8) | ((uint16_t) sp[1]); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 else |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 val = ((uint16_t) sp[1] << 8) | ((uint16_t) sp[0]); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 params[n] = val; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 sp += 2; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 main(argc, argv) |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 char **argv; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 char *infname, *outfname; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 FILE *inf, *outf; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 gsm dummy_state; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int big_endian; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 unsigned frame_no; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 uint8_t input_bytes[76*2], frame[33]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 gsm_signal params[76]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 int cc; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (argc == 3 && argv[1][0] != '-') { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 big_endian = 0; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 infname = argv[1]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 outfname = argv[2]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 } else if (argc == 4 && !strcmp(argv[1], "-b")) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 big_endian = 1; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 infname = argv[2]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 outfname = argv[3]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } else { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, "usage: %s [-b] input.cod output.gsm\n", |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 argv[0]); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 inf = fopen(infname, "r"); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 if (!inf) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 perror(infname); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 outf = fopen(outfname, "w"); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 if (!outf) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 perror(outfname); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 dummy_state = gsm_create(); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (!dummy_state) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 fprintf(stderr, "gsm_create() failed!\n"); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 for (frame_no = 0; ; frame_no++) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 cc = fread(input_bytes, 2, 76, inf); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (cc == 0) |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 break; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 if (cc != 76) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 fprintf(stderr, "error: short read from %s\n", infname); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 bytes_to_params(input_bytes, params, big_endian); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 gsm_implode(dummy_state, params, frame); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 fwrite(frame, 1, sizeof frame, outf); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 fclose(outf); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 exit(0); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |