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