FreeCalypso > hg > gsm-codec-lib
comparison efrtest/decode-tw5-r.c @ 548:583dc4cbee95
efrtest: new program gsmefr-decode-tw5-r
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 04 Oct 2024 20:40:42 +0000 |
| parents | frtest/decode-tw5-r.c@4d596bfdf8d9 |
| children |
comparison
equal
deleted
inserted
replaced
| 547:f9535c1fbf70 | 548:583dc4cbee95 |
|---|---|
| 1 /* | |
| 2 * This file is the main module for gsmefr-decode-tw5-r utility. It is just | |
| 3 * like the original gsmefr-decode-r, but reads the GSM-EFR speech recording | |
| 4 * from TW-TS-005 Annex A hexadecimal format instead of the old gsmx | |
| 5 * binary format. The output format is robe, as indicated by the -r suffix. | |
| 6 */ | |
| 7 | |
| 8 #include <stdio.h> | |
| 9 #include <stdint.h> | |
| 10 #include <stdlib.h> | |
| 11 #include "../libgsmefr/gsm_efr.h" | |
| 12 #include "../libtest/tw5reader.h" | |
| 13 #include "../libtest/robewrite.h" | |
| 14 | |
| 15 main(argc, argv) | |
| 16 char **argv; | |
| 17 { | |
| 18 FILE *hexf, *outf; | |
| 19 unsigned lineno; | |
| 20 struct EFR_decoder_state *state; | |
| 21 uint8_t frame[TWTS005_MAX_FRAME]; | |
| 22 unsigned frame_len; | |
| 23 int16_t pcm[160]; | |
| 24 int rc; | |
| 25 | |
| 26 if (argc != 3) { | |
| 27 fprintf(stderr, "usage: %s input.hex output.robe\n", argv[0]); | |
| 28 exit(1); | |
| 29 } | |
| 30 hexf = fopen(argv[1], "r"); | |
| 31 if (!hexf) { | |
| 32 perror(argv[1]); | |
| 33 exit(1); | |
| 34 } | |
| 35 lineno = 0; | |
| 36 outf = fopen(argv[2], "w"); | |
| 37 if (!outf) { | |
| 38 perror(argv[2]); | |
| 39 exit(1); | |
| 40 } | |
| 41 state = EFR_decoder_create(); | |
| 42 if (!state) { | |
| 43 perror("EFR_decoder_create()"); | |
| 44 exit(1); | |
| 45 } | |
| 46 for (;;) { | |
| 47 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); | |
| 48 if (rc < 0) { | |
| 49 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
| 50 argv[1], lineno); | |
| 51 exit(1); | |
| 52 } | |
| 53 if (!rc) | |
| 54 break; | |
| 55 rc = EFR_decode_rtp(state, frame, frame_len, pcm); | |
| 56 if (rc < 0) { | |
| 57 fprintf(stderr, | |
| 58 "%s line %u: not a valid GSM-EFR frame\n", | |
| 59 argv[1], lineno); | |
| 60 exit(1); | |
| 61 } | |
| 62 write_pcm_to_robe(outf, pcm); | |
| 63 } | |
| 64 fclose(outf); | |
| 65 exit(0); | |
| 66 } |
