FreeCalypso > hg > gsm-codec-lib
comparison efrtest/etsi-enc.c @ 114:ff0372186b59
gsmefr-etsi-enc test program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 29 Nov 2022 20:31:11 +0000 |
parents | |
children | a13b1605142b |
comparison
equal
deleted
inserted
replaced
113:269d341db403 | 114:ff0372186b59 |
---|---|
1 /* | |
2 * gsmefr-etsi-enc is a test program for our EFR encoder: it reads raw | |
3 * 16-bit PCM (matching ETSI's *.inp) as input and writes ETSI's *.cod | |
4 * format as output, allowing our decoder to be tested with ETSI's | |
5 * official test sequences. | |
6 * | |
7 * ETSI input and output files are read and written in LE byte order, | |
8 * matching the official test sequences in ts_100725v050200p0.zip. | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 #include <stdint.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <strings.h> | |
16 #include "../libgsmefr/gsm_efr.h" | |
17 | |
18 static int | |
19 read_input(inf, pcm, filename_for_errs) | |
20 FILE *inf; | |
21 int16_t *pcm; | |
22 char *filename_for_errs; | |
23 { | |
24 uint8_t file_bytes[320], *sp; | |
25 int cc; | |
26 unsigned n; | |
27 | |
28 cc = fread(file_bytes, 2, 160, inf); | |
29 if (cc == 0) | |
30 return 0; | |
31 if (cc != 160) { | |
32 fprintf(stderr, "error: short read from %s\n", | |
33 filename_for_errs); | |
34 exit(1); | |
35 } | |
36 sp = file_bytes; | |
37 for (n = 0; n < 160; n++) { | |
38 pcm[n] = sp[0] | (sp[1] << 8); | |
39 sp += 2; | |
40 } | |
41 return 1; | |
42 } | |
43 | |
44 static void | |
45 frame2bits(frame, bits) | |
46 uint8_t *frame, *bits; | |
47 { | |
48 unsigned nb, byte, mask, bit; | |
49 | |
50 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { | |
51 byte = *frame++; | |
52 for (mask = 0x80; mask; mask >>= 1) { | |
53 if (byte & mask) | |
54 bit = 1; | |
55 else | |
56 bit = 0; | |
57 *bits++ = bit; | |
58 } | |
59 } | |
60 } | |
61 | |
62 static void | |
63 emit_output(outf, bits, nbits) | |
64 FILE *outf; | |
65 uint8_t *bits; | |
66 unsigned nbits; | |
67 { | |
68 unsigned n; | |
69 | |
70 for (n = 0; n < nbits; n++) { | |
71 putc(bits[n], outf); | |
72 putc(0, outf); | |
73 } | |
74 } | |
75 | |
76 main(argc, argv) | |
77 char **argv; | |
78 { | |
79 char *infname, *outfname; | |
80 FILE *inf, *outf; | |
81 struct EFR_encoder_state *state; | |
82 int16_t pcm[160]; | |
83 uint8_t frame[EFR_RTP_FRAME_LEN], bits[250]; | |
84 int dtx, rc, sp, vad; | |
85 | |
86 if (argc == 3 && argv[1][0] != '-') { | |
87 dtx = 0; | |
88 infname = argv[1]; | |
89 outfname = argv[2]; | |
90 } else if (argc == 4 && !strcmp(argv[1], "-d")) { | |
91 dtx = 1; | |
92 infname = argv[2]; | |
93 outfname = argv[3]; | |
94 } else { | |
95 fprintf(stderr, "usage: %s [-d] input.inp output.cod\n", | |
96 argv[0]); | |
97 exit(1); | |
98 } | |
99 inf = fopen(infname, "r"); | |
100 if (!inf) { | |
101 perror(infname); | |
102 exit(1); | |
103 } | |
104 outf = fopen(outfname, "w"); | |
105 if (!outf) { | |
106 perror(outfname); | |
107 exit(1); | |
108 } | |
109 state = EFR_encoder_create(dtx); | |
110 if (!state) { | |
111 perror("EFR_encoder_create()"); | |
112 exit(1); | |
113 } | |
114 for (;;) { | |
115 rc = read_input(inf, pcm, argv[1]); | |
116 if (!rc) | |
117 break; | |
118 EFR_encode_frame(state, pcm, frame, &sp, &vad); | |
119 frame2bits(frame, bits); | |
120 bits[248] = vad; | |
121 bits[249] = sp; | |
122 emit_output(outf, bits + 4, 246); | |
123 } | |
124 fclose(outf); | |
125 exit(0); | |
126 } |