FreeCalypso > hg > gsm-codec-lib
annotate miscutil/pcm16-check13.c @ 485:751f06541fbb
doc/Codec-utils: clarify lack of DHF in gsmfr-decode-rb
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 20 May 2024 01:47:22 +0000 |
parents | 6555dae764b3 |
children |
rev | line source |
---|---|
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This program reads a 16-bit PCM recording in raw format (robe by default, |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
3 * or LE with -l option) and checks whether or not every sample fits into |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
4 * left-justified 13 bits, with the 3 least significant bits of every 16-bit |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
5 * sample cleared. |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 */ |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdint.h> |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <stdlib.h> |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include <string.h> |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include <strings.h> |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 main(argc, argv) |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int little_endian; |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
18 char *infname; |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
19 FILE *inf; |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
20 unsigned sample_count; |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 uint8_t inb[2]; |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
22 uint16_t ins, lowbits; |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 int cc; |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
25 if (argc == 2 && argv[1][0] != '-') { |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 little_endian = 0; |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 infname = argv[1]; |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
28 } else if (argc == 3 && !strcmp(argv[1], "-l")) { |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 little_endian = 1; |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 infname = argv[2]; |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } else { |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
32 fprintf(stderr, "usage: %s [-l] input.pcm16\n", argv[0]); |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 exit(1); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 } |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 inf = fopen(infname, "r"); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 if (!inf) { |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 perror(infname); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 exit(1); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
40 for (sample_count = 0; ; sample_count++) { |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 cc = fread(inb, 1, 2, inf); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (cc <= 0) |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 break; |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (cc & 1) { |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 fprintf(stderr, "error: %s has odd number of bytes\n", |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 infname); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 exit(1); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 if (little_endian) |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 ins = ((uint16_t) inb[1] << 8) | ((uint16_t) inb[0]); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 else |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 ins = ((uint16_t) inb[0] << 8) | ((uint16_t) inb[1]); |
221
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
53 lowbits = ins & 7; |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
54 if (lowbits) { |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
55 fprintf(stderr, |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
56 "check13 fail: %s sample #%u low 3 bits are %u\n", |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
57 infname, sample_count, lowbits); |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
58 exit(1); |
6555dae764b3
miscutil: new program pcm16-check13
Mychaela Falconia <falcon@freecalypso.org>
parents:
219
diff
changeset
|
59 } |
219
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 exit(0); |
dc52c3857bf7
miscutil: new program pcm16-to-alaw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 } |