FreeCalypso > hg > gsm-codec-lib
comparison miscutil/gsmx-to-tw5a.c @ 520:785b302992f0
miscutil: new program gsmx-to-tw5a
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 19 Sep 2024 01:06:58 +0000 |
| parents | miscutil/gsmrec-dump.c@b5f8ea41362b |
| children | 68fe269b4316 |
comparison
equal
deleted
inserted
replaced
| 519:6f8abfe253a4 | 520:785b302992f0 |
|---|---|
| 1 /* | |
| 2 * This program converts FR/EFR speech recordings from gsmx binary format | |
| 3 * into more formally standardized TW-TS-005 Annex A format. | |
| 4 * | |
| 5 * FR and EFR frames are written in basic format (no TEH); | |
| 6 * BFI marker records are converted into TW-TS-001 No_Data 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 "../libgsmfr2/tw_gsmfr.h" | |
| 15 #include "../libgsmefr/gsm_efr.h" | |
| 16 #include "../libtest/binreader.h" | |
| 17 | |
| 18 static void | |
| 19 emit_hex_frame(frame, nbytes) | |
| 20 uint8_t *frame; | |
| 21 unsigned nbytes; | |
| 22 { | |
| 23 unsigned n; | |
| 24 | |
| 25 for (n = 0; n < nbytes; n++) | |
| 26 printf("%02X", frame[n]); | |
| 27 putchar('\n'); | |
| 28 } | |
| 29 | |
| 30 main(argc, argv) | |
| 31 char **argv; | |
| 32 { | |
| 33 FILE *binf, *outf; | |
| 34 unsigned frame_index; | |
| 35 uint8_t frame[BINFILE_MAX_FRAME]; | |
| 36 int rc; | |
| 37 | |
| 38 if (argc != 3) { | |
| 39 fprintf(stderr, "usage: %s input.gsmx output.hex\n", argv[0]); | |
| 40 exit(1); | |
| 41 } | |
| 42 binf = fopen(argv[1], "r"); | |
| 43 if (!binf) { | |
| 44 perror(argv[1]); | |
| 45 exit(1); | |
| 46 } | |
| 47 if (strcmp(argv[2], "-")) { | |
| 48 outf = fopen(argv[2], "w"); | |
| 49 if (!outf) { | |
| 50 perror(argv[2]); | |
| 51 exit(1); | |
| 52 } | |
| 53 } else | |
| 54 outf = stdout; | |
| 55 for (frame_index = 0; ; frame_index++) { | |
| 56 rc = binfile_read_frame(binf, frame); | |
| 57 if (rc < 0) { | |
| 58 fprintf(stderr, | |
| 59 "error: garbage in %s after %u frames\n", | |
| 60 argv[1], frame_index); | |
| 61 exit(1); | |
| 62 } | |
| 63 if (!rc) | |
| 64 break; | |
| 65 switch (frame[0] & 0xF0) { | |
| 66 case 0xB0: | |
| 67 printf("%02X\n", 0xE6 | frame[1] & 1); | |
| 68 break; | |
| 69 case 0xC0: | |
| 70 emit_hex_frame(frame, EFR_RTP_FRAME_LEN); | |
| 71 break; | |
| 72 case 0xD0: | |
| 73 emit_hex_frame(frame, GSMFR_RTP_FRAME_LEN); | |
| 74 break; | |
| 75 } | |
| 76 } | |
| 77 exit(0); | |
| 78 } |
