comparison miscutil/amr2efr.c @ 101:d86f866489e9

gsm-amr2efr utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 27 Nov 2022 05:15:39 +0000
parents
children dd88f9312170
comparison
equal deleted inserted replaced
100:d5bab777865a 101:d86f866489e9
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 main(argc, argv)
17 char **argv;
18 {
19 FILE *inf, *outf;
20 int hdrb;
21 uint8_t frm_in[31], frm_out[31];
22 unsigned bit_a, bit_n;
23
24 if (argc != 3) {
25 fprintf(stderr, "usage: %s input.amr output.gsmx\n", argv[0]);
26 exit(1);
27 }
28 inf = fopen(argv[1], "r");
29 if (!inf) {
30 perror(argv[1]);
31 exit(1);
32 }
33 outf = fopen(argv[2], "w");
34 if (!outf) {
35 perror(argv[2]);
36 exit(1);
37 }
38 for (;;) {
39 hdrb = getc(inf);
40 if (hdrb < 0)
41 break;
42 if ((hdrb & 0x78) != 0x38) {
43 fprintf(stderr, "error: unexpected content in %s\n",
44 argv[1]);
45 exit(1);
46 }
47 if (fread(frm_in, 1, 31, inf) != 31) {
48 fprintf(stderr, "error: short read from %s\n", argv[1]);
49 exit(1);
50 }
51 bzero(frm_out, 31);
52 frm_out[0] = 0xC0;
53 for (bit_a = 0; bit_a < 244; bit_a++) {
54 bit_n = amr_122_bit_order[bit_a];
55 msb_set_bit(frm_out, 4 + bit_n,
56 msb_get_bit(frm_in, bit_a));
57 }
58 fwrite(frm_out, 1, 31, outf);
59 }
60 fclose(outf);
61 exit(0);
62 }