FreeCalypso > hg > gsm-codec-lib
comparison efrtest/decode-r.c @ 154:01ce75ea1c8e
gsmefr-decode-r utility put together
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Wed, 14 Dec 2022 23:18:18 +0000 |
| parents | efrtest/decode.c@d5bab777865a |
| children |
comparison
equal
deleted
inserted
replaced
| 153:14b627682458 | 154:01ce75ea1c8e |
|---|---|
| 1 /* | |
| 2 * gsmefr-decode-r is like gsmefr-decode, but writes the decoded PCM | |
| 3 * output in our "robe" format instead of WAV. | |
| 4 */ | |
| 5 | |
| 6 #include <stdio.h> | |
| 7 #include <stdint.h> | |
| 8 #include <stdlib.h> | |
| 9 #include "../libgsmefr/gsm_efr.h" | |
| 10 #include "../libtest/binreader.h" | |
| 11 #include "../libtest/robewrite.h" | |
| 12 | |
| 13 main(argc, argv) | |
| 14 char **argv; | |
| 15 { | |
| 16 FILE *binf, *outf; | |
| 17 struct EFR_decoder_state *state; | |
| 18 uint8_t frame[BINFILE_MAX_FRAME]; | |
| 19 int16_t pcm[160]; | |
| 20 int rc, bfi, taf; | |
| 21 | |
| 22 if (argc != 3) { | |
| 23 fprintf(stderr, "usage: %s input.gsmx output.robe\n", argv[0]); | |
| 24 exit(1); | |
| 25 } | |
| 26 binf = fopen(argv[1], "r"); | |
| 27 if (!binf) { | |
| 28 perror(argv[1]); | |
| 29 exit(1); | |
| 30 } | |
| 31 outf = fopen(argv[2], "w"); | |
| 32 if (!outf) { | |
| 33 perror(argv[2]); | |
| 34 exit(1); | |
| 35 } | |
| 36 state = EFR_decoder_create(); | |
| 37 if (!state) { | |
| 38 perror("EFR_decoder_create()"); | |
| 39 exit(1); | |
| 40 } | |
| 41 for (;;) { | |
| 42 rc = binfile_read_frame(binf, frame); | |
| 43 if (rc < 0) { | |
| 44 fprintf(stderr, "error: garbage in %s\n", argv[1]); | |
| 45 exit(1); | |
| 46 } | |
| 47 if (!rc) | |
| 48 break; | |
| 49 if (frame[0] == 0xBF) { | |
| 50 bfi = 1; | |
| 51 taf = frame[1] & 1; | |
| 52 } else if ((frame[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 EFR_decode_bfi_nodata(state, taf, pcm); | |
| 62 else | |
| 63 EFR_decode_frame(state, frame, 0, 0, pcm); | |
| 64 write_pcm_to_robe(outf, pcm); | |
| 65 } | |
| 66 fclose(outf); | |
| 67 exit(0); | |
| 68 } |
