FreeCalypso > hg > gsm-codec-lib
comparison efrtest/etsi-dec.c @ 150:da17c7f02c6c
gsmefr-etsi-dec: add BE support
| author | Mychaela Falconia <falcon@freecalypso.org> |
|---|---|
| date | Wed, 14 Dec 2022 22:04:39 +0000 |
| parents | 8ed838709897 |
| children | 9f354d2aea13 |
comparison
equal
deleted
inserted
replaced
| 149:95d47a34070a | 150:da17c7f02c6c |
|---|---|
| 2 * gsmefr-etsi-dec is a test program for our EFR decoder: it reads ETSI's | 2 * gsmefr-etsi-dec is a test program for our EFR decoder: it reads ETSI's |
| 3 * .dec format as input and writes raw 16-bit PCM (same as ETSI's *.out) | 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 | 4 * as output, allowing our decoder to be tested with ETSI's official test |
| 5 * sequences. | 5 * sequences. |
| 6 * | 6 * |
| 7 * ETSI input and output files are read and written in LE byte order, | 7 * ETSI input and output files are read and written in LE byte order |
| 8 * matching the official test sequences in ts_100725v050200p0.zip. | 8 * by default, or in BE byte order if -b option is given. |
| 9 */ | 9 */ |
| 10 | 10 |
| 11 #include <stdio.h> | 11 #include <stdio.h> |
| 12 #include <stdint.h> | 12 #include <stdint.h> |
| 13 #include <stdlib.h> | 13 #include <stdlib.h> |
| 14 #include <string.h> | 14 #include <string.h> |
| 15 #include <strings.h> | 15 #include <strings.h> |
| 16 #include "../libgsmefr/gsm_efr.h" | 16 #include "../libgsmefr/gsm_efr.h" |
| 17 #include "etsi.h" | 17 #include "etsi.h" |
| 18 | |
| 19 static void | |
| 20 write_pcm_be(outf, pcm) | |
| 21 FILE *outf; | |
| 22 int16_t *pcm; | |
| 23 { | |
| 24 uint8_t bytes[320], *dp; | |
| 25 int16_t samp; | |
| 26 unsigned n; | |
| 27 | |
| 28 dp = bytes; | |
| 29 for (n = 0; n < 160; n++) { | |
| 30 samp = pcm[n]; | |
| 31 *dp++ = (samp >> 8) & 0xFF; | |
| 32 *dp++ = samp & 0xFF; | |
| 33 } | |
| 34 fwrite(bytes, 2, 160, outf); | |
| 35 } | |
| 18 | 36 |
| 19 static void | 37 static void |
| 20 write_pcm_le(outf, pcm) | 38 write_pcm_le(outf, pcm) |
| 21 FILE *outf; | 39 FILE *outf; |
| 22 int16_t *pcm; | 40 int16_t *pcm; |
| 35 } | 53 } |
| 36 | 54 |
| 37 main(argc, argv) | 55 main(argc, argv) |
| 38 char **argv; | 56 char **argv; |
| 39 { | 57 { |
| 58 int big_endian; | |
| 59 char *infname, *outfname; | |
| 40 FILE *inf, *outf; | 60 FILE *inf, *outf; |
| 41 struct EFR_decoder_state *state; | 61 struct EFR_decoder_state *state; |
| 42 unsigned frame_no; | 62 unsigned frame_no; |
| 43 uint8_t input_bits[ETSI_DEC_NWORDS], frame[EFR_RTP_FRAME_LEN]; | 63 uint8_t input_bits[ETSI_DEC_NWORDS], frame[EFR_RTP_FRAME_LEN]; |
| 44 int16_t pcm[160]; | 64 int16_t pcm[160]; |
| 45 int rc; | 65 int rc; |
| 46 | 66 |
| 47 if (argc != 3) { | 67 if (argc == 3 && argv[1][0] != '-') { |
| 48 fprintf(stderr, "usage: %s input.dec output.out\n", argv[0]); | 68 big_endian = 0; |
| 69 infname = argv[1]; | |
| 70 outfname = argv[2]; | |
| 71 } else if (argc == 4 && !strcmp(argv[1], "-b")) { | |
| 72 big_endian = 1; | |
| 73 infname = argv[2]; | |
| 74 outfname = argv[3]; | |
| 75 } else { | |
| 76 fprintf(stderr, "usage: %s [-b] input.dec output.out\n", | |
| 77 argv[0]); | |
| 49 exit(1); | 78 exit(1); |
| 50 } | 79 } |
| 51 inf = fopen(argv[1], "r"); | 80 inf = fopen(infname, "r"); |
| 52 if (!inf) { | 81 if (!inf) { |
| 53 perror(argv[1]); | 82 perror(infname); |
| 54 exit(1); | 83 exit(1); |
| 55 } | 84 } |
| 56 outf = fopen(argv[2], "w"); | 85 outf = fopen(outfname, "w"); |
| 57 if (!outf) { | 86 if (!outf) { |
| 58 perror(argv[2]); | 87 perror(outfname); |
| 59 exit(1); | 88 exit(1); |
| 60 } | 89 } |
| 61 state = EFR_decoder_create(); | 90 state = EFR_decoder_create(); |
| 62 if (!state) { | 91 if (!state) { |
| 63 perror("EFR_decoder_create()"); | 92 perror("EFR_decoder_create()"); |
| 64 exit(1); | 93 exit(1); |
| 65 } | 94 } |
| 66 for (frame_no = 0; ; frame_no++) { | 95 for (frame_no = 0; ; frame_no++) { |
| 67 rc = read_etsi_bits(inf, 0, input_bits, ETSI_DEC_NWORDS, | 96 rc = read_etsi_bits(inf, big_endian, input_bits, |
| 68 argv[1]); | 97 ETSI_DEC_NWORDS, infname); |
| 69 if (!rc) | 98 if (!rc) |
| 70 break; | 99 break; |
| 71 if (input_bits[0] > 1) { | 100 if (input_bits[0] > 1) { |
| 72 fprintf(stderr, "error in %s frame #%u: BFI > 1\n", | 101 fprintf(stderr, "error in %s frame #%u: BFI > 1\n", |
| 73 argv[1], frame_no); | 102 infname, frame_no); |
| 74 exit(1); | 103 exit(1); |
| 75 } | 104 } |
| 76 bits2frame(input_bits + 1, frame, argv[1], frame_no); | 105 bits2frame(input_bits + 1, frame, infname, frame_no); |
| 77 if (input_bits[245] > 2) { | 106 if (input_bits[245] > 2) { |
| 78 fprintf(stderr, "error in %s frame #%u: SID > 2\n", | 107 fprintf(stderr, "error in %s frame #%u: SID > 2\n", |
| 79 argv[1], frame_no); | 108 infname, frame_no); |
| 80 exit(1); | 109 exit(1); |
| 81 } | 110 } |
| 82 if (input_bits[246] > 1) { | 111 if (input_bits[246] > 1) { |
| 83 fprintf(stderr, "error in %s frame #%u: TAF > 1\n", | 112 fprintf(stderr, "error in %s frame #%u: TAF > 1\n", |
| 84 argv[1], frame_no); | 113 infname, frame_no); |
| 85 exit(1); | 114 exit(1); |
| 86 } | 115 } |
| 87 rc = EFR_sid_classify(frame); | 116 rc = EFR_sid_classify(frame); |
| 88 if (input_bits[245] != rc) { | 117 if (input_bits[245] != rc) { |
| 89 fprintf(stderr, | 118 fprintf(stderr, |
| 90 "warning: frame #%u has mismatching SID (file says %u, analysis yields %d)\n", | 119 "warning: frame #%u has mismatching SID (file says %u, analysis yields %d)\n", |
| 91 frame_no, input_bits[245], rc); | 120 frame_no, input_bits[245], rc); |
| 92 } | 121 } |
| 93 EFR_decode_frame(state, frame, input_bits[0], input_bits[246], | 122 EFR_decode_frame(state, frame, input_bits[0], input_bits[246], |
| 94 pcm); | 123 pcm); |
| 95 write_pcm_le(outf, pcm); | 124 if (big_endian) |
| 125 write_pcm_be(outf, pcm); | |
| 126 else | |
| 127 write_pcm_le(outf, pcm); | |
| 96 } | 128 } |
| 97 fclose(outf); | 129 fclose(outf); |
| 98 exit(0); | 130 exit(0); |
| 99 } | 131 } |
