comparison efrtest/etsi-enc-common.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 efrtest/etsi-enc.c@d4f47d0962e7
children
comparison
equal deleted inserted replaced
432:d4f47d0962e7 433:51678b070c7a
1 /*
2 * This C module holds some functions that have been split off from
3 * etsi-enc.c, with the goal of making it easier to build both
4 * standard-EFR and AMR-EFR versions of the ETSI-format EFR encoder.
5 */
6
7 #include <stdio.h>
8 #include <stdint.h>
9 #include <stdlib.h>
10 #include <string.h>
11 #include <strings.h>
12 #include <unistd.h>
13 #include "../libgsmefr/gsm_efr.h"
14
15 read_input(inf, pcm, filename_for_errs, big_endian)
16 FILE *inf;
17 int16_t *pcm;
18 char *filename_for_errs;
19 {
20 uint8_t file_bytes[320], *sp;
21 int cc;
22 unsigned n;
23
24 cc = fread(file_bytes, 2, 160, inf);
25 if (cc == 0)
26 return 0;
27 if (cc != 160) {
28 fprintf(stderr, "error: short read from %s\n",
29 filename_for_errs);
30 exit(1);
31 }
32 sp = file_bytes;
33 for (n = 0; n < 160; n++) {
34 if (big_endian)
35 pcm[n] = (sp[0] << 8) | sp[1];
36 else
37 pcm[n] = sp[0] | (sp[1] << 8);
38 sp += 2;
39 }
40 return 1;
41 }
42
43 void
44 frame2bits(frame, bits)
45 uint8_t *frame, *bits;
46 {
47 unsigned nb, byte, mask, bit;
48
49 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) {
50 byte = *frame++;
51 for (mask = 0x80; mask; mask >>= 1) {
52 if (byte & mask)
53 bit = 1;
54 else
55 bit = 0;
56 *bits++ = bit;
57 }
58 }
59 }
60
61 void
62 emit_output(outf, bits, nbits, big_endian)
63 FILE *outf;
64 uint8_t *bits;
65 unsigned nbits;
66 {
67 unsigned n;
68
69 for (n = 0; n < nbits; n++) {
70 if (big_endian) {
71 putc(0, outf);
72 putc(bits[n], outf);
73 } else {
74 putc(bits[n], outf);
75 putc(0, outf);
76 }
77 }
78 }