FreeCalypso > hg > gsm-codec-lib
comparison amrconv/efr2amr.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/efr2amr.c@41f1ae68d253 |
children |
comparison
equal
deleted
inserted
replaced
183:452c1d5a6268 | 184:b092a510141e |
---|---|
1 /* | |
2 * Our gsm-efr2amr utility reads in an EFR speech recording in our | |
3 * extended-libgsm file format and converts it to AMR, inserting | |
4 * an AMR NO_DATA frame in the place of every BFI in the input | |
5 * but NOT performing any special handling or even detection of | |
6 * EFR SID frames. | |
7 */ | |
8 | |
9 #include <stdio.h> | |
10 #include <stdint.h> | |
11 #include <stdlib.h> | |
12 #include <string.h> | |
13 #include <strings.h> | |
14 #include "../libtest/binreader.h" | |
15 | |
16 extern const uint8_t amr_122_bit_order[244]; | |
17 | |
18 static const char amr_file_hdr[] = "#!AMR\n"; | |
19 | |
20 main(argc, argv) | |
21 char **argv; | |
22 { | |
23 char *infname, *outfname; | |
24 FILE *inf, *outf; | |
25 int wrong_flag; | |
26 uint8_t frm_in[BINFILE_MAX_FRAME], frm_out[32]; | |
27 unsigned bit_a, bit_n, outlen; | |
28 int rc, bfi; | |
29 | |
30 if (argc == 3 && argv[1][0] != '-') { | |
31 wrong_flag = 0; | |
32 infname = argv[1]; | |
33 outfname = argv[2]; | |
34 } else if (argc == 4 && !strcmp(argv[1], "-w")) { | |
35 wrong_flag = 1; | |
36 infname = argv[2]; | |
37 outfname = argv[3]; | |
38 } else { | |
39 fprintf(stderr, "usage: %s [-w] input.gsmx output.amr\n", | |
40 argv[0]); | |
41 exit(1); | |
42 } | |
43 inf = fopen(infname, "r"); | |
44 if (!inf) { | |
45 perror(infname); | |
46 exit(1); | |
47 } | |
48 outf = fopen(outfname, "w"); | |
49 if (!outf) { | |
50 perror(outfname); | |
51 exit(1); | |
52 } | |
53 fwrite(amr_file_hdr, 1, 6, outf); | |
54 for (;;) { | |
55 rc = binfile_read_frame(inf, frm_in); | |
56 if (rc < 0) { | |
57 fprintf(stderr, "error: garbage in %s\n", infname); | |
58 exit(1); | |
59 } | |
60 if (!rc) | |
61 break; | |
62 if (frm_in[0] == 0xBF) | |
63 bfi = 1; | |
64 else if ((frm_in[0] & 0xF0) == 0xC0) | |
65 bfi = 0; | |
66 else { | |
67 fprintf(stderr, | |
68 "error: %s is not in EFR codec format\n", | |
69 infname); | |
70 exit(1); | |
71 } | |
72 if (bfi) { | |
73 frm_out[0] = 0x78; | |
74 outlen = 1; | |
75 } else { | |
76 frm_out[0] = 0x3C; | |
77 frm_out[31] = 0; | |
78 for (bit_a = 0; bit_a < 244; bit_a++) { | |
79 if (wrong_flag) | |
80 bit_n = bit_a; | |
81 else | |
82 bit_n = amr_122_bit_order[bit_a]; | |
83 msb_set_bit(frm_out + 1, bit_a, | |
84 msb_get_bit(frm_in, 4 + bit_n)); | |
85 } | |
86 outlen = 32; | |
87 } | |
88 fwrite(frm_out, 1, outlen, outf); | |
89 } | |
90 fclose(outf); | |
91 exit(0); | |
92 } |