comparison efrtest/decode.c @ 100:d5bab777865a

gsmefr-decode utility written
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 26 Nov 2022 22:07:55 +0000
parents frtest/decode.c@b9a842775f40
children
comparison
equal deleted inserted replaced
99:7152cc7d1ca3 100:d5bab777865a
1 /*
2 * This file is the main module for gsmefr-decode utility.
3 */
4
5 #include <stdio.h>
6 #include <stdint.h>
7 #include <stdlib.h>
8 #include "../libgsmefr/gsm_efr.h"
9 #include "../libtest/binreader.h"
10 #include "../libtest/wavwriter.h"
11 #include "../libtest/pcmwrite.h"
12
13 main(argc, argv)
14 char **argv;
15 {
16 FILE *binf;
17 void *wav;
18 struct EFR_decoder_state *state;
19 uint8_t frame[BINFILE_MAX_FRAME];
20 int16_t pcm[160];
21 int rc, bfi, taf;
22
23 if (argc != 3) {
24 fprintf(stderr, "usage: %s input.gsmx output.wav\n", argv[0]);
25 exit(1);
26 }
27 binf = fopen(argv[1], "r");
28 if (!binf) {
29 perror(argv[1]);
30 exit(1);
31 }
32 wav = wav_write_open(argv[2], 8000, 16, 1);
33 if (!wav) {
34 perror(argv[2]);
35 exit(1);
36 }
37 state = EFR_decoder_create();
38 if (!state) {
39 perror("EFR_decoder_create()");
40 exit(1);
41 }
42 for (;;) {
43 rc = binfile_read_frame(binf, frame);
44 if (rc < 0) {
45 fprintf(stderr, "error: garbage in %s\n", argv[1]);
46 exit(1);
47 }
48 if (!rc)
49 break;
50 if (frame[0] == 0xBF) {
51 bfi = 1;
52 taf = frame[1] & 1;
53 } else if ((frame[0] & 0xF0) == 0xC0)
54 bfi = 0;
55 else {
56 fprintf(stderr,
57 "error: %s is not in EFR codec format\n",
58 argv[1]);
59 exit(1);
60 }
61 if (bfi)
62 EFR_decode_bfi_nodata(state, taf, pcm);
63 else
64 EFR_decode_frame(state, frame, 0, 0, pcm);
65 write_pcm_to_wav(wav, pcm);
66 }
67 wav_write_close(wav);
68 exit(0);
69 }