annotate amrtest/decode.c @ 484:20d44cfc219c

CHANGES: list all new command line utils
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 20 May 2024 01:42:38 +0000
parents fe4983b05230
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
2 * twamr-decode is a speech decoder utility going from *.amr input
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
3 * to WAV output. It logically replaces amrnb-dec from opencore-amr
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
4 * package.
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>
422
1ceda5586d01 implement twamr-tseq-enc test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 151
diff changeset
12 #include "../libtwamr/tw_amr.h"
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
13 #include "../libtest/wavwriter.h"
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
14 #include "../libtest/pcmwrite.h"
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 main(argc, argv)
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 char **argv;
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 {
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
19 FILE *inf;
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
20 void *wav;
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
21 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
22 struct amr_decoder_state *state;
edbbbf1c4ab1 implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
23 struct amr_param_frame frame;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 int16_t pcm[160];
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
25 int rc;
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
27 if (argc != 3) {
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
28 fprintf(stderr, "usage: %s input.amr output.wav\n", argv[0]);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
31 inf = fopen(argv[1], "r");
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
32 if (!inf) {
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
33 perror(argv[1]);
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
34 exit(1);
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
35 }
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
36 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
37 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
38 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
39 argv[1]);
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
40 exit(1);
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
41 }
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
42 wav = wav_write_open(argv[2], 8000, 16, 1);
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
43 if (!wav) {
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
44 perror(argv[2]);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
430
edbbbf1c4ab1 implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
47 state = amr_decoder_create();
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (!state) {
430
edbbbf1c4ab1 implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
49 perror("amr_decoder_create()");
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 exit(1);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
52 for (;;) {
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
53 rc = getc(inf);
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
54 if (rc < 0)
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 break;
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
56 frm_in[0] = rc;
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
57 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
58 if (rc < 0) {
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
59 inv: fprintf(stderr, "error: %s contains invalid AMR data\n",
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
60 argv[1]);
430
edbbbf1c4ab1 implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
61 exit(1);
edbbbf1c4ab1 implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
62 }
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
63 if (rc && fread(frm_in+1, 1, rc, inf) != rc)
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
64 goto inv;
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
65 amr_frame_from_ietf(frm_in, &frame);
430
edbbbf1c4ab1 implement twamr-tseq-dec test program
Mychaela Falconia <falcon@freecalypso.org>
parents: 423
diff changeset
66 amr_decode_frame(state, &frame, pcm);
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
67 write_pcm_to_wav(wav, pcm);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 }
444
fe4983b05230 amrtest: implement twamr-decode
Mychaela Falconia <falcon@freecalypso.org>
parents: 430
diff changeset
69 wav_write_close(wav);
114
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 exit(0);
ff0372186b59 gsmefr-etsi-enc test program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 }