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_get_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 Arguments: h_frame_data - handle to struct SBR_FRAME_DATA 33 hBitBuf - handle to struct BIT_BUF 34 channel - channel number 35 36 Return: void 37 38 39------------------------------------------------------------------------------ 40 FUNCTION DESCRIPTION 41 42 Reads envelope data from bitstream 43 44------------------------------------------------------------------------------ 45 REQUIREMENTS 46 47 48------------------------------------------------------------------------------ 49 REFERENCES 50 51SC 29 Software Copyright Licencing Disclaimer: 52 53This software module was originally developed by 54 Coding Technologies 55 56and edited by 57 - 58 59in the course of development of the ISO/IEC 13818-7 and ISO/IEC 14496-3 60standards for reference purposes and its performance may not have been 61optimized. This software module is an implementation of one or more tools as 62specified by the ISO/IEC 13818-7 and ISO/IEC 14496-3 standards. 63ISO/IEC gives users free license to this software module or modifications 64thereof for use in products claiming conformance to audiovisual and 65image-coding related ITU Recommendations and/or ISO/IEC International 66Standards. ISO/IEC gives users the same free license to this software module or 67modifications thereof for research purposes and further ISO/IEC standardisation. 68Those intending to use this software module in products are advised that its 69use may infringe existing patents. ISO/IEC have no liability for use of this 70software module or modifications thereof. Copyright is not released for 71products that do not conform to audiovisual and image-coding related ITU 72Recommendations and/or ISO/IEC International Standards. 73The original developer retains full right to modify and use the code for its 74own purpose, assign or donate the code to a third party and to inhibit third 75parties from using the code for products that do not conform to audiovisual and 76image-coding related ITU Recommendations and/or ISO/IEC International Standards. 77This copyright notice must be included in all copies or derivative works. 78Copyright (c) ISO/IEC 2002. 79 80------------------------------------------------------------------------------ 81 PSEUDO-CODE 82 83------------------------------------------------------------------------------ 84*/ 85 86 87/*---------------------------------------------------------------------------- 88; INCLUDES 89----------------------------------------------------------------------------*/ 90 91#ifdef AAC_PLUS 92 93 94#include "sbr_get_envelope.h" 95#include "s_huffman.h" 96#include "e_coupling_mode.h" 97#include "sbr_code_book_envlevel.h" 98#include "buf_getbits.h" 99#include "sbr_decode_huff_cw.h" 100 101 102/*---------------------------------------------------------------------------- 103; MACROS 104; Define module specific macros here 105----------------------------------------------------------------------------*/ 106 107 108/*---------------------------------------------------------------------------- 109; DEFINES 110; Include all pre-processor statements here. Include conditional 111; compile variables also. 112----------------------------------------------------------------------------*/ 113 114/*---------------------------------------------------------------------------- 115; LOCAL FUNCTION DEFINITIONS 116; Function Prototype declaration 117----------------------------------------------------------------------------*/ 118 119/*---------------------------------------------------------------------------- 120; LOCAL STORE/BUFFER/POINTER DEFINITIONS 121; Variable declaration - defined here and used outside this module 122----------------------------------------------------------------------------*/ 123 124/*---------------------------------------------------------------------------- 125; EXTERNAL FUNCTION REFERENCES 126; Declare functions defined elsewhere and referenced in this module 127----------------------------------------------------------------------------*/ 128 129/*---------------------------------------------------------------------------- 130; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 131; Declare variables used in this module but defined elsewhere 132----------------------------------------------------------------------------*/ 133 134/*---------------------------------------------------------------------------- 135; FUNCTION CODE 136----------------------------------------------------------------------------*/ 137 138void sbr_get_envelope(SBR_FRAME_DATA * h_frame_data, 139 BIT_BUFFER * hBitBuf) 140{ 141 Int32 i; 142 Int32 j; 143 Int32 tmp; 144 Int32 no_band[MAX_ENVELOPES]; 145 Int32 delta = 0; 146 Int32 offset = 0; 147 Int32 ampRes; 148 Int32 envDataTableCompFactor; 149 Int32 start_bits; 150 Int32 start_bits_balance; 151 SbrHuffman hcb_t; 152 SbrHuffman hcb_f; 153 COUPLING_MODE coupling = h_frame_data->coupling; 154 155 h_frame_data->nScaleFactors = 0; 156 157 if ((h_frame_data->frameClass == FIXFIX) && 158 (h_frame_data->frameInfo[0] == 1)) 159 { 160 h_frame_data->ampRes = SBR_AMP_RES_1_5; 161 } 162 else 163 { 164 h_frame_data->ampRes = h_frame_data->sbr_header.ampResolution; 165 } 166 167 ampRes = h_frame_data->ampRes; 168 169 /* 170 * Set number of bits for first value depending on amplitude resolution 171 */ 172 if (ampRes == SBR_AMP_RES_3_0) 173 { 174 start_bits = SI_SBR_START_ENV_BITS_AMP_RES_3_0; 175 start_bits_balance = SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_3_0; 176 } 177 else 178 { 179 start_bits = SI_SBR_START_ENV_BITS_AMP_RES_1_5; 180 start_bits_balance = SI_SBR_START_ENV_BITS_BALANCE_AMP_RES_1_5; 181 } 182 183 /* 184 * Calculate number of values for each envelope and alltogether 185 */ 186 for (i = 0; i < h_frame_data->frameInfo[0]; i++) 187 { 188 no_band[i] = 189 h_frame_data->nSfb[h_frame_data->frameInfo[h_frame_data->frameInfo[0] + 2 + i]]; 190 h_frame_data->nScaleFactors += no_band[i]; 191 } 192 193 194 /* 195 * Select huffman codebook depending on coupling mode and amplitude resolution 196 */ 197 if (coupling == COUPLING_BAL) 198 { 199 envDataTableCompFactor = 1; 200 if (ampRes == SBR_AMP_RES_1_5) 201 { 202 hcb_t = bookSbrEnvBalance10T; 203 hcb_f = bookSbrEnvBalance10F; 204 } 205 else 206 { 207 hcb_t = bookSbrEnvBalance11T; 208 hcb_f = bookSbrEnvBalance11F; 209 } 210 } 211 else 212 { 213 envDataTableCompFactor = 0; 214 if (ampRes == SBR_AMP_RES_1_5) 215 { 216 hcb_t = bookSbrEnvLevel10T; 217 hcb_f = bookSbrEnvLevel10F; 218 } 219 else 220 { 221 hcb_t = bookSbrEnvLevel11T; 222 hcb_f = bookSbrEnvLevel11F; 223 } 224 } 225 226 /* 227 * Now read raw envelope data 228 */ 229 for (j = 0; j < h_frame_data->frameInfo[0]; j++) 230 { 231 if (h_frame_data->domain_vec1[j] == FREQ) 232 { 233 if (coupling == COUPLING_BAL) 234 { 235 tmp = buf_getbits(hBitBuf, start_bits_balance); 236 h_frame_data->iEnvelope_man[offset] = tmp << envDataTableCompFactor; 237 } 238 else 239 { 240 tmp = buf_getbits(hBitBuf, start_bits); 241 h_frame_data->iEnvelope_man[offset] = tmp; 242 } 243 } 244 245 for (i = (1 - h_frame_data->domain_vec1[j]); i < no_band[j]; i++) 246 { 247 248 if (h_frame_data->domain_vec1[j] == FREQ) 249 { 250 delta = sbr_decode_huff_cw(hcb_f, hBitBuf); 251 } 252 else 253 { 254 delta = sbr_decode_huff_cw(hcb_t, hBitBuf); 255 } 256 257 h_frame_data->iEnvelope_man[offset + i] = delta << envDataTableCompFactor; 258 } 259 offset += no_band[j]; 260 } 261 262} 263 264#endif 265 266