FreeCalypso > hg > gsm-codec-lib
comparison amrtest/tseq-dec.c @ 430:edbbbf1c4ab1
implement twamr-tseq-dec test program
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 07 May 2024 23:35:41 +0000 |
parents | amrtest/tseq-enc.c@cf90077b753c |
children |
comparison
equal
deleted
inserted
replaced
429:3ce30a95769e | 430:edbbbf1c4ab1 |
---|---|
1 /* | |
2 * twamr-tseq-dec is a test program for our AMR decoder: it reads | |
3 * 3GPP AMR *.cod files as input and writes 16-bit linear PCM (raw) | |
4 * files as output, allowing libtwamr decoder to be tested with the | |
5 * official test sequences. | |
6 * | |
7 * Both input and output are read/written in the host machine's | |
8 * native byte order. | |
9 */ | |
10 | |
11 #include <stdio.h> | |
12 #include <stdint.h> | |
13 #include <stdlib.h> | |
14 #include <string.h> | |
15 #include <strings.h> | |
16 #include <unistd.h> | |
17 #include "../libtwamr/tw_amr.h" | |
18 | |
19 static int | |
20 read_input(inf, cod, filename_for_errs) | |
21 FILE *inf; | |
22 uint16_t *cod; | |
23 char *filename_for_errs; | |
24 { | |
25 int cc; | |
26 | |
27 cc = fread(cod, 2, AMR_COD_WORDS, inf); | |
28 if (cc == 0) | |
29 return 0; | |
30 if (cc != AMR_COD_WORDS) { | |
31 fprintf(stderr, "error: short read from %s\n", | |
32 filename_for_errs); | |
33 exit(1); | |
34 } | |
35 return 1; | |
36 } | |
37 | |
38 main(argc, argv) | |
39 char **argv; | |
40 { | |
41 char *infname, *outfname; | |
42 FILE *inf, *outf; | |
43 struct amr_decoder_state *state; | |
44 uint16_t cod[AMR_COD_WORDS]; | |
45 struct amr_param_frame frame; | |
46 int16_t pcm[160]; | |
47 int opt, use_rxtype = 0, rc; | |
48 unsigned frame_no; | |
49 extern int optind; | |
50 | |
51 while ((opt = getopt(argc, argv, "r")) != EOF) { | |
52 switch (opt) { | |
53 case 'r': | |
54 use_rxtype = 1; | |
55 continue; | |
56 default: | |
57 usage: | |
58 fprintf(stderr, "usage: %s [-r] input.cod output.out\n", | |
59 argv[0]); | |
60 exit(1); | |
61 } | |
62 } | |
63 if (argc != optind + 2) | |
64 goto usage; | |
65 infname = argv[optind]; | |
66 outfname = argv[optind+1]; | |
67 | |
68 inf = fopen(infname, "r"); | |
69 if (!inf) { | |
70 perror(infname); | |
71 exit(1); | |
72 } | |
73 outf = fopen(outfname, "w"); | |
74 if (!outf) { | |
75 perror(outfname); | |
76 exit(1); | |
77 } | |
78 state = amr_decoder_create(); | |
79 if (!state) { | |
80 perror("amr_decoder_create()"); | |
81 exit(1); | |
82 } | |
83 for (frame_no = 0; ; frame_no++) { | |
84 rc = read_input(inf, cod, infname); | |
85 if (!rc) | |
86 break; | |
87 rc = amr_frame_from_tseq(cod, use_rxtype, &frame); | |
88 if (rc < 0) { | |
89 fprintf(stderr, | |
90 "error in %s frame %u: amr_frame_from_tseq() returned %d\n", | |
91 infname, frame_no, rc); | |
92 exit(1); | |
93 } | |
94 amr_decode_frame(state, &frame, pcm); | |
95 fwrite(pcm, 2, 160, outf); | |
96 } | |
97 fclose(outf); | |
98 exit(0); | |
99 } |