annotate libgsmhr1/paramval_common.c @ 512:4f0ab833bec0

libgsmhr1: add parameter validation function
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 25 Aug 2024 18:42:27 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
512
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * The function implemented in this module examines an array of 18 codec
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * parameters in the int16_t representation used in this library, and checks
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 * if the unused upper bits of each int16_t word are cleared as they should be.
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 * This function, or higher-level wrappers around it, should be used when
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 * reading from ETSI-format *.cod and *.dec files, to guard against reading
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 * garbage or wrong endian.
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include "tw_gsmhr.h"
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 int gsmhr_check_common_params(const int16_t *params)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 /* common parameters for all modes */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 if (params[0] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 if (params[1] & 0xF800)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (params[2] & 0xFE00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (params[3] & 0xFF00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 if (params[4] & 0xFFFE)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 if (params[5] & 0xFFFC)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (params[5]) {
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 /* voiced modes */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 /* subframe 1 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (params[6] & 0xFF00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (params[7] & 0xFE00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 if (params[8] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 /* subframe 2 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 if (params[9] & 0xFFF0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (params[10] & 0xFE00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (params[11] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 /* subframe 3 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (params[12] & 0xFFF0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 if (params[13] & 0xFE00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (params[14] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 /* subframe 4 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (params[15] & 0xFFF0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 if (params[16] & 0xFE00)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 if (params[17] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 } else {
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 /* unvoiced mode */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 /* subframe 1 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (params[6] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (params[7] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 if (params[8] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 /* subframe 2 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (params[9] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 if (params[10] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 if (params[11] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 /* subframe 3 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 if (params[12] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 if (params[13] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (params[14] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 /* subframe 4 */
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (params[15] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (params[16] & 0xFF80)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 if (params[17] & 0xFFE0)
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return -1;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 return 0;
4f0ab833bec0 libgsmhr1: add parameter validation function
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 }