FreeCalypso > hg > gsm-codec-lib
comparison hrutil/decode.c @ 607:cdf3f5c618b8
hrutil: new program gsmhr-decode
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Fri, 05 Dec 2025 02:43:19 +0000 |
| parents | frtest/decode-tw5.c@f9eefb61fb2f |
| children |
comparison
equal
deleted
inserted
replaced
| 606:bc57dcfa91d0 | 607:cdf3f5c618b8 |
|---|---|
| 1 /* | |
| 2 * This file is the main module for gsmhr-decode utility. This utility | |
| 3 * is intended to serve as the "user-friendly" decoder for GSM-HR encoded | |
| 4 * speech, reading TW-TS-005 Annex B as input and emitting playable WAV | |
| 5 * as output. | |
| 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/wavwriter.h" | |
| 14 #include "../libtest/pcmwrite.h" | |
| 15 | |
| 16 main(argc, argv) | |
| 17 char **argv; | |
| 18 { | |
| 19 FILE *hexf; | |
| 20 void *wav; | |
| 21 unsigned lineno; | |
| 22 struct gsmhr_decoder_state *state; | |
| 23 uint8_t frame[TWTS005_MAX_FRAME]; | |
| 24 unsigned frame_len; | |
| 25 int16_t params[GSMHR_NUM_PARAMS_DEC]; | |
| 26 int16_t pcm[160]; | |
| 27 int rc; | |
| 28 | |
| 29 if (argc != 3) { | |
| 30 fprintf(stderr, "usage: %s input.hex output.wav\n", argv[0]); | |
| 31 exit(1); | |
| 32 } | |
| 33 hexf = fopen(argv[1], "r"); | |
| 34 if (!hexf) { | |
| 35 perror(argv[1]); | |
| 36 exit(1); | |
| 37 } | |
| 38 lineno = 0; | |
| 39 wav = wav_write_open(argv[2], 8000, 16, 1); | |
| 40 if (!wav) { | |
| 41 perror(argv[2]); | |
| 42 exit(1); | |
| 43 } | |
| 44 state = gsmhr_decoder_create(); | |
| 45 if (!state) { | |
| 46 fprintf(stderr, "gsmhr_decoder_create() failed!\n"); | |
| 47 exit(1); | |
| 48 } | |
| 49 for (;;) { | |
| 50 rc = twts005_read_frame(hexf, &lineno, frame, &frame_len); | |
| 51 if (rc < 0) { | |
| 52 fprintf(stderr, "%s line %u: not valid TW-TS-005\n", | |
| 53 argv[1], lineno); | |
| 54 exit(1); | |
| 55 } | |
| 56 if (!rc) | |
| 57 break; | |
| 58 rc = gsmhr_rtp_in_direct(frame, frame_len, params); | |
| 59 if (rc < 0) { | |
| 60 fprintf(stderr, | |
| 61 "%s line %u: not a valid GSM-HR frame\n", | |
| 62 argv[1], lineno); | |
| 63 exit(1); | |
| 64 } | |
| 65 gsmhr_decode_frame(state, params, pcm); | |
| 66 write_pcm_to_wav(wav, pcm); | |
| 67 } | |
| 68 wav_write_close(wav); | |
| 69 exit(0); | |
| 70 } |
