FreeCalypso > hg > gsm-codec-lib
comparison miscutil/efr2amr.c @ 103:0123ca1f1402
gsm-efr2amr utility written
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Sun, 27 Nov 2022 05:41:13 +0000 |
| parents | |
| children | 7f43089e9a7a |
comparison
equal
deleted
inserted
replaced
| 102:dd88f9312170 | 103:0123ca1f1402 |
|---|---|
| 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 FILE *inf, *outf; | |
| 24 uint8_t frm_in[BINFILE_MAX_FRAME], frm_out[32]; | |
| 25 unsigned bit_a, bit_n, outlen; | |
| 26 int rc, bfi; | |
| 27 | |
| 28 if (argc != 3) { | |
| 29 fprintf(stderr, "usage: %s input.gsmx output.amr\n", argv[0]); | |
| 30 exit(1); | |
| 31 } | |
| 32 inf = fopen(argv[1], "r"); | |
| 33 if (!inf) { | |
| 34 perror(argv[1]); | |
| 35 exit(1); | |
| 36 } | |
| 37 outf = fopen(argv[2], "w"); | |
| 38 if (!outf) { | |
| 39 perror(argv[2]); | |
| 40 exit(1); | |
| 41 } | |
| 42 for (;;) { | |
| 43 rc = binfile_read_frame(inf, frm_in); | |
| 44 if (rc < 0) { | |
| 45 fprintf(stderr, "error: garbage in %s\n", argv[1]); | |
| 46 exit(1); | |
| 47 } | |
| 48 if (!rc) | |
| 49 break; | |
| 50 if (frm_in[0] == 0xBF) | |
| 51 bfi = 1; | |
| 52 else if ((frm_in[0] & 0xF0) == 0xC0) | |
| 53 bfi = 0; | |
| 54 else { | |
| 55 fprintf(stderr, | |
| 56 "error: %s is not in EFR codec format\n", | |
| 57 argv[1]); | |
| 58 exit(1); | |
| 59 } | |
| 60 if (bfi) { | |
| 61 frm_out[0] = 0x78; | |
| 62 outlen = 1; | |
| 63 } else { | |
| 64 frm_out[0] = 0x3C; | |
| 65 bzero(frm_out + 1, 31); | |
| 66 for (bit_a = 0; bit_a < 244; bit_a++) { | |
| 67 bit_n = amr_122_bit_order[bit_a]; | |
| 68 msb_set_bit(frm_out + 1, bit_a, | |
| 69 msb_get_bit(frm_in, 4 + bit_n)); | |
| 70 } | |
| 71 outlen = 32; | |
| 72 } | |
| 73 fwrite(frm_out, 1, outlen, outf); | |
| 74 } | |
| 75 fclose(outf); | |
| 76 exit(0); | |
| 77 } |
