FreeCalypso > hg > gsm-codec-lib
comparison hrutil/etsi-dec.c @ 606:bc57dcfa91d0
hrutil: new program gsmhr-etsi-dec
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Thu, 04 Dec 2025 21:36:51 +0000 |
| parents | efrtest/etsi-dec.c@9f354d2aea13 |
| children |
comparison
equal
deleted
inserted
replaced
| 605:63f774192906 | 606:bc57dcfa91d0 |
|---|---|
| 1 /* | |
| 2 * gsmhr-etsi-dec is a test program for our GSM-HR decoder: it reads ETSI's | |
| 3 * .dec format as input and writes raw 16-bit PCM (same as ETSI's *.out) | |
| 4 * as output, allowing our decoder to be tested with ETSI's official test | |
| 5 * sequences. | |
| 6 * | |
| 7 * ETSI input and output files are read and written in the local machine's | |
| 8 * native byte order by default; -b and -l options can be used to force | |
| 9 * BE or LE, respectively. | |
| 10 */ | |
| 11 | |
| 12 #include <stdio.h> | |
| 13 #include <stdint.h> | |
| 14 #include <stdlib.h> | |
| 15 #include <string.h> | |
| 16 #include <strings.h> | |
| 17 #include <unistd.h> | |
| 18 #include "../libgsmhr1/tw_gsmhr.h" | |
| 19 #include "../libtest/local_endian.h" | |
| 20 | |
| 21 main(argc, argv) | |
| 22 char **argv; | |
| 23 { | |
| 24 char *infname, *outfname; | |
| 25 FILE *inf, *outf; | |
| 26 int opt, rc, big_endian; | |
| 27 struct gsmhr_decoder_state *state; | |
| 28 unsigned frame_no; | |
| 29 int16_t params[GSMHR_NUM_PARAMS_DEC]; | |
| 30 int16_t pcm[160]; | |
| 31 extern int optind; | |
| 32 | |
| 33 big_endian = is_native_big_endian(); | |
| 34 while ((opt = getopt(argc, argv, "bl")) != EOF) { | |
| 35 switch (opt) { | |
| 36 case 'b': | |
| 37 big_endian = 1; | |
| 38 continue; | |
| 39 case 'l': | |
| 40 big_endian = 0; | |
| 41 continue; | |
| 42 default: | |
| 43 usage: | |
| 44 fprintf(stderr, | |
| 45 "usage: %s [-b|-l] input.dec output.out\n", | |
| 46 argv[0]); | |
| 47 exit(1); | |
| 48 } | |
| 49 } | |
| 50 if (argc != optind + 2) | |
| 51 goto usage; | |
| 52 infname = argv[optind]; | |
| 53 outfname = argv[optind+1]; | |
| 54 | |
| 55 inf = fopen(infname, "r"); | |
| 56 if (!inf) { | |
| 57 perror(infname); | |
| 58 exit(1); | |
| 59 } | |
| 60 outf = fopen(outfname, "w"); | |
| 61 if (!outf) { | |
| 62 perror(outfname); | |
| 63 exit(1); | |
| 64 } | |
| 65 state = gsmhr_decoder_create(); | |
| 66 if (!state) { | |
| 67 perror("gsmhr_decoder_create()"); | |
| 68 exit(1); | |
| 69 } | |
| 70 for (frame_no = 0; ; frame_no++) { | |
| 71 rc = read_dec_frame(inf, big_endian, params, infname, frame_no); | |
| 72 if (!rc) | |
| 73 break; | |
| 74 gsmhr_decode_frame(state, params, pcm); | |
| 75 if (big_endian) | |
| 76 write_pcm_be(outf, pcm); | |
| 77 else | |
| 78 write_pcm_le(outf, pcm); | |
| 79 } | |
| 80 fclose(outf); | |
| 81 exit(0); | |
| 82 } |
