1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
25 (C) 2007, 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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Filename: homing_amr_wb_dec.cpp
36 ------------------------------------------------------------------------------
40 INPUT AND OUTPUT DEFINITIONS
43 int16 input_frame[], 16-bit input frame
44 int16 mode 16-bit mode
45 int16 nparms 16-bit number of parameters
47 Int16 i number of leading zeros on x
50 ------------------------------------------------------------------------------
53 Performs the homing routines
55 int16 dhf_test(int16 input_frame[], int16 mode, int16 nparms)
56 int16 decoder_homing_frame_test(int16 input_frame[], int16 mode)
57 int16 decoder_homing_frame_test_first(int16 input_frame[], int16 mode)
59 ------------------------------------------------------------------------------
63 ------------------------------------------------------------------------------
66 ------------------------------------------------------------------------------
69 ------------------------------------------------------------------------------
73 /*----------------------------------------------------------------------------
75 ----------------------------------------------------------------------------*/
77 #include "pv_amr_wb_type_defs.h"
78 #include "pvamrwbdecoder_cnst.h"
79 #include "pvamrwbdecoder.h"
80 #include "pvamrwbdecoder_basic_op.h"
81 #include "get_amr_wb_bits.h"
82 #include "pvamrwbdecoder_api.h"
83 #include "pvamrwbdecoder.h"
85 /*----------------------------------------------------------------------------
87 ; Define module specific macros here
88 ----------------------------------------------------------------------------*/
91 /*----------------------------------------------------------------------------
93 ; Include all pre-processor statements here. Include conditional
94 ; compile variables also.
95 ----------------------------------------------------------------------------*/
96 #define DHF_PARMS_MAX 32 /* homing frame pattern */
97 #define NUM_OF_SPMODES 9
100 #define PRMN_7k NBBITS_7k/PRML + 1
101 #define PRMN_9k NBBITS_9k/PRML + 1
102 #define PRMN_12k NBBITS_12k/PRML + 1
103 #define PRMN_14k NBBITS_14k/PRML + 1
104 #define PRMN_16k NBBITS_16k/PRML + 1
105 #define PRMN_18k NBBITS_18k/PRML + 1
106 #define PRMN_20k NBBITS_20k/PRML + 1
107 #define PRMN_23k NBBITS_23k/PRML + 1
108 #define PRMN_24k NBBITS_24k/PRML + 1
110 /*----------------------------------------------------------------------------
111 ; LOCAL FUNCTION DEFINITIONS
112 ; Function Prototype declaration
113 ----------------------------------------------------------------------------*/
119 int16 dhf_test(int16 input_frame[], int32 mode, int16 nparms);
125 /*----------------------------------------------------------------------------
126 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
127 ; Variable declaration - defined here and used outside this module
128 ----------------------------------------------------------------------------*/
129 static const int16 prmnofsf[NUM_OF_SPMODES] =
137 const int16 dfh_M7k[PRMN_7k] =
139 3168, 29954, 29213, 16121,
140 64, 13440, 30624, 16430,
144 const int16 dfh_M9k[PRMN_9k] =
146 3168, 31665, 9943, 9123,
147 15599, 4358, 20248, 2048,
148 17040, 27787, 16816, 13888
151 const int16 dfh_M12k[PRMN_12k] =
153 3168, 31665, 9943, 9128,
154 3647, 8129, 30930, 27926,
155 18880, 12319, 496, 1042,
156 4061, 20446, 25629, 28069,
160 const int16 dfh_M14k[PRMN_14k] =
162 3168, 31665, 9943, 9131,
163 24815, 655, 26616, 26764,
164 7238, 19136, 6144, 88,
165 4158, 25733, 30567, 30494,
169 const int16 dfh_M16k[PRMN_16k] =
171 3168, 31665, 9943, 9131,
172 24815, 700, 3824, 7271,
173 26400, 9528, 6594, 26112,
174 108, 2068, 12867, 16317,
175 23035, 24632, 7528, 1752,
179 const int16 dfh_M18k[PRMN_18k] =
181 3168, 31665, 9943, 9135,
182 14787, 14423, 30477, 24927,
183 25345, 30154, 916, 5728,
184 18978, 2048, 528, 16449,
185 2436, 3581, 23527, 29479,
186 8237, 16810, 27091, 19052,
190 const int16 dfh_M20k[PRMN_20k] =
192 3168, 31665, 9943, 9129,
193 8637, 31807, 24646, 736,
194 28643, 2977, 2566, 25564,
195 12930, 13960, 2048, 834,
196 3270, 4100, 26920, 16237,
197 31227, 17667, 15059, 20589,
201 const int16 dfh_M23k[PRMN_23k] =
203 3168, 31665, 9943, 9132,
204 16748, 3202, 28179, 16317,
205 30590, 15857, 19960, 8818,
206 21711, 21538, 4260, 16690,
207 20224, 3666, 4194, 9497,
208 16320, 15388, 5755, 31551,
209 14080, 3574, 15932, 50,
213 const int16 dfh_M24k[PRMN_24k] =
215 3168, 31665, 9943, 9134,
216 24776, 5857, 18475, 28535,
217 29662, 14321, 16725, 4396,
218 29353, 10003, 17068, 20504,
220 28863, 24774, 9709, 26043,
221 7941, 27649, 13965, 15236,
222 18026, 22047, 16681, 3968
226 /*----------------------------------------------------------------------------
227 ; EXTERNAL FUNCTION REFERENCES
228 ; Declare functions defined elsewhere and referenced in this module
229 ----------------------------------------------------------------------------*/
231 /*----------------------------------------------------------------------------
232 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
233 ; Declare variables used in this module but defined elsewhere
234 ----------------------------------------------------------------------------*/
236 /*----------------------------------------------------------------------------
238 ----------------------------------------------------------------------------*/
240 int16 dhf_test(int16 input_frame[], int32 mode, int16 nparms)
242 int16 i, j, tmp, shift;
243 int16 param[DHF_PARMS_MAX];
246 /* overall table with the parameters of the
247 decoder homing frames for all modes */
269 if (mode != MODE_24k)
271 /* convert the received serial bits */
275 param[i] = Serial_parm(15, &prms);
280 param[i] = Serial_parm(tmp, &prms);
282 param[i] = shl_int16(param[i], shift);
286 /*If mode is 23.85Kbit/s, remove high band energy bits */
287 for (i = 0; i < 10; i++)
289 param[i] = Serial_parm(15, &prms);
291 param[10] = Serial_parm(15, &prms) & 0x61FF;
293 for (i = 11; i < 17; i++)
295 param[i] = Serial_parm(15, &prms);
297 param[17] = Serial_parm(15, &prms) & 0xE0FF;
299 for (i = 18; i < 24; i++)
301 param[i] = Serial_parm(15, &prms);
303 param[24] = Serial_parm(15, &prms) & 0x7F0F;
305 for (i = 25; i < 31; i++)
307 param[i] = Serial_parm(15, &prms);
310 tmp = Serial_parm(8, &prms);
311 param[31] = shl_int16(tmp, 7);
315 /* check if the parameters matches the parameters of the corresponding decoder homing frame */
318 for (i = 0; i < tmp; i++)
320 j = (param[i] ^ dhf[mode][i]);
328 tmp = shl_int16(tmp, shift);
329 tmp = (dhf[mode][i] & tmp);
330 tmp = (param[i] ^ tmp);
331 j = (int16)(j | tmp);
342 /*----------------------------------------------------------------------------
344 ----------------------------------------------------------------------------*/
347 int16 pvDecoder_AmrWb_homing_frame_test(int16 input_frame[], int16 mode)
349 /* perform test for COMPLETE parameter frame */
350 return dhf_test(input_frame, mode, AMR_WB_COMPRESSED[mode]);
353 /*----------------------------------------------------------------------------
355 ----------------------------------------------------------------------------*/
358 int16 pvDecoder_AmrWb_homing_frame_test_first(int16 input_frame[], int16 mode)
360 /* perform test for FIRST SUBFRAME of parameter frame ONLY */
361 return dhf_test(input_frame, mode, prmnofsf[mode]);