FreeCalypso > hg > gsm-codec-lib
annotate amrtest/decode-r.c @ 481:cc0c244bd233
doc/AMR-library-tests: new article
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 20 May 2024 01:02:37 +0000 |
parents | e2f824ffd08a |
children |
rev | line source |
---|---|
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
2 * twamr-decode-r is a speech decoder utility going from *.amr input |
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
3 * to "robe" (raw BE) output. |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
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 #include <stdio.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdint.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
422
1ceda5586d01
implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
151
diff
changeset
|
11 #include "../libtwamr/tw_amr.h" |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
12 #include "../libtest/robewrite.h" |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 main(argc, argv) |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
17 FILE *inf, *outf; |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
18 uint8_t frm_in[AMR_IETF_MAX_PL]; |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
19 struct amr_decoder_state *state; |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
20 struct amr_param_frame frame; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 int16_t pcm[160]; |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
22 int rc; |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
24 if (argc != 3) { |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
25 fprintf(stderr, "usage: %s input.amr output.robe\n", argv[0]); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 } |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
28 inf = fopen(argv[1], "r"); |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
29 if (!inf) { |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
30 perror(argv[1]); |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
31 exit(1); |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
32 } |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
33 if (fread(frm_in, 1, AMR_IETF_HDR_LEN, inf) != AMR_IETF_HDR_LEN || |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
34 bcmp(frm_in, amr_file_header_magic, AMR_IETF_HDR_LEN)) { |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
35 fprintf(stderr, "error: %s is not in IETF AMR format\n", |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
36 argv[1]); |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
37 exit(1); |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
38 } |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
39 outf = fopen(argv[2], "w"); |
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
40 if (!outf) { |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
41 perror(argv[2]); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
44 state = amr_decoder_create(); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 if (!state) { |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
46 perror("amr_decoder_create()"); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
49 for (;;) { |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
50 rc = getc(inf); |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
51 if (rc < 0) |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 break; |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
53 frm_in[0] = rc; |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
54 rc = amr_ietf_grok_first_octet(frm_in[0]); |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
55 if (rc < 0) { |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
56 inv: fprintf(stderr, "error: %s contains invalid AMR data\n", |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
57 argv[1]); |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
58 exit(1); |
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
59 } |
444
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
60 if (rc && fread(frm_in+1, 1, rc, inf) != rc) |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
61 goto inv; |
fe4983b05230
amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents:
430
diff
changeset
|
62 amr_frame_from_ietf(frm_in, &frame); |
430
edbbbf1c4ab1
implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents:
423
diff
changeset
|
63 amr_decode_frame(state, &frame, pcm); |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
64 write_pcm_to_robe(outf, pcm); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
446
e2f824ffd08a
amrtest: implement twamr-decode-r
Mychaela Falconia <falcon@freecalypso.org>
parents:
444
diff
changeset
|
66 fclose(outf); |
114
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 exit(0); |
ff0372186b59
gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 } |