FreeCalypso > hg > gsm-codec-lib
annotate efrtest/etsi-enc-common.c @ 441:ebe499058c63
libtwamr: implement API functions for RFC 4867 I/O
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 09 May 2024 07:06:31 +0000 |
parents | 51678b070c7a |
children |
rev | line source |
---|---|
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
433
51678b070c7a
efrtest: split etsi-enc.c for code reuse
Mychaela Falconia <falcon@freecalypso.org>
parents:
432
diff
changeset
|
2 * This C module holds some functions that have been split off from |
51678b070c7a
efrtest: split etsi-enc.c for code reuse
Mychaela Falconia <falcon@freecalypso.org>
parents:
432
diff
changeset
|
3 * etsi-enc.c, with the goal of making it easier to build both |
51678b070c7a
efrtest: split etsi-enc.c for code reuse
Mychaela Falconia <falcon@freecalypso.org>
parents:
432
diff
changeset
|
4 * standard-EFR and AMR-EFR versions of the ETSI-format EFR encoder. |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 */ |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdint.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <string.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <strings.h> |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
12 #include <unistd.h> |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "../libgsmefr/gsm_efr.h" |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
15 read_input(inf, pcm, filename_for_errs, big_endian) |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 FILE *inf; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int16_t *pcm; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *filename_for_errs; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 uint8_t file_bytes[320], *sp; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int cc; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 unsigned n; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cc = fread(file_bytes, 2, 160, inf); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (cc == 0) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return 0; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (cc != 160) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "error: short read from %s\n", |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 filename_for_errs); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 sp = file_bytes; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 for (n = 0; n < 160; n++) { |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
34 if (big_endian) |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
35 pcm[n] = (sp[0] << 8) | sp[1]; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
36 else |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
37 pcm[n] = sp[0] | (sp[1] << 8); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 sp += 2; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return 1; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 |
433
51678b070c7a
efrtest: split etsi-enc.c for code reuse
Mychaela Falconia <falcon@freecalypso.org>
parents:
432
diff
changeset
|
43 void |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 frame2bits(frame, bits) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 uint8_t *frame, *bits; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 unsigned nb, byte, mask, bit; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 for (nb = 0; nb < EFR_RTP_FRAME_LEN; nb++) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 byte = *frame++; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 for (mask = 0x80; mask; mask >>= 1) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (byte & mask) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 bit = 1; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 else |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 bit = 0; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 *bits++ = bit; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 |
433
51678b070c7a
efrtest: split etsi-enc.c for code reuse
Mychaela Falconia <falcon@freecalypso.org>
parents:
432
diff
changeset
|
61 void |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
62 emit_output(outf, bits, nbits, big_endian) |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 FILE *outf; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 uint8_t *bits; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 unsigned nbits; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 unsigned n; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 for (n = 0; n < nbits; n++) { |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
70 if (big_endian) { |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
71 putc(0, outf); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
72 putc(bits[n], outf); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
73 } else { |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
74 putc(bits[n], outf); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
75 putc(0, outf); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
76 } |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |