FreeCalypso > hg > gsm-codec-lib
annotate miscutil/amr2efr.c @ 104:7f43089e9a7a
gsm-efr2amr: forgot AMR file header again
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 27 Nov 2022 05:43:26 +0000 |
parents | dd88f9312170 |
children | ecfbced76fea |
rev | line source |
---|---|
101
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * Our gsm-amr2efr utility reads in a speech recording in .amr format |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * (the mode must be MR122 for every frame, no DTX) and converts it into |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * our ad hoc .gsmx format for EFR. The conversion is a bit reshuffling |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * only, no transcoding takes place. |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 extern const uint8_t amr_122_bit_order[244]; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
102
dd88f9312170
gsm-amr2efr: forgot about AMR file header
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
16 static const char amr_file_hdr[] = "#!AMR\n"; |
dd88f9312170
gsm-amr2efr: forgot about AMR file header
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
17 |
101
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 main(argc, argv) |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 char **argv; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 FILE *inf, *outf; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 int hdrb; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 uint8_t frm_in[31], frm_out[31]; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 unsigned bit_a, bit_n; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (argc != 3) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 fprintf(stderr, "usage: %s input.amr output.gsmx\n", argv[0]); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 exit(1); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 inf = fopen(argv[1], "r"); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 if (!inf) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 perror(argv[1]); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
102
dd88f9312170
gsm-amr2efr: forgot about AMR file header
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
35 if (fread(frm_in, 1, 6, inf) != 6 || bcmp(frm_in, amr_file_hdr, 6)) { |
dd88f9312170
gsm-amr2efr: forgot about AMR file header
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
36 fprintf(stderr, "error: %s is not in AMR format\n", argv[1]); |
dd88f9312170
gsm-amr2efr: forgot about AMR file header
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
37 exit(1); |
dd88f9312170
gsm-amr2efr: forgot about AMR file header
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
38 } |
101
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 outf = fopen(argv[2], "w"); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (!outf) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 perror(argv[2]); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 for (;;) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 hdrb = getc(inf); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 if (hdrb < 0) |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 break; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 if ((hdrb & 0x78) != 0x38) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fprintf(stderr, "error: unexpected content in %s\n", |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 argv[1]); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 exit(1); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 } |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 if (fread(frm_in, 1, 31, inf) != 31) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 fprintf(stderr, "error: short read from %s\n", argv[1]); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 exit(1); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 bzero(frm_out, 31); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 frm_out[0] = 0xC0; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 for (bit_a = 0; bit_a < 244; bit_a++) { |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 bit_n = amr_122_bit_order[bit_a]; |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 msb_set_bit(frm_out, 4 + bit_n, |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 msb_get_bit(frm_in, bit_a)); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 fwrite(frm_out, 1, 31, outf); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 fclose(outf); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 exit(0); |
d86f866489e9
gsm-amr2efr utility written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |