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 /* 19 20 Filename: sbr_inv_filt_levelemphasis.c 21 22 ------------------------------------------------------------------------------ 23 REVISION HISTORY 24 25 26 Who: Date: MM/DD/YYYY 27 Description: 28 29 ------------------------------------------------------------------------------ 30 INPUT AND OUTPUT DEFINITIONS 31 32 33 34 ------------------------------------------------------------------------------ 35 FUNCTION DESCRIPTION 36 37 38 ------------------------------------------------------------------------------ 39 REQUIREMENTS 40 41 42 ------------------------------------------------------------------------------ 43 REFERENCES 44 45 SC 29 Software Copyright Licencing Disclaimer: 46 47 This software module was originally developed by 48 Coding Technologies 49 50 and edited by 51 - 52 53 in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3 54 standards for reference purposes and its performance may not have been 55 optimized. This software module is an implementation of one or more tools as 56 specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards. 57 ISO/IEC gives users free license to this software module or modifications 58 thereof for use in products claiming conformance to audiovisual and 59 image-coding related ITU Recommendations and/or ISO/IEC International 60 Standards. ISO/IEC gives users the same free license to this software module or 61 modifications thereof for research purposes and further ISO/IEC standardisation. 62 Those intending to use this software module in products are advised that its 63 use may infringe existing patents. ISO/IEC have no liability for use of this 64 software module or modifications thereof. Copyright is not released for 65 products that do not conform to audiovisual and image-coding related ITU 66 Recommendations and/or ISO/IEC International Standards. 67 The original developer retains full right to modify and use the code for its 68 own purpose, assign or donate the code to a third party and to inhibit third 69 parties from using the code for products that do not conform to audiovisual and 70 image-coding related ITU Recommendations and/or ISO/IEC International Standards. 71 This copyright notice must be included in all copies or derivative works. 72 Copyright (c) ISO/IEC 2002. 73 74 ------------------------------------------------------------------------------ 75 PSEUDO-CODE 76 77 ------------------------------------------------------------------------------ 78 */ 79 80 81 /*---------------------------------------------------------------------------- 82 ; INCLUDES 83 ----------------------------------------------------------------------------*/ 84 85 #ifdef AAC_PLUS 86 87 88 #include "sbr_inv_filt_levelemphasis.h" 89 #include "sbr_generate_high_freq.h" 90 91 /*---------------------------------------------------------------------------- 92 ; MACROS 93 ; Define module specific macros here 94 ----------------------------------------------------------------------------*/ 95 96 97 /*---------------------------------------------------------------------------- 98 ; DEFINES 99 ; Include all pre-processor statements here. Include conditional 100 ; compile variables also. 101 ----------------------------------------------------------------------------*/ 102 103 /*---------------------------------------------------------------------------- 104 ; LOCAL FUNCTION DEFINITIONS 105 ; Function Prototype declaration 106 ----------------------------------------------------------------------------*/ 107 108 /*---------------------------------------------------------------------------- 109 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS 110 ; Variable declaration - defined here and used outside this module 111 ----------------------------------------------------------------------------*/ 112 113 /*---------------------------------------------------------------------------- 114 ; EXTERNAL FUNCTION REFERENCES 115 ; Declare functions defined elsewhere and referenced in this module 116 ----------------------------------------------------------------------------*/ 117 118 /*---------------------------------------------------------------------------- 119 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 120 ; Declare variables used in this module but defined elsewhere 121 ----------------------------------------------------------------------------*/ 122 123 124 #include "pv_audio_type_defs.h" 125 #include "fxp_mul32.h" 126 127 #define R_SHIFT 29 128 #define Qfmt(x) (Int32)(x*((Int32)1<<R_SHIFT) + (x>=0?0.5F:-0.5F)) 129 130 const Int32 InvFiltFactors[5] = {Qfmt(0.00f), /* OFF_LEVEL */ 131 Qfmt(0.60f), /* TRANSITION_LEVEL */ 132 Qfmt(0.75f), /* LOW_LEVEL */ 133 Qfmt(0.90f), /* MID_LEVEL */ 134 Qfmt(0.98f) 135 }; /* HIGH_LEVEL */ 136 137 /*---------------------------------------------------------------------------- 138 ; FUNCTION CODE 139 ----------------------------------------------------------------------------*/ 140 141 void sbr_inv_filt_levelemphasis(INVF_MODE *invFiltMode, 142 INVF_MODE *prevInvFiltMode, 143 Int32 nNfb, 144 Int32 BwVector[MAX_NUM_PATCHES], 145 Int32 BwVectorOld[MAX_NUM_PATCHES]) 146 { 147 Int32 i; 148 Int32 j; 149 Int32 tmp; 150 151 for (i = 0; i < nNfb; i++) 152 { 153 switch (invFiltMode[i]) 154 { 155 case INVF_LOW_LEVEL: 156 if (prevInvFiltMode[i] == INVF_OFF) 157 { 158 j = 1; 159 } 160 else 161 { 162 j = 2; 163 } 164 break; 165 166 case INVF_MID_LEVEL: 167 j = 3; 168 break; 169 170 case INVF_HIGH_LEVEL: 171 j = 4; 172 break; 173 174 default: 175 if (prevInvFiltMode[i] == INVF_LOW_LEVEL) 176 { 177 j = 1; 178 } 179 else 180 { 181 j = 0; 182 } 183 } 184 185 tmp = InvFiltFactors[j]; 186 187 if (tmp < BwVectorOld[i]) 188 { 189 tmp = ((tmp << 1) + tmp + BwVectorOld[i]) >> 2; 190 } 191 else 192 { 193 tmp = fxp_mul32_Q29(Qfmt(0.90625f), tmp); 194 tmp = fxp_mac32_Q29(Qfmt(0.09375f), BwVectorOld[i], tmp); 195 } 196 197 if (tmp < Qfmt(0.015625F)) 198 { 199 tmp = 0; 200 } 201 202 if (tmp >= Qfmt(0.99609375f)) 203 { 204 tmp = Qfmt(0.99609375f); 205 } 206 207 BwVector[i] = tmp; 208 } 209 } 210 211 212 #endif 213 214 215