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 Filename: oversamp_12k8_to_16k.cpp
38 ------------------------------------------------------------------------------
44 ------------------------------------------------------------------------------
45 INPUT AND OUTPUT DEFINITIONS
47 int16 signal[], input signal / output is divided by 16
48 int16 lg, lenght of signal
49 int16 mem[] in/out: memory (size=30)
50 int16 x[] scratch mem ( size= 60)
52 ------------------------------------------------------------------------------
55 Oversamp_16k : oversampling from 12.8kHz to 16kHz.
58 ------------------------------------------------------------------------------
62 ------------------------------------------------------------------------------
65 ------------------------------------------------------------------------------
68 ------------------------------------------------------------------------------
72 /*----------------------------------------------------------------------------
74 ----------------------------------------------------------------------------*/
76 #include "pv_amr_wb_type_defs.h"
77 #include "pvamrwbdecoder_basic_op.h"
78 #include "pvamrwbdecoder_acelp.h"
79 #include "pvamrwbdecoder_cnst.h"
81 /*----------------------------------------------------------------------------
83 ; Define module specific macros here
84 ----------------------------------------------------------------------------*/
87 /*----------------------------------------------------------------------------
89 ; Include all pre-processor statements here. Include conditional
90 ; compile variables also.
91 ----------------------------------------------------------------------------*/
95 #define INV_FAC5 6554 /* 1/5 in Q15 */
96 #define DOWN_FAC 26215 /* 4/5 in Q15 */
97 #define UP_FAC 20480 /* 5/4 in Q14 */
98 #define NB_COEF_DOWN 15
100 #define N_LOOP_COEF_UP 4
102 /*----------------------------------------------------------------------------
103 ; LOCAL FUNCTION DEFINITIONS
104 ; Function Prototype declaration
105 ----------------------------------------------------------------------------*/
113 /* Local functions */
116 int16 * sig_d, /* input: signal to oversampling */
117 int16 * sig_u, /* output: oversampled signal */
118 int16 L_frame /* input: length of output */
122 int16 AmrWbInterpol( /* return result of interpolation */
123 int16 * x, /* input vector */
124 const int16 * fir, /* filter coefficient */
125 int16 nb_coef /* number of coefficients */
133 /*----------------------------------------------------------------------------
134 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
135 ; Variable declaration - defined here and used outside this module
136 ----------------------------------------------------------------------------*/
139 /* 1/5 resolution interpolation filter (in Q14) */
140 /* -1.5dB @ 6kHz, -6dB @ 6.4kHz, -10dB @ 6.6kHz,
141 -20dB @ 6.9kHz, -25dB @ 7kHz, -55dB @ 8kHz */
144 const int16 fir_up[4][24] =
148 -1, 12, -33, 68, -119, 191,
149 -291, 430, -634, 963, -1616, 3792,
150 15317, -2496, 1288, -809, 542, -369,
151 247, -160, 96, -52, 23, -6,
154 -4, 24, -62, 124, -213, 338,
155 -510, 752, -1111, 1708, -2974, 8219,
156 12368, -3432, 1881, -1204, 812, -552,
157 368, -235, 139, -73, 30, -7,
160 -7, 30, -73, 139, -235, 368,
161 -552, 812, -1204, 1881, -3432, 12368,
162 8219, -2974, 1708, -1111, 752, -510,
163 338, -213, 124, -62, 24, -4,
166 -6, 23, -52, 96, -160, 247,
167 -369, 542, -809, 1288, -2496, 15317,
168 3792, -1616, 963, -634, 430, -291,
169 191, -119, 68, -33, 12, -1,
173 /*----------------------------------------------------------------------------
174 ; EXTERNAL FUNCTION REFERENCES
175 ; Declare functions defined elsewhere and referenced in this module
176 ----------------------------------------------------------------------------*/
178 /*----------------------------------------------------------------------------
179 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
180 ; Declare variables used in this module but defined elsewhere
181 ----------------------------------------------------------------------------*/
183 /*----------------------------------------------------------------------------
185 ----------------------------------------------------------------------------*/
188 /* output: memory (2*NB_COEF_UP) set to zeros */
189 void oversamp_12k8_to_16k_init(int16 mem[])
191 pv_memset((void *)mem, 0, (2*NB_COEF_UP)*sizeof(*mem));
195 /*----------------------------------------------------------------------------
197 ----------------------------------------------------------------------------*/
199 void oversamp_12k8_to_16k(
200 int16 sig12k8[], /* input: signal to oversampling */
201 int16 lg, /* input: length of input */
202 int16 sig16k[], /* output: oversampled signal */
203 int16 mem[], /* in/out: memory (2*NB_COEF_UP) */
209 pv_memcpy((void *)signal,
211 (2*NB_COEF_UP)*sizeof(*mem));
213 pv_memcpy((void *)(signal + (2*NB_COEF_UP)),
215 lg*sizeof(*sig12k8));
217 lg_up = lg + (lg >> 2); /* 5/4 of lg */
219 AmrWbUp_samp(signal + NB_COEF_UP, sig16k, lg_up);
221 pv_memcpy((void *)mem,
222 (void *)(signal + lg),
223 (2*NB_COEF_UP)*sizeof(*signal));
230 /*----------------------------------------------------------------------------
232 ----------------------------------------------------------------------------*/
236 int16 * sig_d, /* input: signal to oversampling */
237 int16 * sig_u, /* output: oversampled signal */
238 int16 L_frame /* input: length of output */
244 int16 * pt_sig_u = sig_u;
247 for (int16 j = 0; j < L_frame; j++)
249 i = ((int32)j * INV_FAC5) >> 13; /* integer part = pos * 1/5 */
254 *(pt_sig_u++) = AmrWbInterpol(&sig_d[i],
255 fir_up[(FAC5-1) - frac],
260 *(pt_sig_u++) = sig_d[i+12 - NB_COEF_UP ];
267 /*----------------------------------------------------------------------------
269 ----------------------------------------------------------------------------*/
272 /* Fractional interpolation of signal at position (frac/resol) */
275 int16 AmrWbInterpol( /* return result of interpolation */
276 int16 * x, /* input vector */
277 const int16 *fir, /* filter coefficient */
278 int16 nb_coef /* number of coefficients */
282 const int16 *pt_fir = fir;
284 int16 tmp1, tmp2, tmp3, tmp4;
285 int16 *pt_x = x - nb_coef - (nb_coef << 1) + 1;
292 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), 0x00002000L);
293 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
294 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
295 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
300 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
301 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
302 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
303 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
308 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
309 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
310 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
311 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
316 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
317 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
318 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
319 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
324 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
325 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
326 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
327 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
332 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
333 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
334 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
335 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
338 L_sum = shl_int32(L_sum, 2); /* saturation can occur here */
340 return ((int16(L_sum >> 16)));