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_requantize_envelope_data.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_constants.h" 89 #include "sbr_requantize_envelope_data.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 #define R_SHIFT 30 103 #define Qfmt(x) (Int32)(x*((Int32)1<<R_SHIFT) + (x>=0?0.5F:-0.5F)) 104 /*---------------------------------------------------------------------------- 105 ; LOCAL FUNCTION DEFINITIONS 106 ; Function Prototype declaration 107 ----------------------------------------------------------------------------*/ 108 109 /*---------------------------------------------------------------------------- 110 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS 111 ; Variable declaration - defined here and used outside this module 112 ----------------------------------------------------------------------------*/ 113 114 /*---------------------------------------------------------------------------- 115 ; EXTERNAL FUNCTION REFERENCES 116 ; Declare functions defined elsewhere and referenced in this module 117 ----------------------------------------------------------------------------*/ 118 119 /*---------------------------------------------------------------------------- 120 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 121 ; Declare variables used in this module but defined elsewhere 122 ----------------------------------------------------------------------------*/ 123 124 /*---------------------------------------------------------------------------- 125 ; FUNCTION CODE 126 ----------------------------------------------------------------------------*/ 127 128 void sbr_requantize_envelope_data(SBR_FRAME_DATA * hFrameData) 129 130 { 131 Int32 i; 132 133 134 Int32 nScaleFactors = hFrameData->nScaleFactors; 135 Int32 nNoiseFactors = hFrameData->nNoiseFactors; 136 Int32 ampRes = hFrameData->ampRes; 137 Int32 *iEnvelope_man = hFrameData->iEnvelope_man; 138 Int32 *iEnvelope_exp = hFrameData->iEnvelope_exp; 139 Int32 *sbrNoiseFloorLevel_man = hFrameData->sbrNoiseFloorLevel_man; 140 Int32 *sbrNoiseFloorLevel_exp = hFrameData->sbrNoiseFloorLevel_exp; 141 142 /* 143 * ampRes could be 0 (resolution step = 1.5 dB) or 144 * 1 (resolution step = 3 dB) 145 */ 146 if (ampRes) 147 { 148 /* iEnvelope[i] always positive 6 bits max */ 149 for (i = 0; i < nScaleFactors; i++) 150 { 151 152 iEnvelope_exp[i] = iEnvelope_man[i] + 6; 153 iEnvelope_man[i] = Qfmt(1.000F); 154 } 155 } 156 else 157 { 158 /* iEnvelope[i] always positive 7 bits max */ 159 for (i = 0; i < nScaleFactors; i++) 160 { 161 iEnvelope_exp[i] = (iEnvelope_man[i] >> 1) + 6; 162 if (iEnvelope_man[i] & 0x1) /* odd */ 163 { 164 iEnvelope_man[i] = Qfmt(1.41421356237310F); 165 } 166 else 167 { 168 iEnvelope_man[i] = Qfmt(1.000F); 169 } 170 } 171 172 } 173 for (i = 0; i < nNoiseFactors; i++) 174 { 175 /* sbrNoiseFloorLevel[i] varies from -31 to 31 if no coupling is used */ 176 177 sbrNoiseFloorLevel_exp[i] = NOISE_FLOOR_OFFSET - sbrNoiseFloorLevel_man[i]; 178 sbrNoiseFloorLevel_man[i] = 0x40000000; 179 } 180 } 181 182 #endif 183 184