1 /* ------------------------------------------------------------------
2 * Copyright (C) 1998-2009 PacketVideo
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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
14 * See the License for the specific language governing permissions
15 * and limitations under the License.
16 * -------------------------------------------------------------------
18 /****************************************************************************************
19 Portions of this file are derived from the following 3GPP standard:
22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec
23 Available from http://www.3gpp.org
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 ****************************************************************************************/
30 ------------------------------------------------------------------------------
34 Pathname: ./cpp/include/pvamrwbdecoder_acelp.h
36 ------------------------------------------------------------------------------
39 ------------------------------------------------------------------------------
42 #ifndef PVAMRWBDECODER_ACELP_H
43 #define PVAMRWBDECODER_ACELP_H
46 /*----------------------------------------------------------------------------
48 ----------------------------------------------------------------------------*/
50 #include "pv_amr_wb_type_defs.h"
51 #include "pvamrwbdecoder_mem_funcs.h"
58 /*-----------------------------------------------------------------*
60 *-----------------------------------------------------------------*/
62 void isf_extrapolation(int16 HfIsf[]);
64 void Init_Lagconc(int16 lag_hist[]);
66 int16 gain_hist[], /* (i) : Gain history */
67 int16 lag_hist[], /* (i) : Subframe size */
75 int16 * sig_in, /* input : postfilter input signal */
76 int16 * sig_out, /* in/out: postfilter output signal */
77 int16 l_trm /* input : subframe size */
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) */
88 int16 median5(int16 x[]);
91 int16 isp[], /* (i) Q15 : Immittance spectral pairs */
92 int16 a[], /* (o) Q12 : predictor coefficients (order = M) */
94 int16 adaptive_scaling /* (i) 0 : adaptive scaling disabled */
95 /* 1 : adaptive scaling enabled */
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 */
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 */
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. */
116 /*-----------------------------------------------------------------*
118 *-----------------------------------------------------------------*/
121 int16 * indice, /* input: quantization indices */
122 int16 * isf_q /* input : ISF in the frequency domain (0..0.5) */
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 */
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 */
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 */
151 /*-----------------------------------------------------------------*
152 * filter prototypes *
153 *-----------------------------------------------------------------*/
155 void oversamp_12k8_to_16k_init(
156 int16 mem[] /* output: memory (2*NB_COEF_UP) set to zeros */
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) */
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] */
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] */
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) */
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 */
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]) */
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. */
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 */
224 /*-----------------------------------------------------------------*
226 *-----------------------------------------------------------------*/
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 */
236 /*-----------------------------------------------------------------*
238 *-----------------------------------------------------------------*/
241 void dec_gain2_amr_wb_init(
242 int16 * mem /* output : memory (4 words) */
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) */
259 /*-----------------------------------------------------------------*
261 *-----------------------------------------------------------------*/
263 void dec_acelp_2p_in_64(
264 int16 index, /* (i) : 12 bits index */
265 int16 code[] /* (o) :Q9 algebraic (fixed) codebook excitation */
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 */
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 */
287 /*-----------------------------------------------------------------*
288 * others prototypes *
289 *-----------------------------------------------------------------*/
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 */
301 int16 x[], /* (i/o) : signal to scale */
302 int16 lg, /* (i) : size of x[] */
303 int16 exp /* (i) : exponent: x = round(x << exp) */
306 int16 noise_gen_amrwb(int16 * seed);
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) */