FreeCalypso > hg > gsm-codec-lib
annotate efrtest/etsi-enc.c @ 478:936a08cc73ce
doc/AMR-library-API: describe the decoder
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 19 May 2024 21:32: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 /* |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * gsmefr-etsi-enc is a test program for our EFR encoder: it reads raw |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * 16-bit PCM (matching ETSI's *.inp) as input and writes ETSI's *.cod |
432
d4f47d0962e7
efrtest/etsi-enc.c: fix error in head comment
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
4 * format as output, allowing our encoder to be tested with ETSI's |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * official test sequences. |
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 * ETSI input and output files are read and written in LE byte order, |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 * matching the official test sequences in ts_100725v050200p0.zip. |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 */ |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <stdio.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <stdint.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include <stdlib.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 #include <string.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 #include <strings.h> |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
16 #include <unistd.h> |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 #include "../libgsmefr/gsm_efr.h" |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 main(argc, argv) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char **argv; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 char *infname, *outfname; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 FILE *inf, *outf; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 struct EFR_encoder_state *state; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 int16_t pcm[160]; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 uint8_t frame[EFR_RTP_FRAME_LEN], bits[250]; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
27 int opt, dtx = 0, rc, sp, vad, big_endian = 0; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
28 extern int optind; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
30 while ((opt = getopt(argc, argv, "bd")) != EOF) { |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
31 switch (opt) { |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
32 case 'b': |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
33 big_endian = 1; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
34 continue; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
35 case 'd': |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
36 dtx = 1; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
37 continue; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
38 default: |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
39 usage: |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
40 fprintf(stderr, |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
41 "usage: %s [-b] [-d] input.inp output.cod\n", |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
42 argv[0]); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
43 exit(1); |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
44 } |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
46 if (argc != optind + 2) |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
47 goto usage; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
48 infname = argv[optind]; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
49 outfname = argv[optind+1]; |
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
50 |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 inf = fopen(infname, "r"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (!inf) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 perror(infname); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 outf = fopen(outfname, "w"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 if (!outf) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 perror(outfname); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 state = EFR_encoder_create(dtx); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (!state) { |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 perror("EFR_encoder_create()"); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 for (;;) { |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
67 rc = read_input(inf, pcm, infname, big_endian); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 if (!rc) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 break; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 EFR_encode_frame(state, pcm, frame, &sp, &vad); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 frame2bits(frame, bits); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 bits[248] = vad; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 bits[249] = sp; |
151
a13b1605142b
gsmefr-etsi-enc: add BE support
Mychaela Falconia <falcon@freecalypso.org>
parents:
114
diff
changeset
|
74 emit_output(outf, bits + 4, 246, big_endian); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 } |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 fclose(outf); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 exit(0); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |