comparison amrefr/decode-r.c @ 439:65d20172e92a

amrefr: implement amrefr-decode-r utility
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 09 May 2024 00:12:33 +0000
parents efrtest/decode-r.c@01ce75ea1c8e
children
comparison
equal deleted inserted replaced
438:1bf1bbcef763 439:65d20172e92a
1 /*
2 * amrefr-decode-r is a counterpart to gsmefr-decode-r, implementing
3 * "alternative EFR" by way of libtwamr. Unlike standard gsmefr-decode-r,
4 * this version cannot handle SID frames in input: they are not explicitly
5 * checked for, but an input containing SIDs will not be decoded correctly.
6 */
7
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include "../libgsmefr/gsm_efr.h"
12 #include "../libtwamr/tw_amr.h"
13 #include "../libtest/binreader.h"
14 #include "../libtest/robewrite.h"
15
16 main(argc, argv)
17 char **argv;
18 {
19 FILE *binf, *outf;
20 struct amr_decoder_state *state;
21 uint8_t frame[BINFILE_MAX_FRAME];
22 struct amr_param_frame amr_frame;
23 int16_t pcm[160];
24 int rc, bfi;
25
26 if (argc != 3) {
27 fprintf(stderr, "usage: %s input.gsmx output.robe\n", argv[0]);
28 exit(1);
29 }
30 binf = fopen(argv[1], "r");
31 if (!binf) {
32 perror(argv[1]);
33 exit(1);
34 }
35 outf = fopen(argv[2], "w");
36 if (!outf) {
37 perror(argv[2]);
38 exit(1);
39 }
40 state = amr_decoder_create();
41 if (!state) {
42 perror("amr_decoder_create()");
43 exit(1);
44 }
45 amr_frame.mode = 0x87;
46 for (;;) {
47 rc = binfile_read_frame(binf, frame);
48 if (rc < 0) {
49 fprintf(stderr, "error: garbage in %s\n", argv[1]);
50 exit(1);
51 }
52 if (!rc)
53 break;
54 if (frame[0] == 0xBF)
55 bfi = 1;
56 else if ((frame[0] & 0xF0) == 0xC0)
57 bfi = 0;
58 else {
59 fprintf(stderr,
60 "error: %s is not in EFR codec format\n",
61 argv[1]);
62 exit(1);
63 }
64 if (bfi)
65 amr_frame.type = RX_NO_DATA;
66 else {
67 amr_frame.type = RX_SPEECH_GOOD;
68 EFR_frame2params(frame, amr_frame.param);
69 }
70 amr_decode_frame(state, &amr_frame, pcm);
71 write_pcm_to_robe(outf, pcm);
72 }
73 fclose(outf);
74 exit(0);
75 }