annotate libhr/paramval_common.c @ 40:e1eabf554a75

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