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: syn_filt.c * 19 * * 20 * Description: Do the synthesis filtering 1/A(z) * 21 * * 22 ************************************************************************/ 23 24 #include "typedef.h" 25 #include "basic_op.h" 26 #include "math_op.h" 27 #include "cnst.h" 28 29 void Syn_filt( 30 Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */ 31 Word16 x[], /* (i) : input signal */ 32 Word16 y[], /* (o) : output signal */ 33 Word16 lg, /* (i) : size of filtering */ 34 Word16 mem[], /* (i/o) : memory associated with this filtering. */ 35 Word16 update /* (i) : 0=no update, 1=update of memory. */ 36 ) 37 { 38 Word32 i, a0; 39 Word16 y_buf[L_SUBFR16k + M16k]; 40 Word32 L_tmp; 41 Word16 *yy, *p1, *p2; 42 yy = &y_buf[0]; 43 /* copy initial filter states into synthesis buffer */ 44 for (i = 0; i < 16; i++) 45 { 46 *yy++ = mem[i]; 47 } 48 a0 = (a[0] >> 1); /* input / 2 */ 49 /* Do the filtering. */ 50 for (i = 0; i < lg; i++) 51 { 52 p1 = &a[1]; 53 p2 = &yy[i-1]; 54 L_tmp = vo_mult32(a0, x[i]); 55 L_tmp -= vo_mult32((*p1++), (*p2--)); 56 L_tmp -= vo_mult32((*p1++), (*p2--)); 57 L_tmp -= vo_mult32((*p1++), (*p2--)); 58 L_tmp -= vo_mult32((*p1++), (*p2--)); 59 L_tmp -= vo_mult32((*p1++), (*p2--)); 60 L_tmp -= vo_mult32((*p1++), (*p2--)); 61 L_tmp -= vo_mult32((*p1++), (*p2--)); 62 L_tmp -= vo_mult32((*p1++), (*p2--)); 63 L_tmp -= vo_mult32((*p1++), (*p2--)); 64 L_tmp -= vo_mult32((*p1++), (*p2--)); 65 L_tmp -= vo_mult32((*p1++), (*p2--)); 66 L_tmp -= vo_mult32((*p1++), (*p2--)); 67 L_tmp -= vo_mult32((*p1++), (*p2--)); 68 L_tmp -= vo_mult32((*p1++), (*p2--)); 69 L_tmp -= vo_mult32((*p1++), (*p2--)); 70 L_tmp -= vo_mult32((*p1), (*p2)); 71 72 L_tmp = L_shl2(L_tmp, 4); 73 y[i] = yy[i] = extract_h(L_add(L_tmp, 0x8000)); 74 } 75 /* Update memory if required */ 76 if (update) 77 for (i = 0; i < 16; i++) 78 { 79 mem[i] = yy[lg - 16 + i]; 80 } 81 return; 82 } 83 84 85 void Syn_filt_32( 86 Word16 a[], /* (i) Q12 : a[m+1] prediction coefficients */ 87 Word16 m, /* (i) : order of LP filter */ 88 Word16 exc[], /* (i) Qnew: excitation (exc[i] >> Qnew) */ 89 Word16 Qnew, /* (i) : exc scaling = 0(min) to 8(max) */ 90 Word16 sig_hi[], /* (o) /16 : synthesis high */ 91 Word16 sig_lo[], /* (o) /16 : synthesis low */ 92 Word16 lg /* (i) : size of filtering */ 93 ) 94 { 95 Word32 i,a0; 96 Word32 L_tmp, L_tmp1; 97 Word16 *p1, *p2, *p3; 98 a0 = a[0] >> (4 + Qnew); /* input / 16 and >>Qnew */ 99 /* Do the filtering. */ 100 for (i = 0; i < lg; i++) 101 { 102 L_tmp = 0; 103 L_tmp1 = 0; 104 p1 = a; 105 p2 = &sig_lo[i - 1]; 106 p3 = &sig_hi[i - 1]; 107 108 L_tmp -= vo_mult32((*p2--), (*p1)); 109 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 110 L_tmp -= vo_mult32((*p2--), (*p1)); 111 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 112 L_tmp -= vo_mult32((*p2--), (*p1)); 113 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 114 L_tmp -= vo_mult32((*p2--), (*p1)); 115 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 116 L_tmp -= vo_mult32((*p2--), (*p1)); 117 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 118 L_tmp -= vo_mult32((*p2--), (*p1)); 119 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 120 L_tmp -= vo_mult32((*p2--), (*p1)); 121 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 122 L_tmp -= vo_mult32((*p2--), (*p1)); 123 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 124 L_tmp -= vo_mult32((*p2--), (*p1)); 125 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 126 L_tmp -= vo_mult32((*p2--), (*p1)); 127 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 128 L_tmp -= vo_mult32((*p2--), (*p1)); 129 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 130 L_tmp -= vo_mult32((*p2--), (*p1)); 131 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 132 L_tmp -= vo_mult32((*p2--), (*p1)); 133 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 134 L_tmp -= vo_mult32((*p2--), (*p1)); 135 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 136 L_tmp -= vo_mult32((*p2--), (*p1)); 137 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 138 L_tmp -= vo_mult32((*p2--), (*p1)); 139 L_tmp1 -= vo_mult32((*p3--), (*p1++)); 140 141 L_tmp = L_tmp >> 11; 142 L_tmp += vo_L_mult(exc[i], a0); 143 144 /* sig_hi = bit16 to bit31 of synthesis */ 145 L_tmp = L_tmp - (L_tmp1<<1); 146 147 L_tmp = L_tmp >> 3; /* ai in Q12 */ 148 sig_hi[i] = extract_h(L_tmp); 149 150 /* sig_lo = bit4 to bit15 of synthesis */ 151 L_tmp >>= 4; /* 4 : sig_lo[i] >> 4 */ 152 sig_lo[i] = (Word16)((L_tmp - (sig_hi[i] << 13))); 153 } 154 155 return; 156 } 157 158 159 160 161