FreeCalypso > hg > vband-misc
annotate amrdiff/readone-amr.c @ 2:75ba83624a29
readone-amr program written
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 03 Apr 2024 19:41:45 +0000 |
parents | |
children |
rev | line source |
---|---|
2
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a single frame (the first one) from an AMR *.cod file, |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * enforces that this frame is MR122 speech, and emits the frame of 244 bits |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 * as comma-separated ASCII. The intent is to extract the DHF in a form |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 * convenient for inclusion in amrdiff source. |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 #include "amr_defs.h" |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 main(argc, argv) |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 char **argv; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 char *filename; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int bigend, rc; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 FILE *inf; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint8_t amr_bits[COD_FORMAT_NWORDS]; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (argc != 3) { |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 usage: fprintf(stderr, "usage: %s amr-cod-file be|le\n", argv[0]); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 exit(1); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 filename = argv[1]; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (!strcmp(argv[2], "be")) |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 bigend = 1; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 else if (!strcmp(argv[2], "le")) |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 bigend = 0; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 else |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 goto usage; |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 inf = fopen(filename, "r"); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (!inf) { |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 perror(filename); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 exit(1); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 } |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 rc = read_etsi_bits(inf, bigend, amr_bits, COD_FORMAT_NWORDS, filename); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 if (!rc) { |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 fprintf(stderr, "error: %s is empty\n", filename); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 exit(1); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 } |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (amr_bits[0] != TX_SPEECH_GOOD || amr_bits[245] != MR122) { |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 fprintf(stderr, "error: frame type is wrong\n"); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 exit(1); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 } |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 emit_frame244(amr_bits + 1); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 exit(0); |
75ba83624a29
readone-amr program written
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 } |