FreeCalypso > hg > gsm-codec-lib
comparison efrtest/etsi-enc.c @ 433:51678b070c7a
efrtest: split etsi-enc.c for code reuse
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 08 May 2024 01:13:50 +0000 |
parents | d4f47d0962e7 |
children |
comparison
equal
deleted
inserted
replaced
432:d4f47d0962e7 | 433:51678b070c7a |
---|---|
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 <unistd.h> | 16 #include <unistd.h> |
17 #include "../libgsmefr/gsm_efr.h" | 17 #include "../libgsmefr/gsm_efr.h" |
18 | |
19 static int | |
20 read_input(inf, pcm, filename_for_errs, big_endian) | |
21 FILE *inf; | |
22 int16_t *pcm; | |
23 char *filename_for_errs; | |
24 { | |
25 uint8_t file_bytes[320], *sp; | |
26 int cc; | |
27 unsigned n; | |
28 | |
29 cc = fread(file_bytes, 2, 160, inf); | |
30 if (cc == 0) | |
31 return 0; | |
32 if (cc != 160) { | |
33 fprintf(stderr, "error: short read from %s\n", | |
34 filename_for_errs); | |
35 exit(1); | |
36 } | |
37 sp = file_bytes; | |
38 for (n = 0; n < 160; n++) { | |
39 if (big_endian) | |
40 pcm[n] = (sp[0] << 8) | sp[1]; | |
41 else | |
42 pcm[n] = sp[0] | (sp[1] << 8); | |
43 sp += 2; | |
44 } | |
45 return 1; | |
46 } | |
47 | |
48 static void | |
49 frame2bits(frame, bits) | |
50 uint8_t *frame, *bits; | |
51 { | |
52 unsigned nb, byte, mask, bit; | |
53 | |
54 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { | |
55 byte = *frame++; | |
56 for (mask = 0x80; mask; mask >>= 1) { | |
57 if (byte & mask) | |
58 bit = 1; | |
59 else | |
60 bit = 0; | |
61 *bits++ = bit; | |
62 } | |
63 } | |
64 } | |
65 | |
66 static void | |
67 emit_output(outf, bits, nbits, big_endian) | |
68 FILE *outf; | |
69 uint8_t *bits; | |
70 unsigned nbits; | |
71 { | |
72 unsigned n; | |
73 | |
74 for (n = 0; n < nbits; n++) { | |
75 if (big_endian) { | |
76 putc(0, outf); | |
77 putc(bits[n], outf); | |
78 } else { | |
79 putc(bits[n], outf); | |
80 putc(0, outf); | |
81 } | |
82 } | |
83 } | |
84 | 18 |
85 main(argc, argv) | 19 main(argc, argv) |
86 char **argv; | 20 char **argv; |
87 { | 21 { |
88 char *infname, *outfname; | 22 char *infname, *outfname; |