1 /*
2  ** Copyright 2003-2010, VisualOn, Inc.
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 express or implied.
13  ** See the License for the specific language governing permissions and
14  ** limitations under the License.
15  */
16 
17 /***********************************************************************
18 *      File: pred_lt4.c                                                *
19 *                                                                      *
20 *      Description: Compute the result of long term prediction with    *
21 *      fractional interpolation of resolution 1/4                      *
22 *      on return exc[0..L_subr-1] contains the interpolated signal     *
23 *      (adaptive codebook excitation)                                  *
24 *                                                                      *
25 ************************************************************************/
26 
27 #include "typedef.h"
28 #include "basic_op.h"
29 
30 #define UP_SAMP      4
31 #define L_INTERPOL2  16
32 
33 /* 1/4 resolution interpolation filter (-3 dB at 0.856*fs/2) in Q14 */
34 
35 Word16 inter4_2[4][32] =
36 {
37     {0,-2,4,-2,-10,38,-88,165,-275,424,-619,871,-1207,1699,-2598,5531,14031,-2147,780,-249,
38     -16,153,-213,226,-209,175,-133,91,-55,28,-10,2},
39 
40     {1,-7,19,-33,47,-52,43,-9,-60,175,-355,626,-1044,1749,-3267,10359,10359,-3267,1749,-1044,
41     626,-355,175,-60,-9,43,-52,47,-33,19, -7, 1},
42 
43     {2,-10,28,-55,91,-133,175,-209,226,-213,153,-16,-249,780,-2147,14031,5531,-2598,1699,-1207,
44     871,-619,424,-275,165,-88,38,-10,-2,4,-2,0},
45 
46     {1,-7,22,-49,92,-153,231,-325,431,-544,656,-762,853,-923,968,15401,968,-923,853,-762,
47     656,-544,431,-325,231,-153,92,-49,22,-7, 1, 0}
48 
49 };
50 
Pred_lt4(Word16 exc[],Word16 T0,Word16 frac,Word16 L_subfr)51 void Pred_lt4(
52         Word16 exc[],                         /* in/out: excitation buffer */
53         Word16 T0,                            /* input : integer pitch lag */
54         Word16 frac,                          /* input : fraction of lag   */
55         Word16 L_subfr                        /* input : subframe size     */
56          )
57 {
58     Word16 j, k, *x;
59     Word32 L_sum;
60     Word16 *ptr, *ptr1;
61     Word16 *ptr2;
62 
63     x = exc - T0;
64     frac = -frac;
65     if (frac < 0)
66     {
67         frac += UP_SAMP;
68         x--;
69     }
70     x -= 15;                                     /* x = L_INTERPOL2 - 1 */
71     k = 3 - frac;                                /* k = UP_SAMP - 1 - frac */
72 
73     ptr2 = &(inter4_2[k][0]);
74     for (j = 0; j < L_subfr; j++)
75     {
76         ptr = ptr2;
77         ptr1 = x;
78         L_sum  = vo_mult32((*ptr1++), (*ptr++));
79         L_sum += vo_mult32((*ptr1++), (*ptr++));
80         L_sum += vo_mult32((*ptr1++), (*ptr++));
81         L_sum += vo_mult32((*ptr1++), (*ptr++));
82         L_sum += vo_mult32((*ptr1++), (*ptr++));
83         L_sum += vo_mult32((*ptr1++), (*ptr++));
84         L_sum += vo_mult32((*ptr1++), (*ptr++));
85         L_sum += vo_mult32((*ptr1++), (*ptr++));
86         L_sum += vo_mult32((*ptr1++), (*ptr++));
87         L_sum += vo_mult32((*ptr1++), (*ptr++));
88         L_sum += vo_mult32((*ptr1++), (*ptr++));
89         L_sum += vo_mult32((*ptr1++), (*ptr++));
90         L_sum += vo_mult32((*ptr1++), (*ptr++));
91         L_sum += vo_mult32((*ptr1++), (*ptr++));
92         L_sum += vo_mult32((*ptr1++), (*ptr++));
93         L_sum += vo_mult32((*ptr1++), (*ptr++));
94         L_sum += vo_mult32((*ptr1++), (*ptr++));
95         L_sum += vo_mult32((*ptr1++), (*ptr++));
96         L_sum += vo_mult32((*ptr1++), (*ptr++));
97         L_sum += vo_mult32((*ptr1++), (*ptr++));
98         L_sum += vo_mult32((*ptr1++), (*ptr++));
99         L_sum += vo_mult32((*ptr1++), (*ptr++));
100         L_sum += vo_mult32((*ptr1++), (*ptr++));
101         L_sum += vo_mult32((*ptr1++), (*ptr++));
102         L_sum += vo_mult32((*ptr1++), (*ptr++));
103         L_sum += vo_mult32((*ptr1++), (*ptr++));
104         L_sum += vo_mult32((*ptr1++), (*ptr++));
105         L_sum += vo_mult32((*ptr1++), (*ptr++));
106         L_sum += vo_mult32((*ptr1++), (*ptr++));
107         L_sum += vo_mult32((*ptr1++), (*ptr++));
108         L_sum += vo_mult32((*ptr1++), (*ptr++));
109         L_sum += vo_mult32((*ptr1++), (*ptr++));
110 
111         L_sum = L_shl2(L_sum, 2);
112         exc[j] = extract_h(L_add(L_sum, 0x8000));
113         x++;
114     }
115 
116     return;
117 }
118 
119 
120 
121