Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / deemphasis_32.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.173
22     ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23     Available from http://www.3gpp.org
24
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 ****************************************************************************************/
29 /*
30 ------------------------------------------------------------------------------
31
32
33
34  Filename: deemphasis_32.cpp
35
36 ------------------------------------------------------------------------------
37  INPUT AND OUTPUT DEFINITIONS
38
39      int16 x_hi[],               (i)     : input signal (bit31..16)
40      int16 x_lo[],               (i)     : input signal (bit15..4)
41      int16 y[],                  (o)     : output signal (x16)
42      int16 mu,                   (i) Q15 : deemphasis factor
43      int16 L,                    (i)     : vector size
44      int16 * mem                 (i/o)   : memory (y[-1])
45
46 ------------------------------------------------------------------------------
47  FUNCTION DESCRIPTION
48
49     32-bits filtering through 1/(1-mu z^-1)
50
51 ------------------------------------------------------------------------------
52  REQUIREMENTS
53
54
55 ------------------------------------------------------------------------------
56  REFERENCES
57
58 ------------------------------------------------------------------------------
59  PSEUDO-CODE
60
61     Deemphasis H(z) = 1/(1 - 0.68z^(-1))   where mu = 0.67999 in Q15
62
63 ------------------------------------------------------------------------------
64 */
65
66
67 /*----------------------------------------------------------------------------
68 ; INCLUDES
69 ----------------------------------------------------------------------------*/
70
71 #include "pv_amr_wb_type_defs.h"
72 #include "pvamrwbdecoder_basic_op.h"
73 #include "pvamrwb_math_op.h"
74 #include "pvamrwbdecoder_acelp.h"
75
76 /*----------------------------------------------------------------------------
77 ; MACROS
78 ; Define module specific macros here
79 ----------------------------------------------------------------------------*/
80
81
82 /*----------------------------------------------------------------------------
83 ; DEFINES
84 ; Include all pre-processor statements here. Include conditional
85 ; compile variables also.
86 ----------------------------------------------------------------------------*/
87
88 /*----------------------------------------------------------------------------
89 ; LOCAL FUNCTION DEFINITIONS
90 ; Function Prototype declaration
91 ----------------------------------------------------------------------------*/
92
93 /*----------------------------------------------------------------------------
94 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
95 ; Variable declaration - defined here and used outside this module
96 ----------------------------------------------------------------------------*/
97
98 /*----------------------------------------------------------------------------
99 ; EXTERNAL FUNCTION REFERENCES
100 ; Declare functions defined elsewhere and referenced in this module
101 ----------------------------------------------------------------------------*/
102
103 /*----------------------------------------------------------------------------
104 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
105 ; Declare variables used in this module but defined elsewhere
106 ----------------------------------------------------------------------------*/
107
108 /*----------------------------------------------------------------------------
109 ; FUNCTION CODE
110 ----------------------------------------------------------------------------*/
111
112 void deemphasis_32(
113     int16 x_hi[],                        /* (i)     : input signal (bit31..16) */
114     int16 x_lo[],                        /* (i)     : input signal (bit15..4)  */
115     int16 y[],                           /* (o)     : output signal (x16)      */
116     int16 mu,                            /* (i) Q15 : deemphasis factor        */
117     int16 L,                             /* (i)     : vector size              */
118     int16 * mem                          /* (i/o)   : memory (y[-1])           */
119 )
120 {
121     int16 i;
122     int32 L_tmp;
123     int16 lo, hi;
124
125     L_tmp  = ((int32)x_hi[0]) << 16;
126     L_tmp += ((int32)x_lo[0]) << 4;
127     L_tmp  = shl_int32(L_tmp, 3);
128
129     L_tmp = fxp_mac_16by16(*mem, mu, L_tmp),
130
131             L_tmp = shl_int32(L_tmp, 1);               /* saturation can occur here */
132     y[0] = amr_wb_round(L_tmp);
133
134     lo = x_lo[1];
135     hi = x_hi[1];
136     for (i = 1; i < L - 1; i++)
137     {
138         L_tmp  = ((int32)hi) << 16;
139         L_tmp += ((int32)lo) << 4;
140         L_tmp  = shl_int32(L_tmp, 3);
141         L_tmp  = fxp_mac_16by16(y[i - 1], mu, L_tmp),
142                  L_tmp  = shl_int32(L_tmp, 1);           /* saturation can occur here */
143         y[i]   = amr_wb_round(L_tmp);
144         lo     = x_lo[i+1];
145         hi     = x_hi[i+1];
146     }
147     L_tmp  = ((int32)hi) << 16;
148     L_tmp += ((int32)lo) << 4;
149     L_tmp  = shl_int32(L_tmp, 3);
150     L_tmp  = fxp_mac_16by16(y[i - 1], mu, L_tmp),
151              L_tmp  = shl_int32(L_tmp, 1);           /* saturation can occur here */
152     y[i]   = amr_wb_round(L_tmp);
153
154     *mem = y[L - 1];
155
156     return;
157 }
158