comparison miscutil/pcm16-check13.c @ 221:6555dae764b3

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