annotate miscutil/pcm16-check13.c @ 242:f081a6850fb5

libgsmfrp: new refined implementation The previous implementation exhibited the following defects, which are now fixed: 1) The last received valid SID was cached forever for the purpose of handling future invalid SIDs - we could have received some valid SID ages ago, then lots of speech or NO_DATA, and if we then get an invalid SID, we would resurrect the last valid SID from ancient history - a bad design. In our new design, we handle invalid SID based on the current state, much like BFI. 2) GSM 06.11 spec says clearly that after the second lost SID (received BFI=1 && TAF=1 in CN state) we need to gradually decrease the output level, rather than jump directly to emitting silence frames - we previously failed to implement such logic. 3) Per GSM 06.12 section 5.2, Xmaxc should be the same in all 4 subframes in a SID frame. What should we do if we receive an otherwise valid SID frame with different Xmaxc? Our previous approach would replicate this Xmaxc oddity in every subsequent generated CN frame, which is rather bad. In our new design, the very first CN frame (which can be seen as a transformation of the SID frame itself) retains the original 4 distinct Xmaxc, but all subsequent CN frames are based on the Xmaxc from the last subframe of the most recent SID.
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 09 May 2023 05:16:31 +0000
parents 6555dae764b3
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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 }