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
36 ------------------------------------------------------------------------------
37 INPUT AND OUTPUT DEFINITIONS
39 int16 signal[], input signal / output is divided by 16
40 int16 lg, lenght of signal
41 int16 mem[] in/out: memory (size=30)
42 int16 x[] scratch mem ( size= 60)
44 ------------------------------------------------------------------------------
47 Oversamp_16k : oversampling from 12.8kHz to 16kHz.
50 ------------------------------------------------------------------------------
54 ------------------------------------------------------------------------------
57 ------------------------------------------------------------------------------
60 ------------------------------------------------------------------------------
64 /*----------------------------------------------------------------------------
66 ----------------------------------------------------------------------------*/
68 #include "pv_amr_wb_type_defs.h"
69 #include "pvamrwbdecoder_basic_op.h"
70 #include "pvamrwbdecoder_acelp.h"
71 #include "pvamrwbdecoder_cnst.h"
73 /*----------------------------------------------------------------------------
75 ; Define module specific macros here
76 ----------------------------------------------------------------------------*/
79 /*----------------------------------------------------------------------------
81 ; Include all pre-processor statements here. Include conditional
82 ; compile variables also.
83 ----------------------------------------------------------------------------*/
87 #define INV_FAC5 6554 /* 1/5 in Q15 */
88 #define DOWN_FAC 26215 /* 4/5 in Q15 */
89 #define UP_FAC 20480 /* 5/4 in Q14 */
90 #define NB_COEF_DOWN 15
92 #define N_LOOP_COEF_UP 4
94 /*----------------------------------------------------------------------------
95 ; LOCAL FUNCTION DEFINITIONS
96 ; Function Prototype declaration
97 ----------------------------------------------------------------------------*/
105 /* Local functions */
108 int16 * sig_d, /* input: signal to oversampling */
109 int16 * sig_u, /* output: oversampled signal */
110 int16 L_frame /* input: length of output */
114 int16 AmrWbInterpol( /* return result of interpolation */
115 int16 * x, /* input vector */
116 const int16 * fir, /* filter coefficient */
117 int16 nb_coef /* number of coefficients */
125 /*----------------------------------------------------------------------------
126 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS
127 ; Variable declaration - defined here and used outside this module
128 ----------------------------------------------------------------------------*/
131 /* 1/5 resolution interpolation filter (in Q14) */
132 /* -1.5dB @ 6kHz, -6dB @ 6.4kHz, -10dB @ 6.6kHz,
133 -20dB @ 6.9kHz, -25dB @ 7kHz, -55dB @ 8kHz */
136 const int16 fir_up[4][24] =
140 -1, 12, -33, 68, -119, 191,
141 -291, 430, -634, 963, -1616, 3792,
142 15317, -2496, 1288, -809, 542, -369,
143 247, -160, 96, -52, 23, -6,
146 -4, 24, -62, 124, -213, 338,
147 -510, 752, -1111, 1708, -2974, 8219,
148 12368, -3432, 1881, -1204, 812, -552,
149 368, -235, 139, -73, 30, -7,
152 -7, 30, -73, 139, -235, 368,
153 -552, 812, -1204, 1881, -3432, 12368,
154 8219, -2974, 1708, -1111, 752, -510,
155 338, -213, 124, -62, 24, -4,
158 -6, 23, -52, 96, -160, 247,
159 -369, 542, -809, 1288, -2496, 15317,
160 3792, -1616, 963, -634, 430, -291,
161 191, -119, 68, -33, 12, -1,
165 /*----------------------------------------------------------------------------
166 ; EXTERNAL FUNCTION REFERENCES
167 ; Declare functions defined elsewhere and referenced in this module
168 ----------------------------------------------------------------------------*/
170 /*----------------------------------------------------------------------------
171 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES
172 ; Declare variables used in this module but defined elsewhere
173 ----------------------------------------------------------------------------*/
175 /*----------------------------------------------------------------------------
177 ----------------------------------------------------------------------------*/
180 /* output: memory (2*NB_COEF_UP) set to zeros */
181 void oversamp_12k8_to_16k_init(int16 mem[])
183 pv_memset((void *)mem, 0, (2*NB_COEF_UP)*sizeof(*mem));
187 /*----------------------------------------------------------------------------
189 ----------------------------------------------------------------------------*/
191 void oversamp_12k8_to_16k(
192 int16 sig12k8[], /* input: signal to oversampling */
193 int16 lg, /* input: length of input */
194 int16 sig16k[], /* output: oversampled signal */
195 int16 mem[], /* in/out: memory (2*NB_COEF_UP) */
201 pv_memcpy((void *)signal,
203 (2*NB_COEF_UP)*sizeof(*mem));
205 pv_memcpy((void *)(signal + (2*NB_COEF_UP)),
207 lg*sizeof(*sig12k8));
209 lg_up = lg + (lg >> 2); /* 5/4 of lg */
211 AmrWbUp_samp(signal + NB_COEF_UP, sig16k, lg_up);
213 pv_memcpy((void *)mem,
214 (void *)(signal + lg),
215 (2*NB_COEF_UP)*sizeof(*signal));
222 /*----------------------------------------------------------------------------
224 ----------------------------------------------------------------------------*/
228 int16 * sig_d, /* input: signal to oversampling */
229 int16 * sig_u, /* output: oversampled signal */
230 int16 L_frame /* input: length of output */
236 int16 * pt_sig_u = sig_u;
239 for (int16 j = 0; j < L_frame; j++)
241 i = ((int32)j * INV_FAC5) >> 13; /* integer part = pos * 1/5 */
246 *(pt_sig_u++) = AmrWbInterpol(&sig_d[i],
247 fir_up[(FAC5-1) - frac],
252 *(pt_sig_u++) = sig_d[i+12 - NB_COEF_UP ];
259 /*----------------------------------------------------------------------------
261 ----------------------------------------------------------------------------*/
264 /* Fractional interpolation of signal at position (frac/resol) */
267 int16 AmrWbInterpol( /* return result of interpolation */
268 int16 * x, /* input vector */
269 const int16 *fir, /* filter coefficient */
270 int16 nb_coef /* number of coefficients */
274 const int16 *pt_fir = fir;
276 int16 tmp1, tmp2, tmp3, tmp4;
277 int16 *pt_x = x - nb_coef - (nb_coef << 1) + 1;
284 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), 0x00002000L);
285 L_sum = fxp_mac_16by16(tmp2, *(pt_fir++), L_sum);
286 L_sum = fxp_mac_16by16(tmp3, *(pt_fir++), L_sum);
287 L_sum = fxp_mac_16by16(tmp4, *(pt_fir++), L_sum);
292 L_sum = fxp_mac_16by16(tmp1, *(pt_fir++), L_sum);
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);
330 L_sum = shl_int32(L_sum, 2); /* saturation can occur here */
332 return ((int16)(L_sum >> 16));