FreeCalypso > hg > gsm-codec-lib
annotate frtest/cod2std.c @ 345:29769a9b89d3
libtwamr: integrate d_plsf_5.c
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Apr 2024 01:27:10 +0000 |
parents | 25649b3a83e9 |
children |
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> |
283
25649b3a83e9
gsmfr-cod2std: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
245
diff
changeset
|
11 #include "../libgsmfr2/tw_gsmfr.h" |
245
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; |
283
25649b3a83e9
gsmfr-cod2std: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
245
diff
changeset
|
16 int16_t *params; |
245
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 int big_endian; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 unsigned frame_no; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 uint8_t input_bytes[76*2], frame[33]; |
283
25649b3a83e9
gsmfr-cod2std: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
245
diff
changeset
|
41 int16_t params[76]; |
245
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 int cc; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (argc == 3 && argv[1][0] != '-') { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 big_endian = 0; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 infname = argv[1]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 outfname = argv[2]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } else if (argc == 4 && !strcmp(argv[1], "-b")) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 big_endian = 1; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 infname = argv[2]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 outfname = argv[3]; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } else { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "usage: %s [-b] input.cod output.gsm\n", |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 argv[0]); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 inf = fopen(infname, "r"); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 if (!inf) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 perror(infname); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 outf = fopen(outfname, "w"); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (!outf) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 perror(outfname); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 for (frame_no = 0; ; frame_no++) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 cc = fread(input_bytes, 2, 76, inf); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 if (cc == 0) |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 break; |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 if (cc != 76) { |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 fprintf(stderr, "error: short read from %s\n", infname); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 exit(1); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 bytes_to_params(input_bytes, params, big_endian); |
283
25649b3a83e9
gsmfr-cod2std: convert to libgsmfr2
Mychaela Falconia <falcon@freecalypso.org>
parents:
245
diff
changeset
|
76 gsmfr_pack_from_array(params, frame); |
245
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 fwrite(frame, 1, sizeof frame, outf); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 fclose(outf); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 exit(0); |
6de564ef70d3
frtest: new program gsmfr-cod2std
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |