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: deemph.c * 19 * * 20 * Description:filtering through 1/(1-mu z^ -1) * 21 * Deemph2 --> signal is divided by 2 * 22 * Deemph_32 --> for 32 bits signal. * 23 * * 24 ************************************************************************/ 25 26 #include "typedef.h" 27 #include "basic_op.h" 28 #include "math_op.h" 29 30 void Deemph( 31 Word16 x[], /* (i/o) : input signal overwritten by the output */ 32 Word16 mu, /* (i) Q15 : deemphasis factor */ 33 Word16 L, /* (i) : vector size */ 34 Word16 * mem /* (i/o) : memory (y[-1]) */ 35 ) 36 { 37 Word32 i; 38 Word32 L_tmp; 39 40 L_tmp = L_deposit_h(x[0]); 41 L_tmp = L_mac(L_tmp, *mem, mu); 42 x[0] = vo_round(L_tmp); 43 44 for (i = 1; i < L; i++) 45 { 46 L_tmp = L_deposit_h(x[i]); 47 L_tmp = L_mac(L_tmp, x[i - 1], mu); 48 x[i] = voround(L_tmp); 49 } 50 51 *mem = x[L - 1]; 52 53 return; 54 } 55 56 57 void Deemph2( 58 Word16 x[], /* (i/o) : input signal overwritten by the output */ 59 Word16 mu, /* (i) Q15 : deemphasis factor */ 60 Word16 L, /* (i) : vector size */ 61 Word16 * mem /* (i/o) : memory (y[-1]) */ 62 ) 63 { 64 Word32 i; 65 Word32 L_tmp; 66 L_tmp = x[0] << 15; 67 L_tmp += ((*mem) * mu)<<1; 68 x[0] = (L_tmp + 0x8000)>>16; 69 for (i = 1; i < L; i++) 70 { 71 L_tmp = x[i] << 15; 72 L_tmp += (x[i - 1] * mu)<<1; 73 x[i] = (L_tmp + 0x8000)>>16; 74 } 75 *mem = x[L - 1]; 76 return; 77 } 78 79 80 void Deemph_32( 81 Word16 x_hi[], /* (i) : input signal (bit31..16) */ 82 Word16 x_lo[], /* (i) : input signal (bit15..4) */ 83 Word16 y[], /* (o) : output signal (x16) */ 84 Word16 mu, /* (i) Q15 : deemphasis factor */ 85 Word16 L, /* (i) : vector size */ 86 Word16 * mem /* (i/o) : memory (y[-1]) */ 87 ) 88 { 89 Word16 fac; 90 Word32 i, L_tmp; 91 92 fac = mu >> 1; /* Q15 --> Q14 */ 93 94 L_tmp = L_deposit_h(x_hi[0]); 95 L_tmp += (x_lo[0] * 8)<<1; 96 L_tmp = (L_tmp << 3); 97 L_tmp += ((*mem) * fac)<<1; 98 L_tmp = (L_tmp << 1); 99 y[0] = (L_tmp + 0x8000)>>16; 100 101 for (i = 1; i < L; i++) 102 { 103 L_tmp = L_deposit_h(x_hi[i]); 104 L_tmp += (x_lo[i] * 8)<<1; 105 L_tmp = (L_tmp << 3); 106 L_tmp += (y[i - 1] * fac)<<1; 107 L_tmp = (L_tmp << 1); 108 y[i] = (L_tmp + 0x8000)>>16; 109 } 110 111 *mem = y[L - 1]; 112 113 return; 114 } 115 116 117 118