Git init
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_nb / enc / src / pre_big.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: pre_big.cpp
35
36 ------------------------------------------------------------------------------
37  MODULE DESCRIPTION
38
39     Big subframe (2 subframes) preprocessing
40 ------------------------------------------------------------------------------
41 */
42
43 /*----------------------------------------------------------------------------
44 ; INCLUDES
45 ----------------------------------------------------------------------------*/
46 #include "pre_big.h"
47 #include "typedef.h"
48 #include "basic_op.h"
49 #include "syn_filt.h"
50 #include "weight_a.h"
51 #include "residu.h"
52 #include "cnst.h"
53
54 /*----------------------------------------------------------------------------
55 ; MACROS
56 ; Define module specific macros here
57 ----------------------------------------------------------------------------*/
58
59 /*----------------------------------------------------------------------------
60 ; DEFINES
61 ; Include all pre-processor statements here. Include conditional
62 ; compile variables also.
63 ----------------------------------------------------------------------------*/
64
65 /*----------------------------------------------------------------------------
66 ; LOCAL FUNCTION DEFINITIONS
67 ; Function Prototype declaration
68 ----------------------------------------------------------------------------*/
69
70 /*----------------------------------------------------------------------------
71 ; LOCAL VARIABLE DEFINITIONS
72 ; Variable declaration - defined here and used outside this module
73 ----------------------------------------------------------------------------*/
74
75 /*
76 ------------------------------------------------------------------------------
77  FUNCTION NAME: pre_big
78 ------------------------------------------------------------------------------
79  INPUT AND OUTPUT DEFINITIONS
80
81  Inputs:
82     mode = enum Mode -- coder mode
83     gamma1 = array of type const Word16 -- spectral exp. factor 1
84     gamma1_12k2 = array of type const Word16 -- spectral exp. factor 1 for EFR
85     gamma2 = array of type const Word16 -- spectral exp. factor 2
86     A_t = array of type Word16 -- A(z) unquantized, for 4 subframes, Q12
87     frameOffset = Word16 -- Start position in speech vector,   Q0
88     speech[] = array of type Word16 -- speech,                            Q0
89
90  Outputs:
91     mem_w = array of type Word16 -- synthesis filter memory state,     Q0
92     wsp   = array of type Word16 -- weighted speech                    Q0
93     pOverflow = pointer of type Flag -- overflow indicator
94
95  Returns:
96     None
97
98  Global Variables Used:
99     None
100
101  Local Variables Needed:
102     None
103
104 ------------------------------------------------------------------------------
105  FUNCTION DESCRIPTION
106
107
108 ------------------------------------------------------------------------------
109  REQUIREMENTS
110
111  None
112
113 ------------------------------------------------------------------------------
114  REFERENCES
115
116  pre_big.c, UMTS GSM AMR speech codec, R99 - Version 3.2.0, March 2, 2001
117
118 ------------------------------------------------------------------------------
119  PSEUDO-CODE
120
121
122 ------------------------------------------------------------------------------
123  CAUTION [optional]
124  [State any special notes, constraints or cautions for users of this function]
125
126 ------------------------------------------------------------------------------
127 */
128
129 void pre_big(
130     enum Mode mode,            /* i  : coder mode                             */
131     const Word16 gamma1[],     /* i  : spectral exp. factor 1                 */
132     const Word16 gamma1_12k2[],/* i  : spectral exp. factor 1 for EFR         */
133     const Word16 gamma2[],     /* i  : spectral exp. factor 2                 */
134     Word16 A_t[],              /* i  : A(z) unquantized, for 4 subframes, Q12 */
135     Word16 frameOffset,        /* i  : Start position in speech vector,   Q0  */
136     Word16 speech[],           /* i  : speech,                            Q0  */
137     Word16 mem_w[],            /* i/o: synthesis filter memory state,     Q0  */
138     Word16 wsp[],              /* o  : weighted speech                    Q0  */
139     Flag   *pOverflow          /* o  : overflow indicator                     */
140 )
141 {
142     Word16 Ap1[MP1];            /* A(z) with spectral expansion         */
143     Word16 Ap2[MP1];            /* A(z) with spectral expansion         */
144     const Word16 *g1;           /* Pointer to correct gammma1 vector    */
145     Word16 aOffset;
146     Word16 i;
147
148     if (mode <= MR795)
149     {
150         g1 = gamma1;
151     }
152     else
153     {
154         g1 = gamma1_12k2;
155     }
156
157     if (frameOffset > 0)
158     {
159         aOffset = MP1 << 1;
160     }
161     else
162     {
163         aOffset = 0;
164     }
165
166     /* process two subframes (which form the "big" subframe) */
167     for (i = 0; i < 2; i++)
168     {
169         Weight_Ai(&A_t[aOffset], g1, Ap1);
170         Weight_Ai(&A_t[aOffset], gamma2, Ap2);
171         Residu(Ap1, &speech[frameOffset], &wsp[frameOffset], L_SUBFR);
172
173         Syn_filt(Ap2, &wsp[frameOffset], &wsp[frameOffset], L_SUBFR, mem_w, 1);
174
175         aOffset += MP1;
176
177         frameOffset += L_SUBFR;
178     }
179
180     return;
181 }