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_decode_envelope.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 45SC 29 Software Copyright Licencing Disclaimer: 46 47This software module was originally developed by 48 Coding Technologies 49 50and edited by 51 - 52 53in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3 54standards for reference purposes and its performance may not have been 55optimized. This software module is an implementation of one or more tools as 56specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards. 57ISO/IEC gives users free license to this software module or modifications 58thereof for use in products claiming conformance to audiovisual and 59image-coding related ITU Recommendations and/or ISO/IEC International 60Standards. ISO/IEC gives users the same free license to this software module or 61modifications thereof for research purposes and further ISO/IEC standardisation. 62Those intending to use this software module in products are advised that its 63use may infringe existing patents. ISO/IEC have no liability for use of this 64software module or modifications thereof. Copyright is not released for 65products that do not conform to audiovisual and image-coding related ITU 66Recommendations and/or ISO/IEC International Standards. 67The original developer retains full right to modify and use the code for its 68own purpose, assign or donate the code to a third party and to inhibit third 69parties from using the code for products that do not conform to audiovisual and 70image-coding related ITU Recommendations and/or ISO/IEC International Standards. 71This copyright notice must be included in all copies or derivative works. 72Copyright (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_decode_envelope.h" 89#include "sbr_constants.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----------------------------------------------------------------------------*/ 107void mapLowResEnergyVal( 108 Int32 currVal, 109 Int32 *prevData, 110 Int32 offset, 111 Int32 index, 112 Int32 res); 113 114Int32 indexLow2High(Int32 offset, 115 Int32 index, 116 Int32 res); 117 118/*---------------------------------------------------------------------------- 119; LOCAL STORE/BUFFER/POINTER DEFINITIONS 120; Variable declaration - defined here and used outside this module 121----------------------------------------------------------------------------*/ 122 123/*---------------------------------------------------------------------------- 124; EXTERNAL FUNCTION REFERENCES 125; Declare functions defined elsewhere and referenced in this module 126----------------------------------------------------------------------------*/ 127 128/*---------------------------------------------------------------------------- 129; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 130; Declare variables used in this module but defined elsewhere 131----------------------------------------------------------------------------*/ 132 133/*---------------------------------------------------------------------------- 134; FUNCTION CODE 135----------------------------------------------------------------------------*/ 136 137 138void sbr_decode_envelope(SBR_FRAME_DATA * hFrameData) 139 140{ 141 Int32 i; 142 Int32 no_of_bands; 143 Int32 band; 144 Int32 freqRes; 145 Int32 *iEnvelope = hFrameData->iEnvelope_man; 146 Int32 *sfb_nrg_prev = hFrameData->sfb_nrg_prev_man; 147 148 Int32 offset = hFrameData->offset; 149 Int32 *nSfb = hFrameData->nSfb; 150 Int32 *domain_vec = hFrameData->domain_vec1; 151 Int32 *frameInfo = hFrameData->frameInfo; 152 153 154 155 for (i = 0; i < frameInfo[0]; i++) 156 { 157 freqRes = frameInfo[frameInfo[0] + i + 2]; 158 no_of_bands = nSfb[freqRes]; 159 160 if (domain_vec[i] == 0) 161 { 162 mapLowResEnergyVal(*iEnvelope, 163 sfb_nrg_prev, 164 offset, 165 0, 166 freqRes); 167 iEnvelope++; 168 169 for (band = 1; band < no_of_bands; band++) 170 { 171 *iEnvelope += *(iEnvelope - 1); 172 173 mapLowResEnergyVal(*iEnvelope, 174 sfb_nrg_prev, 175 offset, 176 band, 177 freqRes); 178 iEnvelope++; 179 } 180 } 181 else 182 { 183 for (band = 0; band < no_of_bands; band++) 184 { 185 *iEnvelope += sfb_nrg_prev[ indexLow2High(offset, band, freqRes)]; 186 187 mapLowResEnergyVal(*iEnvelope, 188 sfb_nrg_prev, 189 offset, 190 band, 191 freqRes); 192 iEnvelope++; 193 } 194 } 195 } 196} 197 198 199 200void mapLowResEnergyVal( 201 Int32 currVal, 202 Int32 *prevData, 203 Int32 offset, 204 Int32 index, 205 Int32 res) 206{ 207 Int32 tmp; 208 209 if (res == LO) 210 { 211 if (offset >= 0) 212 { 213 if (index < offset) 214 { 215 prevData[index] = currVal; 216 } 217 else 218 { 219 tmp = (index << 1) - offset; 220 prevData[tmp ] = currVal; 221 prevData[tmp +1 ] = currVal; 222 } 223 } 224 else 225 { 226 offset = -offset; 227 if (index < offset) 228 { 229 tmp = (index << 1) + index; 230 prevData[tmp ] = currVal; 231 prevData[tmp + 1] = currVal; 232 prevData[tmp + 2] = currVal; 233 } 234 else 235 { 236 tmp = (index << 1) + offset; 237 prevData[tmp ] = currVal; 238 prevData[tmp + 1] = currVal; 239 } 240 } 241 } 242 else 243 { 244 prevData[index] = currVal; 245 } 246} 247 248 249Int32 indexLow2High(Int32 offset, 250 Int32 index, 251 Int32 res) 252{ 253 if (res == LO) 254 { 255 if (offset >= 0) 256 { 257 if (index < offset) 258 { 259 return(index); 260 } 261 else 262 { 263 return((index << 1) - offset); 264 } 265 } 266 else 267 { 268 offset = -offset; 269 if (index < offset) 270 { 271 return((index << 1) + index); 272 } 273 else 274 { 275 return((index << 1) + offset); 276 } 277 } 278 } 279 else 280 { 281 return(index); 282 } 283} 284 285#endif 286 287