FreeCalypso > hg > gsm-codec-lib
comparison hrutil/decode-r.c @ 608:d4e42ec4a688 default tip
hrutil: new program gsmhr-decode-r
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 05 Dec 2025 09:01:14 +0000 |
| parents | hrutil/decode.c@cdf3f5c618b8 |
| children |
comparison
equal
deleted
inserted
replaced
| 607:cdf3f5c618b8 | 608:d4e42ec4a688 |
|---|---|
| 1 /* | |
| 2 * This file is the main module for gsmhr-decode-r utility. This utility | |
| 3 * is intended to serve as a precision tinkering-oriented decoder for | |
| 4 * GSM-HR encoded speech, reading TW-TS-005 Annex B as input and emitting | |
| 5 * 16-bit linear PCM output in robe format. | |
| 6 */ | |
| 7 | |
| 8 #include <stdio.h> | |
| 9 #include <stdint.h> | |
| 10 #include <stdlib.h> | |
| 11 #include "../libgsmhr1/tw_gsmhr.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 gsmhr_decoder_state *state; | |
| 21 uint8_t frame[TWTS005_MAX_FRAME]; | |
| 22 unsigned frame_len; | |
| 23 int16_t params[GSMHR_NUM_PARAMS_DEC]; | |
| 24 int16_t pcm[160]; | |
| 25 int rc; | |
| 26 | |
| 27 if (argc != 3) { | |
| 28 fprintf(stderr, "usage: %s input.hex output.robe\n", argv[0]); | |
| 29 exit(1); | |
| 30 } | |
| 31 hexf = fopen(argv[1], "r"); | |
| 32 if (!hexf) { | |
| 33 perror(argv[1]); | |
| 34 exit(1); | |
| 35 } | |
| 36 lineno = 0; | |
| 37 outf = fopen(argv[2], "w"); | |
| 38 if (!outf) { | |
| 39 perror(argv[2]); | |
| 40 exit(1); | |
| 41 } | |
| 42 state = gsmhr_decoder_create(); | |
| 43 if (!state) { | |
| 44 fprintf(stderr, "gsmhr_decoder_create() failed!\n"); | |
| 45 exit(1); | |
| 46 } | |
| 47 for (;;) { | |
| 48 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); | |
| 49 if (rc < 0) { | |
| 50 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
| 51 argv[1], lineno); | |
| 52 exit(1); | |
| 53 } | |
| 54 if (!rc) | |
| 55 break; | |
| 56 rc = gsmhr_rtp_in_direct(frame, frame_len, params); | |
| 57 if (rc < 0) { | |
| 58 fprintf(stderr, | |
| 59 "%s line %u: not a valid GSM-HR frame\n", | |
| 60 argv[1], lineno); | |
| 61 exit(1); | |
| 62 } | |
| 63 gsmhr_decode_frame(state, params, pcm); | |
| 64 write_pcm_to_robe(outf, pcm); | |
| 65 } | |
| 66 fclose(outf); | |
| 67 exit(0); | |
| 68 } |
