Initialize Tizen 2.3
[external/opencore-amr.git] / opencore / codecs_v2 / audio / gsm_amr / amr_wb / dec / src / pvamrwbdecoder_acelp.h
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  Pathname: ./cpp/include/pvamrwbdecoder_acelp.h
35
36 ------------------------------------------------------------------------------
37  INCLUDE DESCRIPTION
38
39 ------------------------------------------------------------------------------
40 */
41
42 #ifndef PVAMRWBDECODER_ACELP_H
43 #define PVAMRWBDECODER_ACELP_H
44
45
46 /*----------------------------------------------------------------------------
47 ; INCLUDES
48 ----------------------------------------------------------------------------*/
49
50 #include "pv_amr_wb_type_defs.h"
51 #include "pvamrwbdecoder_mem_funcs.h"
52
53 #ifdef __cplusplus
54 extern "C"
55 {
56 #endif
57
58     /*-----------------------------------------------------------------*
59      *                        LPC prototypes                           *
60      *-----------------------------------------------------------------*/
61
62     void isf_extrapolation(int16 HfIsf[]);
63
64     void Init_Lagconc(int16 lag_hist[]);
65     void lagconceal(
66         int16 gain_hist[],                   /* (i) : Gain history     */
67         int16 lag_hist[],                    /* (i) : Subframe size         */
68         int16 * T0,
69         int16 * old_T0,
70         int16 * seed,
71         int16 unusable_frame
72     );
73
74     void agc2_amr_wb(
75         int16 * sig_in,                      /* input : postfilter input signal  */
76         int16 * sig_out,                     /* in/out: postfilter output signal */
77         int16 l_trm                          /* input : subframe size            */
78     );
79
80     void low_pass_filt_7k_init(int16 mem[]);
81     void low_pass_filt_7k(
82         int16 signal[],                      /* input:  signal                  */
83         int16 lg,                            /* input:  length of input         */
84         int16 mem[],                         /* in/out: memory (size=30)        */
85         int16 x[]
86     );
87
88     int16 median5(int16 x[]);
89
90     void Isp_Az(
91         int16 isp[],                         /* (i) Q15 : Immittance spectral pairs            */
92         int16 a[],                           /* (o) Q12 : predictor coefficients (order = M)   */
93         int16 m,
94         int16 adaptive_scaling               /* (i) 0   : adaptive scaling disabled */
95         /*     1   : adaptive scaling enabled  */
96     );
97     void Isf_isp(
98         int16 isf[],                         /* (i) Q15 : isf[m] normalized (range: 0.0<=val<=0.5) */
99         int16 isp[],                         /* (o) Q15 : isp[m] (range: -1<=val<1)                */
100         int16 m                              /* (i)     : LPC order                                */
101     );
102     void interpolate_isp(
103         int16 isp_old[],                     /* input : isps from past frame              */
104         int16 isp_new[],                     /* input : isps from present frame           */
105         const int16 frac[],                  /* input : fraction for 3 first subfr (Q15)  */
106         int16 Az[]                           /* output: LP coefficients in 4 subframes    */
107     );
108     void weight_amrwb_lpc(
109         int16 a[],                           /* (i) Q12 : a[m+1]  LPC coefficients             */
110         int16 ap[],                          /* (o) Q12 : Spectral expanded LPC coefficients   */
111         int16 gamma,                         /* (i) Q15 : Spectral expansion factor.           */
112         int16 m                              /* (i)     : LPC order.                           */
113     );
114
115
116     /*-----------------------------------------------------------------*
117      *                        isf quantizers                           *
118      *-----------------------------------------------------------------*/
119
120     void Disf_ns(
121         int16 * indice,                      /* input:  quantization indices                  */
122         int16 * isf_q                        /* input : ISF in the frequency domain (0..0.5)  */
123     );
124
125     void Dpisf_2s_46b(
126         int16 * indice,                      /* input:  quantization indices                       */
127         int16 * isf_q,                       /* output: quantized ISF in frequency domain (0..0.5) */
128         int16 * past_isfq,                   /* i/0   : past ISF quantizer                    */
129         int16 * isfold,                      /* input : past quantized ISF                    */
130         int16 * isf_buf,                     /* input : isf buffer                                                        */
131         int16 bfi,                           /* input : Bad frame indicator                   */
132         int16 enc_dec
133     );
134     void Dpisf_2s_36b(
135         int16 * indice,                      /* input:  quantization indices                       */
136         int16 * isf_q,                       /* output: quantized ISF in frequency domain (0..0.5) */
137         int16 * past_isfq,                   /* i/0   : past ISF quantizer                    */
138         int16 * isfold,                      /* input : past quantized ISF                    */
139         int16 * isf_buf,                     /* input : isf buffer                                                        */
140         int16 bfi,                           /* input : Bad frame indicator                   */
141         int16 enc_dec
142     );
143
144
145     void Reorder_isf(
146         int16 * isf,                         /* (i/o) Q15: ISF in the frequency domain (0..0.5) */
147         int16 min_dist,                      /* (i) Q15  : minimum distance to keep             */
148         int16 n                              /* (i)      : number of ISF                        */
149     );
150
151     /*-----------------------------------------------------------------*
152      *                       filter prototypes                         *
153      *-----------------------------------------------------------------*/
154
155     void oversamp_12k8_to_16k_init(
156         int16 mem[]                          /* output: memory (2*NB_COEF_UP) set to zeros  */
157     );
158     void oversamp_12k8_to_16k(
159         int16 sig12k8[],                     /* input:  signal to oversampling  */
160         int16 lg,                            /* input:  length of input         */
161         int16 sig16k[],                      /* output: oversampled signal      */
162         int16 mem[],                         /* in/out: memory (2*NB_COEF_UP)   */
163         int16 signal[]
164     );
165
166     void highpass_50Hz_at_12k8_init(int16 mem[]);
167     void highpass_50Hz_at_12k8(
168         int16 signal[],                      /* input/output signal */
169         int16 lg,                            /* lenght of signal    */
170         int16 mem[]                          /* filter memory [6]   */
171     );
172     void highpass_400Hz_at_12k8_init(int16 mem[]);
173     void highpass_400Hz_at_12k8(
174         int16 signal[],                      /* input/output signal */
175         int16 lg,                            /* lenght of signal    */
176         int16 mem[]                          /* filter memory [6]   */
177     );
178
179     void band_pass_6k_7k_init(int16 mem[]);
180     void band_pass_6k_7k(
181         int16 signal[],                      /* input:  signal                  */
182         int16 lg,                            /* input:  length of input         */
183         int16 mem[],                         /* in/out: memory (size=30)        */
184         int16 x[]
185     );
186
187
188     void preemph_amrwb_dec(
189         int16 x[],                           /* (i/o)   : input signal overwritten by the output */
190         int16 mu,                            /* (i) Q15 : preemphasis coefficient                */
191         int16 lg                             /* (i)     : lenght of filtering                    */
192     );
193
194     void deemphasis_32(
195         int16 x_hi[],                        /* (i)     : input signal (bit31..16) */
196         int16 x_lo[],                        /* (i)     : input signal (bit15..4)  */
197         int16 y[],                           /* (o)     : output signal (x16)      */
198         int16 mu,                            /* (i) Q15 : deemphasis factor        */
199         int16 L,                             /* (i)     : vector size              */
200         int16 * mem                          /* (i/o)   : memory (y[-1])           */
201     );
202
203
204     void wb_syn_filt(
205         int16 a[],                           /* (i) Q12 : a[m+1] prediction coefficients           */
206         int16 m,                             /* (i)     : order of LP filter                       */
207         int16 x[],                           /* (i)     : input signal                             */
208         int16 y[],                           /* (o)     : output signal                            */
209         int16 lg,                            /* (i)     : size of filtering                        */
210         int16 mem[],                         /* (i/o)   : memory associated with this filtering.   */
211         int16 update,                        /* (i)     : 0=no update, 1=update of memory.         */
212         int16 y_buf[]
213     );
214     void Syn_filt_32(
215         int16 a[],                           /* (i) Q12 : a[m+1] prediction coefficients */
216         int16 m,                             /* (i)     : order of LP filter             */
217         int16 exc[],                         /* (i) Qnew: excitation (exc[i] >> Qnew)    */
218         int16 Qnew,                          /* (i)     : exc scaling = 0(min) to 8(max) */
219         int16 sig_hi[],                      /* (o) /16 : synthesis high                 */
220         int16 sig_lo[],                      /* (o) /16 : synthesis low                  */
221         int16 lg                             /* (i)     : size of filtering              */
222     );
223
224     /*-----------------------------------------------------------------*
225      *                       pitch prototypes                          *
226      *-----------------------------------------------------------------*/
227
228
229     void Pred_lt4(
230         int16 exc[],                         /* in/out: excitation buffer */
231         int16 T0,                            /* input : integer pitch lag */
232         int16 frac,                          /* input : fraction of lag   */
233         int16 L_subfr                        /* input : subframe size     */
234     );
235
236     /*-----------------------------------------------------------------*
237      *                       gain prototypes                           *
238      *-----------------------------------------------------------------*/
239
240
241     void dec_gain2_amr_wb_init(
242         int16 * mem                          /* output  : memory (4 words)      */
243     );
244     void dec_gain2_amr_wb(
245         int16 index,                         /* (i)     :index of quantization.       */
246         int16 nbits,                         /* (i)     : number of bits (6 or 7)     */
247         int16 code[],                        /* (i) Q9  :Innovative vector.           */
248         int16 L_subfr,                       /* (i)     :Subframe lenght.             */
249         int16 * gain_pit,                    /* (o) Q14 :Pitch gain.                  */
250         int32 * gain_cod,                    /* (o) Q16 :Code gain.                   */
251         int16 bfi,                           /* (i)     :bad frame indicator          */
252         int16 prev_bfi,                      /* (i) : Previous BF indicator      */
253         int16 state,                         /* (i) : State of BFH               */
254         int16 unusable_frame,                /* (i) : UF indicator            */
255         int16 vad_hist,                      /* (i)         :number of non-speech frames  */
256         int16 * mem                          /* (i/o)   : memory (4 words)      */
257     );
258
259     /*-----------------------------------------------------------------*
260      *                       acelp prototypes                          *
261      *-----------------------------------------------------------------*/
262
263     void dec_acelp_2p_in_64(
264         int16 index,                         /* (i) :    12 bits index                                  */
265         int16 code[]                         /* (o) :Q9  algebraic (fixed) codebook excitation          */
266     );
267
268     void dec_acelp_4p_in_64(
269         int16 index[],                       /* (i) : index (20): 5+5+5+5 = 20 bits.                 */
270         /* (i) : index (36): 9+9+9+9 = 36 bits.                 */
271         /* (i) : index (44): 13+9+13+9 = 44 bits.               */
272         /* (i) : index (52): 13+13+13+13 = 52 bits.             */
273         /* (i) : index (64): 2+2+2+2+14+14+14+14 = 64 bits.     */
274         /* (i) : index (72): 10+2+10+2+10+14+10+14 = 72 bits.   */
275         /* (i) : index (88): 11+11+11+11+11+11+11+11 = 88 bits. */
276         int16 nbbits,                        /* (i) : 20, 36, 44, 52, 64, 72 or 88 bits              */
277         int16 code[]                         /* (o) Q9: algebraic (fixed) codebook excitation        */
278     );
279     void Pit_shrp(
280         int16 * x,                           /* in/out: impulse response (or algebraic code) */
281         int16 pit_lag,                       /* input : pitch lag                            */
282         int16 sharp,                         /* input : pitch sharpening factor (Q15)        */
283         int16 L_subfr                        /* input : subframe size                        */
284     );
285
286
287     /*-----------------------------------------------------------------*
288      *                        others prototypes                        *
289      *-----------------------------------------------------------------*/
290
291     int16 voice_factor(                       /* (o) Q15 : factor (-1=unvoiced to 1=voiced) */
292         int16 exc[],                         /* (i) Q_exc: pitch excitation                */
293         int16 Q_exc,                         /* (i)     : exc format                       */
294         int16 gain_pit,                      /* (i) Q14 : gain of pitch                    */
295         int16 code[],                        /* (i) Q9  : Fixed codebook excitation        */
296         int16 gain_code,                     /* (i) Q0  : gain of code                     */
297         int16 L_subfr                        /* (i)     : subframe length                  */
298     );
299
300     void scale_signal(
301         int16 x[],                           /* (i/o) : signal to scale               */
302         int16 lg,                            /* (i)   : size of x[]                   */
303         int16 exp                            /* (i)   : exponent: x = round(x << exp) */
304     );
305
306     int16 noise_gen_amrwb(int16 * seed);
307
308
309     void phase_dispersion(
310         int16 gain_code,                     /* (i) Q0  : gain of code             */
311         int16 gain_pit,                      /* (i) Q14 : gain of pitch            */
312         int16 code[],                        /* (i/o)   : code vector              */
313         int16 mode,                          /* (i)     : level, 0=hi, 1=lo, 2=off */
314         int16 disp_mem[],                    /* (i/o)   :  memory (size = 8) */
315         int16 ScratchMem[]
316     );
317
318 #ifdef __cplusplus
319 }
320 #endif
321
322 #endif  /* ACELP_H */
323