1b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/* ------------------------------------------------------------------
2b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * Copyright (C) 1998-2009 PacketVideo
3b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *
4b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * Licensed under the Apache License, Version 2.0 (the "License");
5b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * you may not use this file except in compliance with the License.
6b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * You may obtain a copy of the License at
7b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *
8b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *      http://www.apache.org/licenses/LICENSE-2.0
9b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber *
10b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * Unless required by applicable law or agreed to in writing, software
11b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * distributed under the License is distributed on an "AS IS" BASIS,
12b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * express or implied.
14b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * See the License for the specific language governing permissions
15b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * and limitations under the License.
16b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber * -------------------------------------------------------------------
17b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber */
18b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/****************************************************************************************
19b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas HuberPortions of this file are derived from the following 3GPP standard:
20b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
21b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    3GPP TS 26.073
22b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ANSI-C code for the Adaptive Multi-Rate (AMR) speech codec
23b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Available from http://www.3gpp.org
24b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
25b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber(C) 2004, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC)
26b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas HuberPermission to distribute, modify and use this file under the standard license
27b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huberterms listed above has been obtained from the copyright holder.
28b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber****************************************************************************************/
29b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*
30b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
31b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
32b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
33b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
34b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Pathname: ./audio/gsm-amr/c/src/qua_gain.c
35b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Functions:
36b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
37b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     Date: 02/05/2002
38b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
39b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
40b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber REVISION HISTORY
41b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
42b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description: Updated template used to PV coding template.
43b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Changed to accept the pOverflow flag for EPOC compatibility.
44b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
45b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description: Changed include files to lowercase.
46b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
47b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description:  Replaced OSCL mem type functions and eliminated include
48b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber               files that now are chosen by OSCL definitions
49b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
50b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description:  Replaced "int" and/or "char" with OSCL defined types.
51b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
52b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description: Added #ifdef __cplusplus around extern'ed table.
53b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
54b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Description:
55b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
56b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
57b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber MODULE DESCRIPTION
58b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
59b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Quantization of pitch and codebook gains.
60b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
61b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber*/
62b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
63b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*----------------------------------------------------------------------------
64b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber; INCLUDES
65b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber----------------------------------------------------------------------------*/
66b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "qua_gain.h"
67b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "typedef.h"
68b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "basic_op.h"
69b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
70b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "mode.h"
71b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "cnst.h"
72b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "pow2.h"
73b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#include "gc_pred.h"
74b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
75b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*--------------------------------------------------------------------------*/
76b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#ifdef __cplusplus
77b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huberextern "C"
78b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber{
79b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#endif
80b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
81b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
82b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; MACROS
83b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; Define module specific macros here
84b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
85b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
86b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
87b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; DEFINES
88b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; Include all pre-processor statements here. Include conditional
89b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; compile variables also.
90b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
91b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
92b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
93b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; LOCAL FUNCTION DEFINITIONS
94b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; Function Prototype declaration
95b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
96b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
97b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
98b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; LOCAL VARIABLE DEFINITIONS
99b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; Variable declaration - defined here and used outside this module
100b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
101b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
102b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*----------------------------------------------------------------------------
103b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
104b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ; Declare variables used in this module but defined elsewhere
105b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    ----------------------------------------------------------------------------*/
106b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    extern const Word16 table_gain_lowrates[];
107b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    extern const Word16 table_gain_highrates[];
108b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
109b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*--------------------------------------------------------------------------*/
110b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#ifdef __cplusplus
111b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber}
112b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber#endif
113b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
114b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber/*
115b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
116b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber FUNCTION NAME:
117b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
118b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber INPUT AND OUTPUT DEFINITIONS
119b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
120b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
121b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Inputs:
122b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    mode -- enum Mode -- AMR mode
123b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 exp_gcode0  -- Word16 -- predicted CB gain (exponent),       Q0
124b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 frac_gcode0 -- Word16 -- predicted CB gain (fraction),      Q15
125b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 frac_coeff -- Word16 Array -- energy coeff. (5), fraction part, Q15
126b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 exp_coeff  -- Word16 Array -- energy coeff. (5), exponent part,  Q0
127b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                                    (frac_coeff and exp_coeff computed in
128b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                                    calc_filt_energies())
129b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
130b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 gp_limit -- Word16 --  pitch gain limit
131b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
132b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Outputs:
133b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *gain_pit -- Pointer to Word16 -- Pitch gain,               Q14
134b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *gain_cod -- Pointer to Word16 -- Code gain,                Q1
135b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *qua_ener_MR122 -- Pointer to Word16 -- quantized energy error,  Q10
136b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                                                (for MR122 MA predictor update)
137b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *qua_ener -- Pointer to Word16 -- quantized energy error,        Q10
138b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                                                (for other MA predictor update)
139b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Flag   *pOverflow -- Pointer to Flag -- overflow indicator
140b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
141b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Returns:
142b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 -- index of quantization.
143b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
144b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Global Variables Used:
145b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
146b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
147b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber Local Variables Needed:
148b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    None
149b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
150b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
151b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber FUNCTION DESCRIPTION
152b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
153b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Quantization of pitch and codebook gains.
154b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
155b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber REQUIREMENTS
156b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
157b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber None
158b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
159b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
160b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber REFERENCES
161b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
162b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber qua_gain.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
163b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
164b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
165b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber PSEUDO-CODE
166b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
167b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
168b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
169b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber RESOURCES USED [optional]
170b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
171b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber When the code is written for a specific target processor the
172b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber the resources used should be documented below.
173b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
174b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber HEAP MEMORY USED: x bytes
175b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
176b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber STACK MEMORY USED: x bytes
177b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
178b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber CLOCK CYCLES: (cycle count equation for this function) + (variable
179b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                used to represent cycle count for each subroutine
180b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                called)
181b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     where: (cycle count variable) = cycle count for [subroutine
182b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                                     name]
183b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
184b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
185b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber CAUTION [optional]
186b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber [State any special notes, constraints or cautions for users of this function]
187b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
188b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber------------------------------------------------------------------------------
189b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber*/
190b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
191b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
192b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas HuberWord16
193b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas HuberQua_gain(                   /* o  : index of quantization.                 */
194b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    enum Mode mode,         /* i  : AMR mode                               */
195b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 exp_gcode0,      /* i  : predicted CB gain (exponent),      Q0  */
196b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 frac_gcode0,     /* i  : predicted CB gain (fraction),      Q15 */
197b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 frac_coeff[],    /* i  : energy coeff. (5), fraction part,  Q15 */
198b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 exp_coeff[],     /* i  : energy coeff. (5), exponent part,  Q0  */
199b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*      (frac_coeff and exp_coeff computed in  */
200b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*       calc_filt_energies())                 */
201b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 gp_limit,        /* i  : pitch gain limit                       */
202b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *gain_pit,       /* o  : Pitch gain,                        Q14 */
203b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *gain_cod,       /* o  : Code gain,                         Q1  */
204b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *qua_ener_MR122, /* o  : quantized energy error,            Q10 */
205b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*      (for MR122 MA predictor update)        */
206b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 *qua_ener,       /* o  : quantized energy error,            Q10 */
207b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*      (for other MA predictor update)        */
208b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Flag   *pOverflow       /* o  : overflow indicator                     */
209b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber)
210b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber{
211b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    const Word16 *p;
212b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 i;
213b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 j;
214b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 index = 0;
215b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 gcode0;
216b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 e_max;
217b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 temp;
218b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 exp_code;
219b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 g_pitch;
220b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 g2_pitch;
221b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 g_code;
222b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 g2_code;
223b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 g_pit_cod;
224b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 coeff[5];
225b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 coeff_lo[5];
226b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 exp_max[5];
227b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word32 L_tmp;
228b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word32 L_tmp2;
229b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word32 dist_min;
230b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    const Word16 *table_gain;
231b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    Word16 table_len;
232b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
233b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    if (mode == MR102 || mode == MR74 || mode == MR67)
234b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    {
235b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        table_len = VQ_SIZE_HIGHRATES;
236b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        table_gain = table_gain_highrates;
237b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    }
238b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    else
239b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    {
240b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        table_len = VQ_SIZE_LOWRATES;
241b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        table_gain = table_gain_lowrates;
242b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    }
243b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
244b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*-------------------------------------------------------------------*
245b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  predicted codebook gain                                          *
246b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  ~~~~~~~~~~~~~~~~~~~~~~~                                          *
247b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  gc0     = 2^exp_gcode0 + 2^frac_gcode0                           *
248b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                                                                   *
249b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  gcode0 (Q14) = 2^14*2^frac_gcode0 = gc0 * 2^(14-exp_gcode0)      *
250b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *-------------------------------------------------------------------*/
251b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
252b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    gcode0 = (Word16)(Pow2(14, frac_gcode0, pOverflow));
253b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
254b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*-------------------------------------------------------------------*
255b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  Scaling considerations:                                          *
256b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  ~~~~~~~~~~~~~~~~~~~~~~~                                          *
257b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *-------------------------------------------------------------------*/
258b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
259b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*
260b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     * The error energy (sum) to be minimized consists of five terms, t[0..4].
261b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
262b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                      t[0] =    gp^2  * <y1 y1>
263b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                      t[1] = -2*gp    * <xn y1>
264b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                      t[2] =    gc^2  * <y2 y2>
265b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                      t[3] = -2*gc    * <xn y2>
266b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                      t[4] =  2*gp*gc * <y1 y2>
267b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *
268b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     */
269b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
270b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /* determine the scaling exponent for g_code: ec = ec0 - 11 */
271b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    exp_code = sub(exp_gcode0, 11, pOverflow);
272b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
273b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /* calculate exp_max[i] = s[i]-1 */
274b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    exp_max[0] = sub(exp_coeff[0], 13, pOverflow);
275b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    exp_max[1] = sub(exp_coeff[1], 14, pOverflow);
276b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
277b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    temp = shl(exp_code, 1, pOverflow);
278b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    temp = add(15, temp, pOverflow);
279b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    exp_max[2] = add(exp_coeff[2], temp, pOverflow);
280b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
281b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    exp_max[3] = add(exp_coeff[3], exp_code, pOverflow);
282b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
283b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    temp = add(1, exp_code, pOverflow);
284b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    exp_max[4] = add(exp_coeff[4], temp, pOverflow);
285b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
286b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
287b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*-------------------------------------------------------------------*
288b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  Find maximum exponent:                                           *
289b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  ~~~~~~~~~~~~~~~~~~~~~~                                           *
290b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                                                                   *
291b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  For the sum operation, all terms must have the same scaling;     *
292b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  that scaling should be low enough to prevent overflow. There-    *
293b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  fore, the maximum scale is determined and all coefficients are   *
294b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  re-scaled:                                                       *
295b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                                                                   *
296b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *    e_max = max(exp_max[i]) + 1;                                   *
297b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *    e = exp_max[i]-e_max;         e <= 0!                          *
298b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *    c[i] = c[i]*2^e                                                *
299b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *-------------------------------------------------------------------*/
300b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
301b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    e_max = exp_max[0];
302b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    for (i = 1; i < 5; i++)
303b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    {
304b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        if (exp_max[i] > e_max)
305b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        {
306b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            e_max = exp_max[i];
307b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        }
308b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    }
309b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
310b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    e_max = add(e_max, 1, pOverflow);      /* To avoid overflow */
311b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
312b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    for (i = 0; i < 5; i++)
313b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    {
314b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        j = sub(e_max, exp_max[i], pOverflow);
315b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        L_tmp = L_deposit_h(frac_coeff[i]);
316b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        L_tmp = L_shr(L_tmp, j, pOverflow);
317b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        L_Extract(L_tmp, &coeff[i], &coeff_lo[i], pOverflow);
318b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    }
319b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
320b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
321b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*-------------------------------------------------------------------*
322b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  Codebook search:                                                 *
323b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  ~~~~~~~~~~~~~~~~                                                 *
324b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                                                                   *
325b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  For each pair (g_pitch, g_fac) in the table calculate the        *
326b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  terms t[0..4] and sum them up; the result is the mean squared    *
327b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  error for the quantized gains from the table. The index for the  *
328b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  minimum MSE is stored and finally used to retrieve the quantized *
329b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  gains                                                            *
330b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *-------------------------------------------------------------------*/
331b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
332b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /* start with "infinite" MSE */
333b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    dist_min = MAX_32;
334b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
335b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    p = &table_gain[0];
336b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
337b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    for (i = 0; i < table_len; i++)
338b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    {
339b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        g_pitch = *p++;
340b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        g_code = *p++;                   /* this is g_fac        */
341b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        p++;                             /* skip log2(g_fac)     */
342b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        p++;                             /* skip 20*log10(g_fac) */
343b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
344b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        if (g_pitch <= gp_limit)
345b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        {
346b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            g_code = mult(g_code, gcode0, pOverflow);
347b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            g2_pitch = mult(g_pitch, g_pitch, pOverflow);
348b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            g2_code = mult(g_code, g_code, pOverflow);
349b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            g_pit_cod = mult(g_code, g_pitch, pOverflow);
350b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
351b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp = Mpy_32_16(coeff[0], coeff_lo[0], g2_pitch, pOverflow);
352b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp2 = Mpy_32_16(coeff[1], coeff_lo[1], g_pitch, pOverflow);
353b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
354b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
355b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp2 = Mpy_32_16(coeff[2], coeff_lo[2], g2_code, pOverflow);
356b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
357b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
358b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp2 =  Mpy_32_16(coeff[3], coeff_lo[3], g_code, pOverflow);
359b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
360b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
361b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp2 = Mpy_32_16(coeff[4], coeff_lo[4], g_pit_cod, pOverflow);
362b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            L_tmp = L_add(L_tmp, L_tmp2, pOverflow);
363b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
364b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            /* store table index if MSE for this index is lower
365b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber               than the minimum MSE seen so far */
366b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            if (L_tmp < dist_min)
367b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            {
368b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                dist_min = L_tmp;
369b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber                index = i;
370b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber            }
371b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber        }
372b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    }
373b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
374b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*------------------------------------------------------------------*
375b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  read quantized gains and new values for MA predictor memories   *
376b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   *
377b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *------------------------------------------------------------------*/
378b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
379b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /* Read the quantized gains */
380b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    p = &table_gain[shl(index, 2, pOverflow)];
381b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    *gain_pit = *p++;
382b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    g_code = *p++;
383b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    *qua_ener_MR122 = *p++;
384b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    *qua_ener = *p;
385b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
386b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    /*------------------------------------------------------------------*
387b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  calculate final fixed codebook gain:                            *
388b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~                            *
389b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *                                                                  *
390b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *   gc = gc0 * g                                                   *
391b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber     *------------------------------------------------------------------*/
392b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
393b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    L_tmp = L_mult(g_code, gcode0, pOverflow);
394b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    temp  = sub(10, exp_gcode0, pOverflow);
395b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    L_tmp = L_shr(L_tmp, temp, pOverflow);
396b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
397b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    *gain_cod = extract_h(L_tmp);
398b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber
399b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber    return index;
400b841f14f8e51f2365945281fbfa54ef6a1b1b5a6Andreas Huber}
401