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: decim54.c                                                 *
19 *                                                                      *
20 *	   Description:Decimation of 16kHz signal to 12.8kHz           *
21 *                                                                      *
22 ************************************************************************/
23 
24 #include "typedef.h"
25 #include "basic_op.h"
26 #include "acelp.h"
27 #include "cnst.h"
28 
29 #define FAC5   5
30 #define DOWN_FAC  26215                    /* 4/5 in Q15 */
31 
32 #define NB_COEF_DOWN  15
33 
34 /* Local functions */
35 static void Down_samp(
36 		Word16 * sig,                         /* input:  signal to downsampling  */
37 		Word16 * sig_d,                       /* output: downsampled signal      */
38 		Word16 L_frame_d                      /* input:  length of output        */
39 		);
40 
41 /* 1/5 resolution interpolation filter  (in Q14)  */
42 /* -1.5dB @ 6kHz, -6dB @ 6.4kHz, -10dB @ 6.6kHz, -20dB @ 6.9kHz, -25dB @ 7kHz, -55dB @ 8kHz */
43 
44 static Word16 fir_down1[4][30] =
45 {
46 	{-5, 24, -50, 54, 0, -128, 294, -408, 344, 0, -647, 1505, -2379, 3034, 13107, 3034, -2379, 1505, -647, 0, 344, -408,
47 	294, -128, 0, 54, -50, 24, -5, 0},
48 
49 	{-6, 19, -26, 0, 77, -188, 270, -233, 0, 434, -964, 1366, -1293, 0, 12254, 6575, -2746, 1030, 0, -507, 601, -441,
50 	198, 0, -95, 99, -58, 18, 0, -1},
51 
52 	{-3, 9, 0, -41, 111, -170, 153, 0, -295, 649, -888, 770, 0, -1997, 9894, 9894, -1997, 0, 770, -888, 649, -295, 0,
53 	153, -170, 111, -41, 0, 9, -3},
54 
55 	{-1, 0, 18, -58, 99, -95, 0, 198, -441, 601, -507, 0, 1030, -2746, 6575, 12254, 0, -1293, 1366, -964, 434, 0,
56 	-233, 270, -188, 77, 0, -26, 19, -6}
57 };
58 
Init_Decim_12k8(Word16 mem[])59 void Init_Decim_12k8(
60 		Word16 mem[]                          /* output: memory (2*NB_COEF_DOWN) set to zeros */
61 		)
62 {
63 	Set_zero(mem, 2 * NB_COEF_DOWN);
64 	return;
65 }
66 
Decim_12k8(Word16 sig16k[],Word16 lg,Word16 sig12k8[],Word16 mem[])67 void Decim_12k8(
68 		Word16 sig16k[],                      /* input:  signal to downsampling  */
69 		Word16 lg,                            /* input:  length of input         */
70 		Word16 sig12k8[],                     /* output: decimated signal        */
71 		Word16 mem[]                          /* in/out: memory (2*NB_COEF_DOWN) */
72 	       )
73 {
74 	Word16 lg_down;
75 	Word16 signal[L_FRAME16k + (2 * NB_COEF_DOWN)];
76 
77 	Copy(mem, signal, 2 * NB_COEF_DOWN);
78 
79 	Copy(sig16k, signal + (2 * NB_COEF_DOWN), lg);
80 
81 	lg_down = (lg * DOWN_FAC)>>15;
82 
83 	Down_samp(signal + NB_COEF_DOWN, sig12k8, lg_down);
84 
85 	Copy(signal + lg, mem, 2 * NB_COEF_DOWN);
86 
87 	return;
88 }
89 
Down_samp(Word16 * sig,Word16 * sig_d,Word16 L_frame_d)90 static void Down_samp(
91 		Word16 * sig,                         /* input:  signal to downsampling  */
92 		Word16 * sig_d,                       /* output: downsampled signal      */
93 		Word16 L_frame_d                      /* input:  length of output        */
94 		)
95 {
96 	Word32 i, j, frac, pos;
97 	Word16 *x, *y;
98 	Word32 L_sum;
99 
100 	pos = 0;                                 /* position is in Q2 -> 1/4 resolution  */
101 	for (j = 0; j < L_frame_d; j++)
102 	{
103 		i = (pos >> 2);                   /* integer part     */
104 		frac = pos & 3;                   /* fractional part */
105 		x = sig + i - NB_COEF_DOWN + 1;
106 		y = (Word16 *)(fir_down1 + frac);
107 
108 		L_sum = vo_mult32((*x++),(*y++));
109 		L_sum += vo_mult32((*x++),(*y++));
110 		L_sum += vo_mult32((*x++),(*y++));
111 		L_sum += vo_mult32((*x++),(*y++));
112 		L_sum += vo_mult32((*x++),(*y++));
113 		L_sum += vo_mult32((*x++),(*y++));
114 		L_sum += vo_mult32((*x++),(*y++));
115 		L_sum += vo_mult32((*x++),(*y++));
116 		L_sum += vo_mult32((*x++),(*y++));
117 		L_sum += vo_mult32((*x++),(*y++));
118 		L_sum += vo_mult32((*x++),(*y++));
119 		L_sum += vo_mult32((*x++),(*y++));
120 		L_sum += vo_mult32((*x++),(*y++));
121 		L_sum += vo_mult32((*x++),(*y++));
122 		L_sum += vo_mult32((*x++),(*y++));
123 		L_sum += vo_mult32((*x++),(*y++));
124 		L_sum += vo_mult32((*x++),(*y++));
125 		L_sum += vo_mult32((*x++),(*y++));
126 		L_sum += vo_mult32((*x++),(*y++));
127 		L_sum += vo_mult32((*x++),(*y++));
128 		L_sum += vo_mult32((*x++),(*y++));
129 		L_sum += vo_mult32((*x++),(*y++));
130 		L_sum += vo_mult32((*x++),(*y++));
131 		L_sum += vo_mult32((*x++),(*y++));
132 		L_sum += vo_mult32((*x++),(*y++));
133 		L_sum += vo_mult32((*x++),(*y++));
134 		L_sum += vo_mult32((*x++),(*y++));
135 		L_sum += vo_mult32((*x++),(*y++));
136 		L_sum += vo_mult32((*x++),(*y++));
137 		L_sum += vo_mult32((*x),(*y));
138 
139 		L_sum = L_shl2(L_sum, 2);
140 		sig_d[j] = extract_h(L_add(L_sum, 0x8000));
141 		pos += FAC5;              /* pos + 5/4 */
142 	}
143 	return;
144 }
145 
146 
147