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