Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / scale_signal.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: scale_signal.cpp
35
36 ------------------------------------------------------------------------------
37  INPUT AND OUTPUT DEFINITIONS
38
39      int16 signal[],             (i/o) : signal to scale
40      int16 lg,                   (i)   : size of x[]
41      int16 exp                   (i)   : exponent: x = round(x << exp)
42
43 ------------------------------------------------------------------------------
44  FUNCTION DESCRIPTION
45
46    Scale signal to get maximum of dynamic range
47
48
49 ------------------------------------------------------------------------------
50  REQUIREMENTS
51
52
53 ------------------------------------------------------------------------------
54  REFERENCES
55
56 ------------------------------------------------------------------------------
57  PSEUDO-CODE
58
59 ------------------------------------------------------------------------------
60 */
61
62
63 /*----------------------------------------------------------------------------
64 ; INCLUDES
65 ----------------------------------------------------------------------------*/
66
67 #include "pv_amr_wb_type_defs.h"
68 #include "pvamrwbdecoder_basic_op.h"
69 #include "pvamrwbdecoder_acelp.h"
70
71 /*----------------------------------------------------------------------------
72 ; MACROS
73 ; Define module specific macros here
74 ----------------------------------------------------------------------------*/
75
76
77 /*----------------------------------------------------------------------------
78 ; DEFINES
79 ; Include all pre-processor statements here. Include conditional
80 ; compile variables also.
81 ----------------------------------------------------------------------------*/
82
83 /*----------------------------------------------------------------------------
84 ; LOCAL FUNCTION DEFINITIONS
85 ; Function Prototype declaration
86 ----------------------------------------------------------------------------*/
87
88 /*----------------------------------------------------------------------------
89 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
90 ; Variable declaration - defined here and used outside this module
91 ----------------------------------------------------------------------------*/
92
93 /*----------------------------------------------------------------------------
94 ; EXTERNAL FUNCTION REFERENCES
95 ; Declare functions defined elsewhere and referenced in this module
96 ----------------------------------------------------------------------------*/
97
98 /*----------------------------------------------------------------------------
99 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
100 ; Declare variables used in this module but defined elsewhere
101 ----------------------------------------------------------------------------*/
102
103 /*----------------------------------------------------------------------------
104 ; FUNCTION CODE
105 ----------------------------------------------------------------------------*/
106
107 void scale_signal(
108     int16 x[],              /* (i/o) : signal to scale               */
109     int16 lg,               /* (i)   : size of x[]                   */
110     int16 exp               /* (i)   : exponent: x = round(x << exp) */
111 )
112 {
113     int16 i;
114     int16 tmp;
115     int16 *pt_x;
116
117
118     int32 L_tmp;
119
120
121     if (exp > 0)
122     {
123         for (i = 0; i < lg; i++)
124         {
125             L_tmp = shl_int32(((int32)x[i] << 16), exp);       /* saturation can occur here */
126             x[i] = amr_wb_round(L_tmp);
127         }
128     }
129     else if (exp < 0)
130     {
131         exp = -exp;
132         exp &= 0xf;
133         tmp = (int16)(0x00008000 >> (16 - exp));
134         pt_x = x;
135
136         for (i = lg >> 1; i != 0; i--)
137         {
138             *(pt_x)   = add_int16(*(pt_x), tmp) >> exp;
139             pt_x++;
140             *(pt_x)   = add_int16(*(pt_x), tmp) >> exp;
141             pt_x++;
142         }
143
144     }
145     return;
146 }