FreeCalypso > hg > gsm-codec-lib
comparison amrconv/amr2efr.c @ 184:b092a510141e
tree reorg: move gsm-amr2efr & gsm-efr2amr to amrconv subdir
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 03 Jan 2023 02:33:45 +0000 |
parents | miscutil/amr2efr.c@41f1ae68d253 |
children |
comparison
equal
deleted
inserted
replaced
183:452c1d5a6268 | 184:b092a510141e |
---|---|
1 /* | |
2 * Our gsm-amr2efr utility reads in a speech recording in .amr format | |
3 * (the mode must be MR122 for every frame, no DTX) and converts it into | |
4 * our ad hoc .gsmx format for EFR. The conversion is a bit reshuffling | |
5 * only, no transcoding takes place. | |
6 */ | |
7 | |
8 #include <stdio.h> | |
9 #include <stdint.h> | |
10 #include <stdlib.h> | |
11 #include <string.h> | |
12 #include <strings.h> | |
13 | |
14 extern const uint8_t amr_122_bit_order[244]; | |
15 | |
16 static const char amr_file_hdr[] = "#!AMR\n"; | |
17 | |
18 main(argc, argv) | |
19 char **argv; | |
20 { | |
21 char *infname, *outfname; | |
22 FILE *inf, *outf; | |
23 int wrong_flag, hdrb; | |
24 uint8_t frm_in[31], frm_out[31]; | |
25 unsigned bit_a, bit_n; | |
26 | |
27 if (argc == 3 && argv[1][0] != '-') { | |
28 wrong_flag = 0; | |
29 infname = argv[1]; | |
30 outfname = argv[2]; | |
31 } else if (argc == 4 && !strcmp(argv[1], "-w")) { | |
32 wrong_flag = 1; | |
33 infname = argv[2]; | |
34 outfname = argv[3]; | |
35 } else { | |
36 fprintf(stderr, "usage: %s [-w] input.amr output.gsmx\n", | |
37 argv[0]); | |
38 exit(1); | |
39 } | |
40 inf = fopen(infname, "r"); | |
41 if (!inf) { | |
42 perror(infname); | |
43 exit(1); | |
44 } | |
45 if (fread(frm_in, 1, 6, inf) != 6 || bcmp(frm_in, amr_file_hdr, 6)) { | |
46 fprintf(stderr, "error: %s is not in AMR format\n", infname); | |
47 exit(1); | |
48 } | |
49 outf = fopen(outfname, "w"); | |
50 if (!outf) { | |
51 perror(outfname); | |
52 exit(1); | |
53 } | |
54 for (;;) { | |
55 hdrb = getc(inf); | |
56 if (hdrb < 0) | |
57 break; | |
58 if ((hdrb & 0x78) != 0x38) { | |
59 fprintf(stderr, "error: unexpected content in %s\n", | |
60 infname); | |
61 exit(1); | |
62 } | |
63 if (fread(frm_in, 1, 31, inf) != 31) { | |
64 fprintf(stderr, "error: short read from %s\n", infname); | |
65 exit(1); | |
66 } | |
67 frm_out[0] = 0xC0; | |
68 for (bit_a = 0; bit_a < 244; bit_a++) { | |
69 if (wrong_flag) | |
70 bit_n = bit_a; | |
71 else | |
72 bit_n = amr_122_bit_order[bit_a]; | |
73 msb_set_bit(frm_out, 4 + bit_n, | |
74 msb_get_bit(frm_in, bit_a)); | |
75 } | |
76 fwrite(frm_out, 1, 31, outf); | |
77 } | |
78 fclose(outf); | |
79 exit(0); | |
80 } |