forge
Explore
Log in

Don't you dare go Hollow

edith_codecs

Clone
★ 0

0 watching0 forksRust370.3 MiB9b67700Tahinli3 days ago4021 commits

bits.rs477 lines, 23.0 KiBHistoryRawDownload
1//! Bit reading (get_amr_wb_bits.cpp), MIME unsorting (mime_io.cpp) and decoder homing frame test (homing_amr_wb_dec.cpp).
2#![allow(dead_code)]
3
4use super::ops::*;
5
6pub const BIT_0: i16 = -127;
7pub const BIT_1: i16 = 127;
8
9pub const MODE_7K: i16 = 0;
10pub const MODE_9K: i16 = 1;
11pub const MODE_12K: i16 = 2;
12pub const MODE_14K: i16 = 3;
13pub const MODE_16K: i16 = 4;
14pub const MODE_18K: i16 = 5;
15pub const MODE_20K: i16 = 6;
16pub const MODE_23K: i16 = 7;
17pub const MODE_24K: i16 = 8;
18pub const MRDTX: i16 = 9;
19pub const MRSID: i16 = 9;
20
21/// Reader over the serial parameter bits (replaces C `int16 **prms`).
22pub struct Prms<'a> {
23 pub buf: &'a [i16],
24 pub pos: usize,
25}
26
27impl<'a> Prms<'a> {
28 pub fn new(buf: &'a [i16]) -> Self {
29 Prms { buf, pos: 0 }
30 }
31 #[inline]
32 fn next(&mut self) -> i16 {
33 let v = self.buf.get(self.pos).copied().unwrap_or(0);
34 self.pos += 1;
35 v
36 }
37}
38
39/// Port of `Serial_parm`.
40pub fn Serial_parm(no_of_bits: i16, prms: &mut Prms) -> i16 {
41 let mut value: i16 = 0;
42 let mut i = no_of_bits >> 1;
43 while i != 0 {
44 value = value.wrapping_shl(2);
45 if prms.next() == BIT_1 {
46 value |= 2;
47 }
48 if prms.next() == BIT_1 {
49 value |= 1;
50 }
51 i -= 1;
52 }
53 if no_of_bits & 1 != 0 {
54 value = value.wrapping_shl(1);
55 if prms.next() == BIT_1 {
56 value |= 1;
57 }
58 }
59 value
60}
61
62/// Port of `Serial_parm_1bit`.
63pub fn Serial_parm_1bit(prms: &mut Prms) -> i16 {
64 if prms.next() == BIT_1 { 1 } else { 0 }
65}
66
67// ---------------- mime_io.cpp ----------------
68
69pub static toc_byte: [u8; 16] = [
70 0x04, 0x0C, 0x14, 0x1C, 0x24, 0x2C, 0x34, 0x3C, 0x44, 0x4C, 0x54, 0x5C, 0x64, 0x6C, 0x74, 0x7C,
71];
72pub static unpacked_size: [i16; 16] = [
73 132, 177, 253, 285, 317, 365, 397, 461, 477, 35, 0, 0, 0, 0, 0, 0,
74];
75pub static packed_size: [i16; 16] = [17, 23, 32, 36, 40, 46, 50, 58, 60, 5, 0, 0, 0, 0, 0, 0];
76pub static unused_size: [i16; 16] = [4, 7, 3, 3, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 0, 0];
77
78pub static sort_660: [i16; 132] = [
79 0, 5, 6, 7, 61, 84, 107, 130, 62, 85, 8, 4, 37, 38, 39, 40, 58, 81, 104, 127, 60, 83, 106, 129,
80 108, 131, 128, 41, 42, 80, 126, 1, 3, 57, 103, 82, 105, 59, 2, 63, 109, 110, 86, 19, 22, 23,
81 64, 87, 18, 20, 21, 17, 13, 88, 43, 89, 65, 111, 14, 24, 25, 26, 27, 28, 15, 16, 44, 90, 66,
82 112, 9, 11, 10, 12, 67, 113, 29, 30, 31, 32, 34, 33, 35, 36, 45, 51, 68, 74, 91, 97, 114, 120,
83 46, 69, 92, 115, 52, 75, 98, 121, 47, 70, 93, 116, 53, 76, 99, 122, 48, 71, 94, 117, 54, 77,
84 100, 123, 49, 72, 95, 118, 55, 78, 101, 124, 50, 73, 96, 119, 56, 79, 102, 125,
85];
86pub static sort_885: [i16; 177] = [
87 0, 4, 6, 7, 5, 3, 47, 48, 49, 112, 113, 114, 75, 106, 140, 171, 80, 111, 145, 176, 77, 108,
88 142, 173, 78, 109, 143, 174, 79, 110, 144, 175, 76, 107, 141, 172, 50, 115, 51, 2, 1, 81, 116,
89 146, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14, 24, 23, 22, 26, 8, 15, 52, 117, 31, 82, 147,
90 9, 33, 11, 83, 148, 53, 118, 28, 27, 84, 149, 34, 35, 29, 46, 32, 30, 54, 119, 37, 36, 39, 38,
91 40, 85, 150, 41, 42, 43, 44, 45, 55, 60, 65, 70, 86, 91, 96, 101, 120, 125, 130, 135, 151, 156,
92 161, 166, 56, 87, 121, 152, 61, 92, 126, 157, 66, 97, 131, 162, 71, 102, 136, 167, 57, 88, 122,
93 153, 62, 93, 127, 158, 67, 98, 132, 163, 72, 103, 137, 168, 58, 89, 123, 154, 63, 94, 128, 159,
94 68, 99, 133, 164, 73, 104, 138, 169, 59, 90, 124, 155, 64, 95, 129, 160, 69, 100, 134, 165, 74,
95 105, 139, 170,
96];
97pub static sort_1265: [i16; 253] = [
98 0, 4, 6, 93, 143, 196, 246, 7, 5, 3, 47, 48, 49, 50, 51, 150, 151, 152, 153, 154, 94, 144, 197,
99 247, 99, 149, 202, 252, 96, 146, 199, 249, 97, 147, 200, 250, 100, 203, 98, 148, 201, 251, 95,
100 145, 198, 248, 52, 2, 1, 101, 204, 155, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14, 24, 23, 22,
101 26, 8, 15, 53, 156, 31, 102, 205, 9, 33, 11, 103, 206, 54, 157, 28, 27, 104, 207, 34, 35, 29,
102 46, 32, 30, 55, 158, 37, 36, 39, 38, 40, 105, 208, 41, 42, 43, 44, 45, 56, 106, 159, 209, 57,
103 66, 75, 84, 107, 116, 125, 134, 160, 169, 178, 187, 210, 219, 228, 237, 58, 108, 161, 211, 62,
104 112, 165, 215, 67, 117, 170, 220, 71, 121, 174, 224, 76, 126, 179, 229, 80, 130, 183, 233, 85,
105 135, 188, 238, 89, 139, 192, 242, 59, 109, 162, 212, 63, 113, 166, 216, 68, 118, 171, 221, 72,
106 122, 175, 225, 77, 127, 180, 230, 81, 131, 184, 234, 86, 136, 189, 239, 90, 140, 193, 243, 60,
107 110, 163, 213, 64, 114, 167, 217, 69, 119, 172, 222, 73, 123, 176, 226, 78, 128, 181, 231, 82,
108 132, 185, 235, 87, 137, 190, 240, 91, 141, 194, 244, 61, 111, 164, 214, 65, 115, 168, 218, 70,
109 120, 173, 223, 74, 124, 177, 227, 79, 129, 182, 232, 83, 133, 186, 236, 88, 138, 191, 241, 92,
110 142, 195, 245,
111];
112pub static sort_1425: [i16; 285] = [
113 0, 4, 6, 101, 159, 220, 278, 7, 5, 3, 47, 48, 49, 50, 51, 166, 167, 168, 169, 170, 102, 160,
114 221, 279, 107, 165, 226, 284, 104, 162, 223, 281, 105, 163, 224, 282, 108, 227, 106, 164, 225,
115 283, 103, 161, 222, 280, 52, 2, 1, 109, 228, 171, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14,
116 24, 23, 22, 26, 8, 15, 53, 172, 31, 110, 229, 9, 33, 11, 111, 230, 54, 173, 28, 27, 112, 231,
117 34, 35, 29, 46, 32, 30, 55, 174, 37, 36, 39, 38, 40, 113, 232, 41, 42, 43, 44, 45, 56, 114,
118 175, 233, 62, 120, 181, 239, 75, 133, 194, 252, 57, 115, 176, 234, 63, 121, 182, 240, 70, 128,
119 189, 247, 76, 134, 195, 253, 83, 141, 202, 260, 92, 150, 211, 269, 84, 142, 203, 261, 93, 151,
120 212, 270, 85, 143, 204, 262, 94, 152, 213, 271, 86, 144, 205, 263, 95, 153, 214, 272, 64, 122,
121 183, 241, 77, 135, 196, 254, 65, 123, 184, 242, 78, 136, 197, 255, 87, 145, 206, 264, 96, 154,
122 215, 273, 58, 116, 177, 235, 66, 124, 185, 243, 71, 129, 190, 248, 79, 137, 198, 256, 88, 146,
123 207, 265, 97, 155, 216, 274, 59, 117, 178, 236, 67, 125, 186, 244, 72, 130, 191, 249, 80, 138,
124 199, 257, 89, 147, 208, 266, 98, 156, 217, 275, 60, 118, 179, 237, 68, 126, 187, 245, 73, 131,
125 192, 250, 81, 139, 200, 258, 90, 148, 209, 267, 99, 157, 218, 276, 61, 119, 180, 238, 69, 127,
126 188, 246, 74, 132, 193, 251, 82, 140, 201, 259, 91, 149, 210, 268, 100, 158, 219, 277,
127];
128pub static sort_1585: [i16; 317] = [
129 0, 4, 6, 109, 175, 244, 310, 7, 5, 3, 47, 48, 49, 50, 51, 182, 183, 184, 185, 186, 110, 176,
130 245, 311, 115, 181, 250, 316, 112, 178, 247, 313, 113, 179, 248, 314, 116, 251, 114, 180, 249,
131 315, 111, 177, 246, 312, 52, 2, 1, 117, 252, 187, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14,
132 24, 23, 22, 26, 8, 15, 53, 188, 31, 118, 253, 9, 33, 11, 119, 254, 54, 189, 28, 27, 120, 255,
133 34, 35, 29, 46, 32, 30, 55, 190, 37, 36, 39, 38, 40, 121, 256, 41, 42, 43, 44, 45, 56, 122,
134 191, 257, 63, 129, 198, 264, 76, 142, 211, 277, 89, 155, 224, 290, 102, 168, 237, 303, 57, 123,
135 192, 258, 70, 136, 205, 271, 83, 149, 218, 284, 96, 162, 231, 297, 62, 128, 197, 263, 75, 141,
136 210, 276, 88, 154, 223, 289, 101, 167, 236, 302, 58, 124, 193, 259, 71, 137, 206, 272, 84, 150,
137 219, 285, 97, 163, 232, 298, 59, 125, 194, 260, 64, 130, 199, 265, 67, 133, 202, 268, 72, 138,
138 207, 273, 77, 143, 212, 278, 80, 146, 215, 281, 85, 151, 220, 286, 90, 156, 225, 291, 93, 159,
139 228, 294, 98, 164, 233, 299, 103, 169, 238, 304, 106, 172, 241, 307, 60, 126, 195, 261, 65,
140 131, 200, 266, 68, 134, 203, 269, 73, 139, 208, 274, 78, 144, 213, 279, 81, 147, 216, 282, 86,
141 152, 221, 287, 91, 157, 226, 292, 94, 160, 229, 295, 99, 165, 234, 300, 104, 170, 239, 305,
142 107, 173, 242, 308, 61, 127, 196, 262, 66, 132, 201, 267, 69, 135, 204, 270, 74, 140, 209, 275,
143 79, 145, 214, 280, 82, 148, 217, 283, 87, 153, 222, 288, 92, 158, 227, 293, 95, 161, 230, 296,
144 100, 166, 235, 301, 105, 171, 240, 306, 108, 174, 243, 309,
145];
146pub static sort_1825: [i16; 365] = [
147 0, 4, 6, 121, 199, 280, 358, 7, 5, 3, 47, 48, 49, 50, 51, 206, 207, 208, 209, 210, 122, 200,
148 281, 359, 127, 205, 286, 364, 124, 202, 283, 361, 125, 203, 284, 362, 128, 287, 126, 204, 285,
149 363, 123, 201, 282, 360, 52, 2, 1, 129, 288, 211, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14,
150 24, 23, 22, 26, 8, 15, 53, 212, 31, 130, 289, 9, 33, 11, 131, 290, 54, 213, 28, 27, 132, 291,
151 34, 35, 29, 46, 32, 30, 55, 214, 37, 36, 39, 38, 40, 133, 292, 41, 42, 43, 44, 45, 56, 134,
152 215, 293, 198, 299, 136, 120, 138, 60, 279, 58, 62, 357, 139, 140, 295, 156, 57, 219, 297, 63,
153 217, 137, 170, 300, 222, 64, 106, 61, 78, 294, 92, 142, 141, 135, 221, 296, 301, 343, 59, 298,
154 184, 329, 315, 220, 216, 265, 251, 218, 237, 352, 223, 157, 86, 171, 87, 164, 351, 111, 302,
155 65, 178, 115, 323, 72, 192, 101, 179, 93, 73, 193, 151, 337, 309, 143, 274, 69, 324, 165, 150,
156 97, 338, 110, 310, 330, 273, 68, 107, 175, 245, 114, 79, 113, 189, 246, 259, 174, 71, 185, 96,
157 344, 100, 322, 83, 334, 316, 333, 252, 161, 348, 147, 82, 269, 232, 260, 308, 353, 347, 163,
158 231, 306, 320, 188, 270, 146, 177, 266, 350, 256, 85, 149, 116, 191, 160, 238, 258, 336, 305,
159 255, 88, 224, 99, 339, 230, 228, 227, 272, 242, 241, 319, 233, 311, 102, 74, 180, 275, 66, 194,
160 152, 325, 172, 247, 244, 261, 117, 158, 166, 354, 75, 144, 108, 312, 94, 186, 303, 80, 234, 89,
161 195, 112, 340, 181, 345, 317, 326, 276, 239, 167, 118, 313, 70, 355, 327, 253, 190, 176, 271,
162 104, 98, 153, 103, 90, 76, 267, 277, 248, 225, 262, 182, 84, 154, 235, 335, 168, 331, 196, 341,
163 249, 162, 307, 148, 349, 263, 321, 257, 243, 229, 356, 159, 119, 67, 187, 173, 145, 240, 77,
164 304, 332, 314, 342, 109, 254, 81, 278, 105, 91, 346, 318, 183, 250, 197, 328, 95, 155, 169,
165 268, 226, 236, 264,
166];
167pub static sort_1985: [i16; 397] = [
168 0, 4, 6, 129, 215, 304, 390, 7, 5, 3, 47, 48, 49, 50, 51, 222, 223, 224, 225, 226, 130, 216,
169 305, 391, 135, 221, 310, 396, 132, 218, 307, 393, 133, 219, 308, 394, 136, 311, 134, 220, 309,
170 395, 131, 217, 306, 392, 52, 2, 1, 137, 312, 227, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14,
171 24, 23, 22, 26, 8, 15, 53, 228, 31, 138, 313, 9, 33, 11, 139, 314, 54, 229, 28, 27, 140, 315,
172 34, 35, 29, 46, 32, 30, 55, 230, 37, 36, 39, 38, 40, 141, 316, 41, 42, 43, 44, 45, 56, 142,
173 231, 317, 63, 73, 92, 340, 82, 324, 149, 353, 159, 334, 165, 338, 178, 163, 254, 77, 168, 257,
174 153, 343, 57, 248, 238, 79, 252, 166, 67, 80, 201, 101, 267, 143, 164, 341, 255, 339, 187, 376,
175 318, 78, 328, 362, 115, 232, 242, 253, 290, 276, 62, 58, 158, 68, 93, 179, 319, 148, 169, 154,
176 72, 385, 329, 333, 344, 102, 83, 144, 233, 323, 124, 243, 192, 354, 237, 64, 247, 202, 209,
177 150, 116, 335, 268, 239, 299, 188, 196, 298, 94, 195, 258, 123, 363, 384, 109, 325, 371, 170,
178 370, 84, 110, 295, 180, 74, 210, 191, 106, 291, 205, 367, 381, 377, 206, 355, 122, 119, 120,
179 383, 160, 105, 108, 277, 380, 294, 284, 285, 345, 208, 269, 249, 366, 386, 300, 297, 259, 125,
180 369, 197, 97, 194, 286, 211, 281, 280, 183, 372, 87, 155, 283, 59, 348, 327, 184, 76, 111, 330,
181 203, 349, 69, 98, 152, 145, 189, 66, 320, 337, 173, 358, 251, 198, 174, 263, 262, 126, 241,
182 193, 88, 388, 117, 95, 387, 112, 359, 287, 244, 103, 272, 301, 171, 162, 234, 273, 127, 373,
183 181, 292, 85, 378, 302, 121, 107, 364, 346, 356, 212, 278, 213, 65, 382, 288, 207, 113, 175,
184 99, 296, 374, 368, 199, 260, 185, 336, 331, 161, 270, 264, 250, 240, 75, 350, 151, 60, 89, 321,
185 156, 274, 360, 326, 70, 282, 167, 146, 352, 81, 91, 389, 266, 245, 177, 235, 190, 256, 204,
186 342, 128, 118, 303, 104, 379, 182, 114, 375, 200, 96, 293, 172, 214, 365, 279, 86, 289, 351,
187 347, 357, 261, 186, 176, 271, 90, 100, 147, 322, 275, 361, 71, 332, 61, 265, 157, 246, 236,
188];
189pub static sort_2305: [i16; 461] = [
190 0, 4, 6, 145, 247, 352, 454, 7, 5, 3, 47, 48, 49, 50, 51, 254, 255, 256, 257, 258, 146, 248,
191 353, 455, 151, 253, 358, 460, 148, 250, 355, 457, 149, 251, 356, 458, 152, 359, 150, 252, 357,
192 459, 147, 249, 354, 456, 52, 2, 1, 153, 360, 259, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14,
193 24, 23, 22, 26, 8, 15, 53, 260, 31, 154, 361, 9, 33, 11, 155, 362, 54, 261, 28, 27, 156, 363,
194 34, 35, 29, 46, 32, 30, 55, 262, 37, 36, 39, 38, 40, 157, 364, 41, 42, 43, 44, 45, 56, 158,
195 263, 365, 181, 192, 170, 79, 57, 399, 90, 159, 297, 377, 366, 275, 68, 183, 388, 286, 194, 299,
196 92, 70, 182, 401, 172, 59, 91, 58, 400, 368, 161, 81, 160, 264, 171, 80, 389, 390, 378, 379,
197 193, 298, 69, 266, 265, 367, 277, 288, 276, 287, 184, 60, 195, 82, 93, 71, 369, 402, 173, 162,
198 444, 300, 391, 98, 76, 278, 61, 267, 374, 135, 411, 167, 102, 380, 200, 87, 178, 65, 94, 204,
199 124, 72, 342, 189, 305, 381, 396, 433, 301, 226, 407, 289, 237, 113, 215, 185, 128, 309, 403,
200 116, 320, 196, 331, 370, 422, 174, 64, 392, 83, 425, 219, 134, 188, 432, 112, 427, 139, 279,
201 163, 436, 208, 447, 218, 236, 229, 97, 294, 385, 230, 166, 268, 177, 443, 225, 426, 101, 272,
202 138, 127, 290, 117, 347, 199, 414, 95, 140, 240, 410, 395, 209, 129, 283, 346, 105, 241, 437,
203 86, 308, 448, 203, 345, 186, 107, 220, 415, 334, 319, 106, 313, 118, 123, 73, 207, 421, 214,
204 384, 373, 438, 62, 371, 341, 75, 449, 168, 323, 164, 242, 416, 324, 304, 197, 335, 404, 271,
205 63, 191, 325, 96, 169, 231, 280, 312, 187, 406, 84, 201, 100, 67, 382, 175, 336, 202, 330, 269,
206 393, 376, 383, 293, 307, 409, 179, 285, 314, 302, 372, 398, 190, 180, 89, 99, 103, 232, 78, 88,
207 77, 136, 387, 165, 198, 394, 125, 176, 428, 74, 375, 238, 227, 66, 273, 282, 141, 306, 412,
208 114, 85, 130, 348, 119, 291, 296, 386, 233, 397, 303, 405, 284, 445, 423, 221, 210, 205, 450,
209 108, 274, 434, 216, 343, 337, 142, 243, 321, 408, 451, 310, 292, 120, 109, 281, 439, 270, 429,
210 332, 295, 418, 211, 315, 222, 326, 131, 430, 244, 327, 349, 417, 316, 143, 338, 440, 234, 110,
211 212, 452, 245, 121, 419, 350, 223, 132, 441, 328, 413, 317, 339, 126, 104, 137, 446, 344, 239,
212 435, 115, 333, 206, 322, 217, 228, 424, 453, 311, 351, 111, 442, 224, 213, 122, 431, 340, 235,
213 246, 133, 144, 420, 329, 318,
214];
215pub static sort_2385: [i16; 477] = [
216 0, 4, 6, 145, 251, 360, 466, 7, 5, 3, 47, 48, 49, 50, 51, 262, 263, 264, 265, 266, 146, 252,
217 361, 467, 151, 257, 366, 472, 148, 254, 363, 469, 149, 255, 364, 470, 156, 371, 150, 256, 365,
218 471, 147, 253, 362, 468, 52, 2, 1, 157, 372, 267, 19, 21, 12, 17, 18, 20, 16, 25, 13, 10, 14,
219 24, 23, 22, 26, 8, 15, 53, 268, 31, 152, 153, 154, 155, 258, 259, 260, 261, 367, 368, 369, 370,
220 473, 474, 475, 476, 158, 373, 9, 33, 11, 159, 374, 54, 269, 28, 27, 160, 375, 34, 35, 29, 46,
221 32, 30, 55, 270, 37, 36, 39, 38, 40, 161, 376, 41, 42, 43, 44, 45, 56, 162, 271, 377, 185, 196,
222 174, 79, 57, 411, 90, 163, 305, 389, 378, 283, 68, 187, 400, 294, 198, 307, 92, 70, 186, 413,
223 176, 59, 91, 58, 412, 380, 165, 81, 164, 272, 175, 80, 401, 402, 390, 391, 197, 306, 69, 274,
224 273, 379, 285, 296, 284, 295, 188, 60, 199, 82, 93, 71, 381, 414, 177, 166, 456, 308, 403, 98,
225 76, 286, 61, 275, 386, 135, 423, 171, 102, 392, 204, 87, 182, 65, 94, 208, 124, 72, 350, 193,
226 313, 393, 408, 445, 309, 230, 419, 297, 241, 113, 219, 189, 128, 317, 415, 116, 328, 200, 339,
227 382, 434, 178, 64, 404, 83, 437, 223, 134, 192, 444, 112, 439, 139, 287, 167, 448, 212, 459,
228 222, 240, 233, 97, 302, 397, 234, 170, 276, 181, 455, 229, 438, 101, 280, 138, 127, 298, 117,
229 355, 203, 426, 95, 140, 244, 422, 407, 213, 129, 291, 354, 105, 245, 449, 86, 316, 460, 207,
230 353, 190, 107, 224, 427, 342, 327, 106, 321, 118, 123, 73, 211, 433, 218, 396, 385, 450, 62,
231 383, 349, 75, 461, 172, 331, 168, 246, 428, 332, 312, 201, 343, 416, 279, 63, 195, 333, 96,
232 173, 235, 288, 320, 191, 418, 84, 205, 100, 67, 394, 179, 344, 206, 338, 277, 405, 388, 395,
233 301, 315, 421, 183, 293, 322, 310, 384, 410, 194, 184, 89, 99, 103, 236, 78, 88, 77, 136, 399,
234 169, 202, 406, 125, 180, 440, 74, 387, 242, 231, 66, 281, 290, 141, 314, 424, 114, 85, 130,
235 356, 119, 299, 304, 398, 237, 409, 311, 417, 292, 457, 435, 225, 214, 209, 462, 108, 282, 446,
236 220, 351, 345, 142, 247, 329, 420, 463, 318, 300, 120, 109, 289, 451, 278, 441, 340, 303, 430,
237 215, 323, 226, 334, 131, 442, 248, 335, 357, 429, 324, 143, 346, 452, 238, 110, 216, 464, 249,
238 121, 431, 358, 227, 132, 453, 336, 425, 325, 347, 126, 104, 137, 458, 352, 243, 447, 115, 341,
239 210, 330, 221, 232, 436, 465, 319, 359, 111, 454, 228, 217, 122, 443, 348, 239, 250, 133, 144,
240 432, 337, 326,
241];
242pub static sort_sid: [i16; 35] = [
243 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25,
244 26, 27, 28, 29, 30, 31, 32, 33, 34,
245];
246
247/// RX_State of mime_io.
248#[derive(Clone, Copy, Default)]
249pub struct RxState {
250 pub prev_ft: i16,
251 pub prev_mode: i16,
252}
253
254fn sorting_table(mode: i16) -> Option<&'static [i16]> {
255 match mode {
256 0 => Some(&sort_660[..]),
257 1 => Some(&sort_885[..]),
258 2 => Some(&sort_1265[..]),
259 3 => Some(&sort_1425[..]),
260 4 => Some(&sort_1585[..]),
261 5 => Some(&sort_1825[..]),
262 6 => Some(&sort_1985[..]),
263 7 => Some(&sort_2305[..]),
264 8 => Some(&sort_2385[..]),
265 9 => Some(&sort_sid[..]),
266 _ => None,
267 }
268}
269
270/// Port of `mime_unsorting`. `mode` must be 0..=15.
271pub fn mime_unsorting(
272 unsorted_bits: &[u8],
273 sorted_bits_into_int16: &mut [i16],
274 frame_type: &mut i16,
275 mode: &mut i16,
276 quality: u8,
277 st: &mut RxState,
278) {
279 use super::dtx::*;
280 let tbl: &[i16] = sorting_table(*mode).unwrap_or(&[]);
281 let mut pt: usize = 0;
282 let mut up: usize = 0;
283 let usz = unpacked_size[(*mode & 15) as usize];
284 for v in sorted_bits_into_int16.iter_mut().take(usz as usize) {
285 *v = 0;
286 }
287 let mut temp: u8 = 0;
288 let mut i = usz >> 3;
289 while i != 0 {
290 temp = unsorted_bits.get(up).copied().unwrap_or(0);
291 up += 1;
292 for _ in 0..2 {
293 // nibble bits, MSB first
294 let nib = temp & 0xf0;
295 for b in 0..4 {
296 if nib & (0x80 >> b) != 0 {
297 sorted_bits_into_int16[tbl[pt] as usize] = BIT_1;
298 }
299 pt += 1;
300 }
301 temp <<= 4;
302 }
303 i -= 1;
304 }
305 temp = unsorted_bits.get(up).copied().unwrap_or(0);
306 let mut i = usz % 8;
307 while i != 0 {
308 if temp & 0x80 != 0 {
309 sorted_bits_into_int16[tbl[pt] as usize] = BIT_1;
310 }
311 pt += 1;
312 temp <<= 1;
313 i -= 1;
314 }
315
316 match *mode {
317 0..=8 => {
318 *frame_type = if quality != 0 {
319 RX_SPEECH_GOOD
320 } else {
321 RX_SPEECH_BAD
322 };
323 }
324 MRSID => {
325 if quality != 0 {
326 *frame_type = if temp & 0x80 != 0 {
327 RX_SID_UPDATE
328 } else {
329 RX_SID_FIRST
330 };
331 } else {
332 *frame_type = RX_SID_BAD;
333 }
334 *mode = st.prev_mode;
335 }
336 14 => {
337 *frame_type = RX_SPEECH_LOST;
338 *mode = st.prev_mode;
339 }
340 _ => {
341 *frame_type = RX_NO_DATA;
342 *mode = st.prev_mode;
343 }
344 }
345 st.prev_mode = *mode;
346}
347
348// ---------------- homing_amr_wb_dec.cpp ----------------
349
350const DHF_PARMS_MAX: usize = 32;
351static prmnofsf: [i16; 9] = [63, 81, 100, 108, 116, 128, 136, 152, 156];
352
353static DFH_M7K: [i16; 9] = [3168, 29954, 29213, 16121, 64, 13440, 30624, 16430, 19008];
354static DFH_M9K: [i16; 12] = [
355 3168, 31665, 9943, 9123, 15599, 4358, 20248, 2048, 17040, 27787, 16816, 13888,
356];
357static DFH_M12K: [i16; 17] = [
358 3168, 31665, 9943, 9128, 3647, 8129, 30930, 27926, 18880, 12319, 496, 1042, 4061, 20446, 25629,
359 28069, 13948,
360];
361static DFH_M14K: [i16; 19] = [
362 3168, 31665, 9943, 9131, 24815, 655, 26616, 26764, 7238, 19136, 6144, 88, 4158, 25733, 30567,
363 30494, 221, 20321, 17823,
364];
365static DFH_M16K: [i16; 22] = [
366 3168, 31665, 9943, 9131, 24815, 700, 3824, 7271, 26400, 9528, 6594, 26112, 108, 2068, 12867,
367 16317, 23035, 24632, 7528, 1752, 6759, 24576,
368];
369static DFH_M18K: [i16; 25] = [
370 3168, 31665, 9943, 9135, 14787, 14423, 30477, 24927, 25345, 30154, 916, 5728, 18978, 2048, 528,
371 16449, 2436, 3581, 23527, 29479, 8237, 16810, 27091, 19052, 0,
372];
373static DFH_M20K: [i16; 27] = [
374 3168, 31665, 9943, 9129, 8637, 31807, 24646, 736, 28643, 2977, 2566, 25564, 12930, 13960, 2048,
375 834, 3270, 4100, 26920, 16237, 31227, 17667, 15059, 20589, 30249, 29123, 0,
376];
377static DFH_M23K: [i16; 31] = [
378 3168, 31665, 9943, 9132, 16748, 3202, 28179, 16317, 30590, 15857, 19960, 8818, 21711, 21538,
379 4260, 16690, 20224, 3666, 4194, 9497, 16320, 15388, 5755, 31551, 14080, 3574, 15932, 50, 23392,
380 26053, 31216,
381];
382static DFH_M24K: [i16; 32] = [
383 3168, 31665, 9943, 9134, 24776, 5857, 18475, 28535, 29662, 14321, 16725, 4396, 29353, 10003,
384 17068, 20504, 720, 0, 8465, 12581, 28863, 24774, 9709, 26043, 7941, 27649, 13965, 15236, 18026,
385 22047, 16681, 3968,
386];
387
388fn dhf_table(mode: i32) -> &'static [i16] {
389 match mode {
390 0 => &DFH_M7K[..],
391 1 => &DFH_M9K[..],
392 2 => &DFH_M12K[..],
393 3 => &DFH_M14K[..],
394 4 => &DFH_M16K[..],
395 5 => &DFH_M18K[..],
396 6 => &DFH_M20K[..],
397 7 => &DFH_M23K[..],
398 _ => &DFH_M24K[..],
399 }
400}
401
402/// Port of `dhf_test`.
403pub fn dhf_test(input_frame: &[i16], mode: i32, nparms: i16) -> i16 {
404 let dhf = dhf_table(mode);
405 let mut param = [0i16; DHF_PARMS_MAX + 1];
406 let mut prms = Prms::new(input_frame);
407 let mut j: i16 = 0;
408 let mut i: usize = 0;
409 let mut shift: i16 = 0;
410 if mode != MRDTX as i32 {
411 if mode != MODE_24K as i32 {
412 let mut tmp = nparms - 15;
413 while tmp > j {
414 param[i] = Serial_parm(15, &mut prms);
415 j += 15;
416 i += 1;
417 }
418 tmp = nparms - j;
419 param[i] = Serial_parm(tmp, &mut prms);
420 shift = 15 - tmp;
421 param[i] = shl_int16(param[i], shift);
422 } else {
423 for k in 0..10 {
424 param[k] = Serial_parm(15, &mut prms);
425 }
426 param[10] = Serial_parm(15, &mut prms) & 0x61FF;
427 for k in 11..17 {
428 param[k] = Serial_parm(15, &mut prms);
429 }
430 param[17] = Serial_parm(15, &mut prms) & (0xE0FFu16 as i16);
431 for k in 18..24 {
432 param[k] = Serial_parm(15, &mut prms);
433 }
434 param[24] = Serial_parm(15, &mut prms) & 0x7F0F;
435 for k in 25..31 {
436 param[k] = Serial_parm(15, &mut prms);
437 }
438 let tmp = Serial_parm(8, &mut prms);
439 param[31] = shl_int16(tmp, 7);
440 i = 31;
441 shift = 0;
442 }
443 let cnt = i;
444 j = 0;
445 i = 0;
446 while i < cnt {
447 j = param[i] ^ dhf[i];
448 if j != 0 {
449 break;
450 }
451 i += 1;
452 }
453 let mut tmp: i16 = 0x7fff;
454 tmp >>= shift;
455 tmp = shl_int16(tmp, shift);
456 tmp = dhf[i] & tmp;
457 tmp = param[i] ^ tmp;
458 j |= tmp;
459 } else {
460 j = 1;
461 }
462 (j == 0) as i16
463}
464
465/// Port of `pvDecoder_AmrWb_homing_frame_test`.
466pub fn pvDecoder_AmrWb_homing_frame_test(input_frame: &[i16], mode: i16) -> i16 {
467 dhf_test(input_frame, mode as i32, AMR_WB_COMPRESSED[mode as usize])
468}
469
470/// Port of `pvDecoder_AmrWb_homing_frame_test_first`.
471pub fn pvDecoder_AmrWb_homing_frame_test_first(input_frame: &[i16], mode: i16) -> i16 {
472 dhf_test(
473 input_frame,
474 mode as i32,
475 prmnofsf.get(mode as usize).copied().unwrap_or(0),
476 )
477}