1/* ------------------------------------------------------------------ 2 * Copyright (C) 1998-2009 PacketVideo 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 13 * express or implied. 14 * See the License for the specific language governing permissions 15 * and limitations under the License. 16 * ------------------------------------------------------------------- 17 */ 18/**************************************************************************************** 19Portions of this file are derived from the following 3GPP standard: 20 21 3GPP TS 26.173 22 ANSI-C code for the Adaptive Multi-Rate - Wideband (AMR-WB) speech codec 23 Available from http://www.3gpp.org 24 25(C) 2007, 3GPP Organizational Partners (ARIB, ATIS, CCSA, ETSI, TTA, TTC) 26Permission to distribute, modify and use this file under the standard license 27terms listed above has been obtained from the copyright holder. 28****************************************************************************************/ 29/* 30------------------------------------------------------------------------------ 31 32 33 34 Filename: deemphasis_32.cpp 35 36 Date: 05/08/2004 37 38------------------------------------------------------------------------------ 39 REVISION HISTORY 40 41 42 Description: 43 44------------------------------------------------------------------------------ 45 INPUT AND OUTPUT DEFINITIONS 46 47 int16 x_hi[], (i) : input signal (bit31..16) 48 int16 x_lo[], (i) : input signal (bit15..4) 49 int16 y[], (o) : output signal (x16) 50 int16 mu, (i) Q15 : deemphasis factor 51 int16 L, (i) : vector size 52 int16 * mem (i/o) : memory (y[-1]) 53 54------------------------------------------------------------------------------ 55 FUNCTION DESCRIPTION 56 57 32-bits filtering through 1/(1-mu z^-1) 58 59------------------------------------------------------------------------------ 60 REQUIREMENTS 61 62 63------------------------------------------------------------------------------ 64 REFERENCES 65 66------------------------------------------------------------------------------ 67 PSEUDO-CODE 68 69 Deemphasis H(z) = 1/(1 - 0.68z^(-1)) where mu = 0.67999 in Q15 70 71------------------------------------------------------------------------------ 72*/ 73 74 75/*---------------------------------------------------------------------------- 76; INCLUDES 77----------------------------------------------------------------------------*/ 78 79#include "pv_amr_wb_type_defs.h" 80#include "pvamrwbdecoder_basic_op.h" 81#include "pvamrwb_math_op.h" 82#include "pvamrwbdecoder_acelp.h" 83 84/*---------------------------------------------------------------------------- 85; MACROS 86; Define module specific macros here 87----------------------------------------------------------------------------*/ 88 89 90/*---------------------------------------------------------------------------- 91; DEFINES 92; Include all pre-processor statements here. Include conditional 93; compile variables also. 94----------------------------------------------------------------------------*/ 95 96/*---------------------------------------------------------------------------- 97; LOCAL FUNCTION DEFINITIONS 98; Function Prototype declaration 99----------------------------------------------------------------------------*/ 100 101/*---------------------------------------------------------------------------- 102; LOCAL STORE/BUFFER/POINTER DEFINITIONS 103; Variable declaration - defined here and used outside this module 104----------------------------------------------------------------------------*/ 105 106/*---------------------------------------------------------------------------- 107; EXTERNAL FUNCTION REFERENCES 108; Declare functions defined elsewhere and referenced in this module 109----------------------------------------------------------------------------*/ 110 111/*---------------------------------------------------------------------------- 112; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 113; Declare variables used in this module but defined elsewhere 114----------------------------------------------------------------------------*/ 115 116/*---------------------------------------------------------------------------- 117; FUNCTION CODE 118----------------------------------------------------------------------------*/ 119 120void deemphasis_32( 121 int16 x_hi[], /* (i) : input signal (bit31..16) */ 122 int16 x_lo[], /* (i) : input signal (bit15..4) */ 123 int16 y[], /* (o) : output signal (x16) */ 124 int16 mu, /* (i) Q15 : deemphasis factor */ 125 int16 L, /* (i) : vector size */ 126 int16 * mem /* (i/o) : memory (y[-1]) */ 127) 128{ 129 int16 i; 130 int32 L_tmp; 131 int16 lo, hi; 132 133 L_tmp = ((int32)x_hi[0]) << 16; 134 L_tmp += ((int32)x_lo[0]) << 4; 135 L_tmp = shl_int32(L_tmp, 3); 136 137 L_tmp = fxp_mac_16by16(*mem, mu, L_tmp), 138 139 L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */ 140 y[0] = amr_wb_round(L_tmp); 141 142 lo = x_lo[1]; 143 hi = x_hi[1]; 144 for (i = 1; i < L - 1; i++) 145 { 146 L_tmp = ((int32)hi) << 16; 147 L_tmp += ((int32)lo) << 4; 148 L_tmp = shl_int32(L_tmp, 3); 149 L_tmp = fxp_mac_16by16(y[i - 1], mu, L_tmp), 150 L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */ 151 y[i] = amr_wb_round(L_tmp); 152 lo = x_lo[i+1]; 153 hi = x_hi[i+1]; 154 } 155 L_tmp = ((int32)hi) << 16; 156 L_tmp += ((int32)lo) << 4; 157 L_tmp = shl_int32(L_tmp, 3); 158 L_tmp = fxp_mac_16by16(y[i - 1], mu, L_tmp), 159 L_tmp = shl_int32(L_tmp, 1); /* saturation can occur here */ 160 y[i] = amr_wb_round(L_tmp); 161 162 *mem = y[L - 1]; 163 164 return; 165} 166 167