Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / common / src / weight_a.cpp
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  Filename: weight_a.cpp
32
33 ------------------------------------------------------------------------------
34 */
35
36 /*----------------------------------------------------------------------------
37 ; INCLUDES
38 ----------------------------------------------------------------------------*/
39 #include    "weight_a.h"
40 #include    "typedef.h"
41 #include    "cnst.h"
42
43 /*----------------------------------------------------------------------------
44 ; MACROS
45 ; Define module specific macros here
46 ----------------------------------------------------------------------------*/
47
48
49 /*----------------------------------------------------------------------------
50 ; DEFINES
51 ; Include all pre-processor statements here. Include conditional
52 ; compile variables also.
53 ----------------------------------------------------------------------------*/
54
55
56 /*----------------------------------------------------------------------------
57 ; LOCAL FUNCTION DEFINITIONS
58 ; Function Prototype declaration
59 ----------------------------------------------------------------------------*/
60
61
62 /*----------------------------------------------------------------------------
63 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
64 ; Variable declaration - defined here and used outside this module
65 ----------------------------------------------------------------------------*/
66
67
68 /*
69 ------------------------------------------------------------------------------
70  FUNCTION NAME: Weight_Ai
71 ------------------------------------------------------------------------------
72  INPUT AND OUTPUT DEFINITIONS
73
74  Inputs:
75     a = LPC coefficients (Word16)
76     fac = Spectral expansion factors (Word16)
77     a_exp = Spectral expanded LPC coefficients (Word16)
78
79  Outputs:
80     a_exp points to the updated spectral expanded LPC coefficients
81
82  Returns:
83     None.
84
85  Global Variables Used:
86     None.
87
88  Local Variables Needed:
89     None.
90
91 ------------------------------------------------------------------------------
92  FUNCTION DESCRIPTION
93
94  This function calculates the spectral expansion for the LP coefficients of
95  order M.
96     a_exp[i] = a[i] * fac[i-1]    ; i=1..M
97
98 ------------------------------------------------------------------------------
99  REQUIREMENTS
100
101  None.
102
103 ------------------------------------------------------------------------------
104  REFERENCES
105
106  weight_a.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
107
108 ------------------------------------------------------------------------------
109  PSEUDO-CODE
110
111 void Weight_Ai (
112     Word16 a[],         // (i)     : a[M+1]  LPC coefficients   (M=10)
113     const Word16 fac[], // (i)     : Spectral expansion factors.
114     Word16 a_exp[]      // (o)     : Spectral expanded LPC coefficients
115 )
116 {
117     Word16 i;
118     a_exp[0] = a[0];
119
120     for (i = 1; i <= M; i++)
121     {
122         a_exp[i] = pv_round (L_mult (a[i], fac[i - 1]));
123     }
124     return;
125 }
126
127 ------------------------------------------------------------------------------
128  CAUTION [optional]
129  [State any special notes, constraints or cautions for users of this function]
130
131 ------------------------------------------------------------------------------
132 */
133
134 OSCL_EXPORT_REF void Weight_Ai(
135     Word16 a[],         /* (i)   : a[M+1]  LPC coefficients   (M=10)    */
136     const Word16 fac[], /* (i)   : Spectral expansion factors.          */
137     Word16 a_exp[]      /* (o)   : Spectral expanded LPC coefficients   */
138 )
139 {
140     register Word16 i;
141
142     *(a_exp) = *(a);
143
144     for (i = M; i >= 1; i--)
145     {
146         a_exp += 1;
147         a += 1;
148         fac += 1;
149         *(a_exp) = (Word16)((((Word32) * (a)) * *(fac - 1)
150                              + 0x00004000L) >> 15);
151     }
152
153     return;
154 }
155