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: preemph.c * 19 * * 20 * Description: Preemphasis: filtering through 1 - g z^-1 * 21 * Preemph2 --> signal is multiplied by 2 * 22 * * 23 ************************************************************************/ 24 25 #include "typedef.h" 26 #include "basic_op.h" 27 28 void Preemph( 29 Word16 x[], /* (i/o) : input signal overwritten by the output */ 30 Word16 mu, /* (i) Q15 : preemphasis coefficient */ 31 Word16 lg, /* (i) : lenght of filtering */ 32 Word16 * mem /* (i/o) : memory (x[-1]) */ 33 ) 34 { 35 Word16 temp; 36 Word32 i, L_tmp; 37 38 temp = x[lg - 1]; 39 40 for (i = lg - 1; i > 0; i--) 41 { 42 L_tmp = L_deposit_h(x[i]); 43 L_tmp -= (x[i - 1] * mu)<<1; 44 x[i] = (L_tmp + 0x8000)>>16; 45 } 46 47 L_tmp = L_deposit_h(x[0]); 48 L_tmp -= ((*mem) * mu)<<1; 49 x[0] = (L_tmp + 0x8000)>>16; 50 51 *mem = temp; 52 53 return; 54 } 55 56 57 void Preemph2( 58 Word16 x[], /* (i/o) : input signal overwritten by the output */ 59 Word16 mu, /* (i) Q15 : preemphasis coefficient */ 60 Word16 lg, /* (i) : lenght of filtering */ 61 Word16 * mem /* (i/o) : memory (x[-1]) */ 62 ) 63 { 64 Word16 temp; 65 Word32 i, L_tmp; 66 67 temp = x[lg - 1]; 68 69 for (i = (Word16) (lg - 1); i > 0; i--) 70 { 71 L_tmp = L_deposit_h(x[i]); 72 L_tmp -= (x[i - 1] * mu)<<1; 73 L_tmp = (L_tmp << 1); 74 x[i] = (L_tmp + 0x8000)>>16; 75 } 76 77 L_tmp = L_deposit_h(x[0]); 78 L_tmp -= ((*mem) * mu)<<1; 79 L_tmp = (L_tmp << 1); 80 x[0] = (L_tmp + 0x8000)>>16; 81 82 *mem = temp; 83 84 return; 85 } 86 87 88 89