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