Tizen 2.0 Release
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / lag_wind.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
32
33
34  Filename: lag_wind.cpp
35
36 ------------------------------------------------------------------------------
37 */
38
39 /*----------------------------------------------------------------------------
40 ; INCLUDES
41 ----------------------------------------------------------------------------*/
42 #include "lag_wind.h"
43 #include "lag_wind_tab.h"
44 #include "basic_op.h"
45
46 /*----------------------------------------------------------------------------
47 ; MACROS
48 ; Define module specific macros here
49 ----------------------------------------------------------------------------*/
50
51
52 /*----------------------------------------------------------------------------
53 ; DEFINES
54 ; Include all pre-processor statements here. Include conditional
55 ; compile variables also.
56 ----------------------------------------------------------------------------*/
57
58
59 /*----------------------------------------------------------------------------
60 ; LOCAL FUNCTION DEFINITIONS
61 ; Function Prototype declaration
62 ----------------------------------------------------------------------------*/
63
64
65 /*----------------------------------------------------------------------------
66 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
67 ; Variable declaration - defined here and used outside this module
68 ----------------------------------------------------------------------------*/
69
70
71 /*
72 ------------------------------------------------------------------------------
73  FUNCTION NAME: lag_wind
74 ------------------------------------------------------------------------------
75  INPUT AND OUTPUT DEFINITIONS
76
77  Inputs:
78     m = LPC order of type Word16
79     r_h[] = pointer to autocorrelations (msb) of type Word16
80     r_l[] = pointer to autocorrelations (lsb) of type Word16
81     pOverflow = pointer to overflow flag
82
83  Outputs:
84     None
85
86  Returns:
87     None
88
89  Global Variables Used:
90     None.
91
92  Local Variables Needed:
93     None.
94
95 ------------------------------------------------------------------------------
96  FUNCTION DESCRIPTION
97
98       File             : lag_wind.c
99       Purpose          : Lag windowing of autocorrelations.
100
101     FUNCTION:  Lag_window()
102
103     PURPOSE:  Lag windowing of autocorrelations.
104
105     DESCRIPTION:
106           r[i] = r[i]*lag_wind[i],   i=1,...,10
107
108       r[i] and lag_wind[i] are in special double precision format.
109       See "oper_32b.c" for the format.
110
111 ------------------------------------------------------------------------------
112  REQUIREMENTS
113
114  None.
115
116 ------------------------------------------------------------------------------
117  REFERENCES
118
119  lag_wind.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
120
121 ------------------------------------------------------------------------------
122  PSEUDO-CODE
123
124     Word16 i;
125     Word32 x;
126
127     for (i = 1; i <= m; i++)
128     {
129         x = Mpy_32 (r_h[i], r_l[i], lag_h[i - 1], lag_l[i - 1], pOverflow);
130         L_Extract (x, &r_h[i], &r_l[i], pOverflow);
131     }
132     return;
133
134 ------------------------------------------------------------------------------
135  CAUTION [optional]
136  [State any special notes, constraints or cautions for users of this function]
137
138 ------------------------------------------------------------------------------
139 */
140 void Lag_window(
141     Word16 m,           /* (i)     : LPC order                        */
142     Word16 r_h[],       /* (i/o)   : Autocorrelations  (msb)          */
143     Word16 r_l[],       /* (i/o)   : Autocorrelations  (lsb)          */
144     Flag   *pOverflow
145 )
146 {
147     Word16 i;
148     Word32 x;
149     const Word16 *p_lag_h = &lag_h[0];
150     const Word16 *p_lag_l = &lag_l[0];
151     Word16 *p_r_h = &r_h[1];
152     Word16 *p_r_l = &r_l[1];
153
154     for (i = m; i != 0 ; i--)
155     {
156         x = Mpy_32(*(p_r_h), *(p_r_l), *(p_lag_h++), *(p_lag_l++), pOverflow);
157         *(p_r_h) = (Word16)(x >> 16);
158         *(p_r_l++) = (x >> 1) - (*(p_r_h++) << 15);
159     }
160
161     return;
162 }
163