1 /* ------------------------------------------------------------------
2  * Copyright (C) 1998-2009 PacketVideo
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13  * express or implied.
14  * See the License for the specific language governing permissions
15  * and limitations under the License.
16  * -------------------------------------------------------------------
17  */
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
20 
21     3GPP TS 26.073
22     ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23     Available from http://www.3gpp.org
24 
25 (C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26 Permission to distribute, modify and use this file under the standard license
27 terms listed above has been obtained from the copyright holder.
28 ****************************************************************************************/
29 /*
30 
31  Pathname: .audio/gsm-amr/c/src/bitreorder.c
32 
33 ------------------------------------------------------------------------------
34  REVISION HISTORY
35 
36  Description: Changed file name to bitreorder_tab.c and .h. Also, updated the
37               module description.
38 
39  Description: Define "const Word16 *reorderBits[NUM_MODES-1]" as
40               "const Word16 *const reorderBits[NUM_MODES-1]".
41 
42  Description: Added #ifdef __cplusplus and removed "extern" from table
43               definition. Removed corresponding header file from Include
44               section.
45 
46  Description: Put "extern" back.
47 
48  Who:                       Date:
49  Description:
50 
51 ------------------------------------------------------------------------------
52  INPUT AND OUTPUT DEFINITIONS
53 
54  Inputs:
55     None
56 
57  Local Stores/Buffers/Pointers Needed:
58     None
59 
60  Global Stores/Buffers/Pointers Needed:
61     None
62 
63  Outputs:
64     None
65 
66  Pointers and Buffers Modified:
67     None
68 
69  Local Stores Modified:
70     None
71 
72  Global Stores Modified:
73     None
74 
75 ------------------------------------------------------------------------------
76  FUNCTION DESCRIPTION
77 
78  This function contains tables needed to reformat the encoded speech bits
79  into IF2, WMF, and ETS.
80 
81 ------------------------------------------------------------------------------
82  REQUIREMENTS
83 
84  None
85 
86 ------------------------------------------------------------------------------
87  REFERENCES
88 
89  AMR Speech Codec Frame Structure,
90  3GPP TS 26.101 version 4.1.0 Release 4, June 2001
91 
92 ------------------------------------------------------------------------------
93  PSEUDO-CODE
94 
95 
96 ------------------------------------------------------------------------------
97  RESOURCES USED
98    When the code is written for a specific target processor the
99      the resources used should be documented below.
100 
101  STACK USAGE: [stack count for this module] + [variable to represent
102           stack usage for each subroutine called]
103 
104      where: [stack usage variable] = stack usage for [subroutine
105          name] (see [filename].ext)
106 
107  DATA MEMORY USED: x words
108 
109  PROGRAM MEMORY USED: x words
110 
111  CLOCK CYCLES: [cycle count equation for this module] + [variable
112            used to represent cycle count for each subroutine
113            called]
114 
115      where: [cycle count variable] = cycle count for [subroutine
116         name] (see [filename].ext)
117 
118 ------------------------------------------------------------------------------
119 */
120 
121 
122 /*----------------------------------------------------------------------------
123 ; INCLUDES
124 ----------------------------------------------------------------------------*/
125 #include "typedef.h"
126 #include "bitreorder_tab.h"
127 
128 /*--------------------------------------------------------------------------*/
129 #ifdef __cplusplus
130 extern "C"
131 {
132 #endif
133 
134     /*----------------------------------------------------------------------------
135     ; MACROS
136     ; Define module specific macros here
137     ----------------------------------------------------------------------------*/
138 
139 
140     /*----------------------------------------------------------------------------
141     ; DEFINES
142     ; Include all pre-processor statements here. Include conditional
143     ; compile variables also.
144     ----------------------------------------------------------------------------*/
145 #define NUM_MODES           16
146 #define NUMBIT_MR475        95
147 #define NUMBIT_MR515       103
148 #define NUMBIT_MR59        118
149 #define NUMBIT_MR67        134
150 #define NUMBIT_MR74        148
151 #define NUMBIT_MR795       159
152 #define NUMBIT_MR102       204
153 #define NUMBIT_MR122       244
154 #define NUMBIT_AMR_SID      39
155 #define NUMBIT_GSMEFR_SID   43
156 #define NUMBIT_TDMAEFR_SID  38
157 #define NUMBIT_PDCEFR_SID   37
158 #define NUMBIT_UNUSED1       0
159 #define NUMBIT_UNUSED2       0
160 #define NUMBIT_UNUSED3       0
161 #define NUMBIT_NO_DATA       0
162 
163 #define MAX_NUM_BITS       244
164     /*----------------------------------------------------------------------------
165     ; LOCAL FUNCTION DEFINITIONS
166     ; Function Prototype declaration
167     ----------------------------------------------------------------------------*/
168 
169 
170     /*----------------------------------------------------------------------------
171     ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
172     ; Variable declaration - defined here and used outside this module
173     ----------------------------------------------------------------------------*/
174     /* number of parameters per modes (values must be <= MAX_PRM_SIZE!) */
175     const Word16 numOfBits[NUM_MODES] =
176     {
177         NUMBIT_MR475,
178         NUMBIT_MR515,
179         NUMBIT_MR59,
180         NUMBIT_MR67,
181         NUMBIT_MR74,
182         NUMBIT_MR795,
183         NUMBIT_MR102,
184         NUMBIT_MR122,
185         NUMBIT_AMR_SID,
186         NUMBIT_GSMEFR_SID,
187         NUMBIT_TDMAEFR_SID,
188         NUMBIT_PDCEFR_SID,
189         NUMBIT_UNUSED1,
190         NUMBIT_UNUSED2,
191         NUMBIT_UNUSED3,
192         NUMBIT_NO_DATA
193     };
194 
195     const Word16 reorderBits_MR475[NUMBIT_MR475] =
196     {
197         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
198         10, 11, 12, 13, 14, 15, 23, 24, 25, 26,
199         27, 28, 48, 49, 61, 62, 82, 83, 47, 46,
200         45, 44, 81, 80, 79, 78, 17, 18, 20, 22,
201         77, 76, 75, 74, 29, 30, 43, 42, 41, 40,
202         38, 39, 16, 19, 21, 50, 51, 59, 60, 63,
203         64, 72, 73, 84, 85, 93, 94, 32, 33, 35,
204         36, 53, 54, 56, 57, 66, 67, 69, 70, 87,
205         88, 90, 91, 34, 55, 68, 89, 37, 58, 71,
206         92, 31, 52, 65, 86
207     };
208 
209     const Word16 reorderBits_MR515[NUMBIT_MR515] =
210     {
211         7,  6,  5,  4,  3,  2,  1,  0, 15, 14,
212         13, 12, 11, 10,  9,  8, 23, 24, 25, 26,
213         27, 46, 65, 84, 45, 44, 43, 64, 63, 62,
214         83, 82, 81, 102, 101, 100, 42, 61, 80, 99,
215         28, 47, 66, 85, 18, 41, 60, 79, 98, 29,
216         48, 67, 17, 20, 22, 40, 59, 78, 97, 21,
217         30, 49, 68, 86, 19, 16, 87, 39, 38, 58,
218         57, 77, 35, 54, 73, 92, 76, 96, 95, 36,
219         55, 74, 93, 32, 51, 33, 52, 70, 71, 89,
220         90, 31, 50, 69, 88, 37, 56, 75, 94, 34,
221         53, 72, 91
222     };
223 
224     const Word16 reorderBits_MR59[NUMBIT_MR59] =
225     {
226         0,  1,  4,  5,  3,  6,  7,  2, 13, 15,
227         8,  9, 11, 12, 14, 10, 16, 28, 74, 29,
228         75, 27, 73, 26, 72, 30, 76, 51, 97, 50,
229         71, 96, 117, 31, 77, 52, 98, 49, 70, 95,
230         116, 53, 99, 32, 78, 33, 79, 48, 69, 94,
231         115, 47, 68, 93, 114, 46, 67, 92, 113, 19,
232         21, 23, 22, 18, 17, 20, 24, 111, 43, 89,
233         110, 64, 65, 44, 90, 25, 45, 66, 91, 112,
234         54, 100, 40, 61, 86, 107, 39, 60, 85, 106,
235         36, 57, 82, 103, 35, 56, 81, 102, 34, 55,
236         80, 101, 42, 63, 88, 109, 41, 62, 87, 108,
237         38, 59, 84, 105, 37, 58, 83, 104
238     };
239 
240     const Word16 reorderBits_MR67[NUMBIT_MR67] =
241     {
242         0,  1,  4,  3,  5,  6, 13,  7,  2,  8,
243         9, 11, 15, 12, 14, 10, 28, 82, 29, 83,
244         27, 81, 26, 80, 30, 84, 16, 55, 109, 56,
245         110, 31, 85, 57, 111, 48, 73, 102, 127, 32,
246         86, 51, 76, 105, 130, 52, 77, 106, 131, 58,
247         112, 33, 87, 19, 23, 53, 78, 107, 132, 21,
248         22, 18, 17, 20, 24, 25, 50, 75, 104, 129,
249         47, 72, 101, 126, 54, 79, 108, 133, 46, 71,
250         100, 125, 128, 103, 74, 49, 45, 70, 99, 124,
251         42, 67, 96, 121, 39, 64, 93, 118, 38, 63,
252         92, 117, 35, 60, 89, 114, 34, 59, 88, 113,
253         44, 69, 98, 123, 43, 68, 97, 122, 41, 66,
254         95, 120, 40, 65, 94, 119, 37, 62, 91, 116,
255         36, 61, 90, 115
256     };
257 
258     const Word16 reorderBits_MR74[NUMBIT_MR74] =
259     {
260         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
261         10, 11, 12, 13, 14, 15, 16, 26, 87, 27,
262         88, 28, 89, 29, 90, 30, 91, 51, 80, 112,
263         141, 52, 81, 113, 142, 54, 83, 115, 144, 55,
264         84, 116, 145, 58, 119, 59, 120, 21, 22, 23,
265         17, 18, 19, 31, 60, 92, 121, 56, 85, 117,
266         146, 20, 24, 25, 50, 79, 111, 140, 57, 86,
267         118, 147, 49, 78, 110, 139, 48, 77, 53, 82,
268         114, 143, 109, 138, 47, 76, 108, 137, 32, 33,
269         61, 62, 93, 94, 122, 123, 41, 42, 43, 44,
270         45, 46, 70, 71, 72, 73, 74, 75, 102, 103,
271         104, 105, 106, 107, 131, 132, 133, 134, 135, 136,
272         34, 63, 95, 124, 35, 64, 96, 125, 36, 65,
273         97, 126, 37, 66, 98, 127, 38, 67, 99, 128,
274         39, 68, 100, 129, 40, 69, 101, 130
275     };
276 
277     const Word16 reorderBits_MR795[NUMBIT_MR795] =
278     {
279         8,  7,  6,  5,  4,  3,  2, 14, 16,  9,
280         10, 12, 13, 15, 11, 17, 20, 22, 24, 23,
281         19, 18, 21, 56, 88, 122, 154, 57, 89, 123,
282         155, 58, 90, 124, 156, 52, 84, 118, 150, 53,
283         85, 119, 151, 27, 93, 28, 94, 29, 95, 30,
284         96, 31, 97, 61, 127, 62, 128, 63, 129, 59,
285         91, 125, 157, 32, 98, 64, 130,  1,  0, 25,
286         26, 33, 99, 34, 100, 65, 131, 66, 132, 54,
287         86, 120, 152, 60, 92, 126, 158, 55, 87, 121,
288         153, 117, 116, 115, 46, 78, 112, 144, 43, 75,
289         109, 141, 40, 72, 106, 138, 36, 68, 102, 134,
290         114, 149, 148, 147, 146, 83, 82, 81, 80, 51,
291         50, 49, 48, 47, 45, 44, 42, 39, 35, 79,
292         77, 76, 74, 71, 67, 113, 111, 110, 108, 105,
293         101, 145, 143, 142, 140, 137, 133, 41, 73, 107,
294         139, 37, 69, 103, 135, 38, 70, 104, 136
295     };
296 
297     const Word16 reorderBits_MR102[NUMBIT_MR102] =
298     {
299         7,  6,  5,  4,  3,  2,  1,  0, 16, 15,
300         14, 13, 12, 11, 10,  9,  8, 26, 27, 28,
301         29, 30, 31, 115, 116, 117, 118, 119, 120, 72,
302         73, 161, 162, 65, 68, 69, 108, 111, 112, 154,
303         157, 158, 197, 200, 201, 32, 33, 121, 122, 74,
304         75, 163, 164, 66, 109, 155, 198, 19, 23, 21,
305         22, 18, 17, 20, 24, 25, 37, 36, 35, 34,
306         80, 79, 78, 77, 126, 125, 124, 123, 169, 168,
307         167, 166, 70, 67, 71, 113, 110, 114, 159, 156,
308         160, 202, 199, 203, 76, 165, 81, 82, 92, 91,
309         93, 83, 95, 85, 84, 94, 101, 102, 96, 104,
310         86, 103, 87, 97, 127, 128, 138, 137, 139, 129,
311         141, 131, 130, 140, 147, 148, 142, 150, 132, 149,
312         133, 143, 170, 171, 181, 180, 182, 172, 184, 174,
313         173, 183, 190, 191, 185, 193, 175, 192, 176, 186,
314         38, 39, 49, 48, 50, 40, 52, 42, 41, 51,
315         58, 59, 53, 61, 43, 60, 44, 54, 194, 179,
316         189, 196, 177, 195, 178, 187, 188, 151, 136, 146,
317         153, 134, 152, 135, 144, 145, 105, 90, 100, 107,
318         88, 106, 89, 98, 99, 62, 47, 57, 64, 45,
319         63, 46, 55, 56
320     };
321 
322     const Word16 reorderBits_MR122[NUMBIT_MR122] =
323     {
324         0,  1,  2,  3,  4,  5,  6,  7,  8,  9,
325         10, 11, 12, 13, 14, 23, 15, 16, 17, 18,
326         19, 20, 21, 22, 24, 25, 26, 27, 28, 38,
327         141, 39, 142, 40, 143, 41, 144, 42, 145, 43,
328         146, 44, 147, 45, 148, 46, 149, 47, 97, 150,
329         200, 48, 98, 151, 201, 49, 99, 152, 202, 86,
330         136, 189, 239, 87, 137, 190, 240, 88, 138, 191,
331         241, 91, 194, 92, 195, 93, 196, 94, 197, 95,
332         198, 29, 30, 31, 32, 33, 34, 35, 50, 100,
333         153, 203, 89, 139, 192, 242, 51, 101, 154, 204,
334         55, 105, 158, 208, 90, 140, 193, 243, 59, 109,
335         162, 212, 63, 113, 166, 216, 67, 117, 170, 220,
336         36, 37, 54, 53, 52, 58, 57, 56, 62, 61,
337         60, 66, 65, 64, 70, 69, 68, 104, 103, 102,
338         108, 107, 106, 112, 111, 110, 116, 115, 114, 120,
339         119, 118, 157, 156, 155, 161, 160, 159, 165, 164,
340         163, 169, 168, 167, 173, 172, 171, 207, 206, 205,
341         211, 210, 209, 215, 214, 213, 219, 218, 217, 223,
342         222, 221, 73, 72, 71, 76, 75, 74, 79, 78,
343         77, 82, 81, 80, 85, 84, 83, 123, 122, 121,
344         126, 125, 124, 129, 128, 127, 132, 131, 130, 135,
345         134, 133, 176, 175, 174, 179, 178, 177, 182, 181,
346         180, 185, 184, 183, 188, 187, 186, 226, 225, 224,
347         229, 228, 227, 232, 231, 230, 235, 234, 233, 238,
348         237, 236, 96, 199
349     };
350 
351     /* overall table with all parameter sizes for all modes */
352     const Word16 * const reorderBits[NUM_MODES-1] =
353     {
354         reorderBits_MR475,
355         reorderBits_MR515,
356         reorderBits_MR59,
357         reorderBits_MR67,
358         reorderBits_MR74,
359         reorderBits_MR795,
360         reorderBits_MR102,
361         reorderBits_MR122
362     };
363 
364     /* Number of Frames (16-bit segments sent for each mode */
365     const Word16 numCompressedBytes[16] =
366     {
367         13, /*4.75*/
368         14, /*5.15*/
369         16, /*5.90*/
370         18, /*6.70*/
371         19, /*7.40*/
372         21, /*7.95*/
373         26, /*10.2*/
374         31, /*12.2*/
375         6, /*GsmAmr comfort noise*/
376         6, /*Gsm-Efr comfort noise*/
377         6, /*IS-641 comfort noise*/
378         6, /*Pdc-Efr comfort noise*/
379         0, /*future use*/
380         0, /*future use*/
381         0, /*future use*/
382         1  /*No transmission*/
383     };
384     /*----------------------------------------------------------------------------
385     ; EXTERNAL FUNCTION REFERENCES
386     ; Declare functions defined elsewhere and referenced in this module
387     ----------------------------------------------------------------------------*/
388 
389 
390     /*----------------------------------------------------------------------------
391     ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
392     ; Declare variables used in this module but defined elsewhere
393     ----------------------------------------------------------------------------*/
394 
395     /*--------------------------------------------------------------------------*/
396 #ifdef __cplusplus
397 }
398 #endif
399 
400 
401 /*----------------------------------------------------------------------------
402 ; FUNCTION CODE
403 ----------------------------------------------------------------------------*/
404 
405 /*----------------------------------------------------------------------------
406 ; Define all local variables
407 ----------------------------------------------------------------------------*/
408 
409 
410 /*----------------------------------------------------------------------------
411 ; Function body here
412 ----------------------------------------------------------------------------*/
413 
414 
415 /*----------------------------------------------------------------------------
416 ; Return nothing or data or data pointer
417 ----------------------------------------------------------------------------*/
418 
419 
420 
421 
422 
423