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 Pathname: get_pulse_data.c 21 22 ------------------------------------------------------------------------------ 23 REVISION HISTORY 24 25 Description: Modified from original shareware code 26 27 Description: Modified to pass variables by reference to eliminate use 28 of global variables. 29 30 Description: Put into PV format 31 32 Description: 1) Change loop to use pointers. 33 2) Rename to from get_nec_nc to get_pulse_data 34 35 Description: Changes per code review 36 1) Fix pathname 37 2) Read in two fields to save call to getbits 38 3) Change how pPulseInfo->number_pulse is stored. 39 40 Description: Placed typecast to Int in places where UInt->Int 41 42 Description: Replace some instances of getbits to get9_n_lessbits 43 when the number of bits read is 9. 44 45 Who: Date: 46 Description: 47 ------------------------------------------------------------------------------ 48 INPUT AND OUTPUT DEFINITIONS 49 50 Inputs: 51 pInputStream = pointer to a BITS structure, used by the function getbits 52 to provide data. Data type pointer to BITS structure 53 54 pPulseInfo = pointer to pulse data structure to be filled with data 55 concerning pulses in the frequency domain. 56 Data type pointer to PulseInfo 57 58 Local Stores/Buffers/Pointers Needed: None 59 60 Global Stores/Buffers/Pointers Needed: None 61 62 Outputs: 63 status = return value, zero signifies success, non-zero otherwise. 64 Presently this function only returns a success, error 65 checking may be added later. 66 Data type Int. 67 68 Pointers and Buffers Modified: 69 70 pPulseInfo contents are updated with pulse information. Specifically, 71 pPulseInfo->number_pulse with the number of pulses found, and 72 pPulseInfo->pulse_start_sfb is set to the first scale factor band. 73 Then pPulseInfo->pulse_offset and pPulseInfo->pulse_amp are filled 74 with data. For these array, only the number of pulses defined will be 75 set, those values beyond the number of pulses will retain their previous 76 value and should not be read from. 77 Note: The value in pPulseInfo->number_pulse is different by a value of 78 one from the original ISO code. 79 80 pInputBuffer contents are updated to the next location to be read from 81 the input stream. 82 83 Local Stores Modified: None 84 85 Global Stores Modified: None 86 87 ------------------------------------------------------------------------------ 88 FUNCTION DESCRIPTION 89 90 This function fills in the pulse data structure with information to be used 91 later for restoring pulses in the spectrum. 92 93 ------------------------------------------------------------------------------ 94 REQUIREMENTS 95 96 This function shall not use global or static variables. 97 98 ------------------------------------------------------------------------------ 99 REFERENCES 100 101 (1) ISO/IEC 13818-7:1997 Titled "Information technology - Generic coding 102 of moving pictures and associated audio information - Part 7: Advanced 103 Audio Coding (AAC)", Table 6.17 - Syntax of pulse_data(), 104 page 15, and section 9.3 "Decoding process", starting on page 41. 105 106 107 (2) MPEG-2 NBC Audio Decoder 108 "This software module was originally developed by AT&T, Dolby 109 Laboratories, Fraunhofer Gesellschaft IIS in the course of development 110 of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 111 3. This software module is an implementation of a part of one or more 112 MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 113 Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio 114 standards free license to this software module or modifications thereof 115 for use in hardware or software products claiming conformance to the 116 MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software 117 module in hardware or software products are advised that this use may 118 infringe existing patents. The original developer of this software 119 module and his/her company, the subsequent editors and their companies, 120 and ISO/IEC have no liability for use of this software module or 121 modifications thereof in an implementation. Copyright is not released 122 for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original 123 developer retains full right to use the code for his/her own purpose, 124 assign or donate the code to a third party and to inhibit third party 125 from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products. 126 This copyright notice must be included in all copies or derivative 127 works." 128 Copyright(c)1996. 129 130 ------------------------------------------------------------------------------ 131 PSEUDO-CODE 132 133 status = SUCCESS; 134 135 CALL getbits(neededBits = LEN_PULSE_NPULSE + LEN_PULSE_ST_SFB, 136 pInputStream = pInputStream) 137 MODIFYING(*pInputStream) 138 RETURNING(temp) 139 140 pPulseInfo->number_pulse = 1 + (temp >> LEN_PULSE_ST_SFB); 141 pPulseInfo->pulse_start_sfb = temp & ((1 << LEN_PULSE_ST_SFB) - 1); 142 143 pPulseOffset = &pPulseInfo->pulse_offset[0]; 144 pPulseAmp = &pPulseInfo->pulse_amp[0]; 145 146 FOR (i = PulseInfo->number_pulse; i > 0; i--) 147 CALL getbits(neededBits = LEN_PULSE_POFF + LEN_PULSE_PAMP, 148 pInputStream = pInputStream) 149 MODIFYING(*pInputStream) 150 RETURNING(temp) 151 152 *pPulseOffset++ = temp >> LEN_PULSE_PAMP; 153 *pPulseAmp++ = temp & ((1 << LEN_PULSE_PAMP) - 1); 154 END FOR 155 156 MODIFYING (*pInputStream) 157 MODIFYING (*pPulseInfo) 158 159 RETURN status 160 161 ------------------------------------------------------------------------------ 162 RESOURCES USED 163 When the code is written for a specific target processor the 164 the resources used should be documented below. 165 166 STACK USAGE: [stack count for this module] + [variable to represent 167 stack usage for each subroutine called] 168 169 where: [stack usage variable] = stack usage for [subroutine 170 name] (see [filename].ext) 171 172 DATA MEMORY USED: x words 173 174 PROGRAM MEMORY USED: x words 175 176 CLOCK CYCLES: [cycle count equation for this module] + [variable 177 used to represent cycle count for each subroutine 178 called] 179 180 where: [cycle count variable] = cycle count for [subroutine 181 name] (see [filename].ext) 182 183 ------------------------------------------------------------------------------ 184 */ 185 186 187 /*---------------------------------------------------------------------------- 188 ; INCLUDES 189 ----------------------------------------------------------------------------*/ 190 191 #include "pv_audio_type_defs.h" 192 #include "ibstream.h" 193 #include "s_pulseinfo.h" 194 #include "s_bits.h" 195 #include "e_rawbitstreamconst.h" 196 #include "get_pulse_data.h" 197 198 199 /*---------------------------------------------------------------------------- 200 ; MACROS 201 ; Define module specific macros here 202 ----------------------------------------------------------------------------*/ 203 204 /*---------------------------------------------------------------------------- 205 ; DEFINES 206 ; Include all pre-processor statements here. Include conditional 207 ; compile variables also. 208 ----------------------------------------------------------------------------*/ 209 210 /*---------------------------------------------------------------------------- 211 ; LOCAL FUNCTION DEFINITIONS 212 ; Function Prototype declaration 213 ----------------------------------------------------------------------------*/ 214 215 /*---------------------------------------------------------------------------- 216 ; LOCAL VARIABLE DEFINITIONS 217 ; Variable declaration - defined here and used outside this module 218 ----------------------------------------------------------------------------*/ 219 220 /*---------------------------------------------------------------------------- 221 ; EXTERNAL FUNCTION REFERENCES 222 ; Declare functions defined elsewhere and referenced in this module 223 ----------------------------------------------------------------------------*/ 224 225 /*---------------------------------------------------------------------------- 226 ; EXTERNAL VARIABLES REFERENCES 227 ; Declare variables used in this module but defined elsewhere 228 ----------------------------------------------------------------------------*/ 229 230 /*---------------------------------------------------------------------------- 231 ; FUNCTION CODE 232 ----------------------------------------------------------------------------*/ 233 Int get_pulse_data( 234 PulseInfo *pPulseInfo, 235 BITS *pInputStream) 236 { 237 Int i; 238 Int *pPulseOffset; 239 Int *pPulseAmp; 240 Int status = SUCCESS; 241 UInt temp; 242 243 /* 244 * Read in both field fields at once to save cycles. These are the 245 * original lines of code: 246 * pPulseInfo->number_pulse = getbits(LEN_PULSE_NPULSE, pInputStream); 247 * pPulseInfo->pulse_start_sfb = getbits(LEN_PULSE_ST_SFB, pInputStream); 248 */ 249 250 temp = 251 get9_n_lessbits( 252 LEN_PULSE_NPULSE + LEN_PULSE_ST_SFB, 253 pInputStream); 254 255 pPulseInfo->number_pulse = (Int)(1 + (temp >> LEN_PULSE_ST_SFB)); 256 pPulseInfo->pulse_start_sfb = (Int)(temp & ((1 << LEN_PULSE_ST_SFB) - 1)); 257 258 pPulseOffset = &pPulseInfo->pulse_offset[0]; 259 pPulseAmp = &pPulseInfo->pulse_amp[0]; 260 261 /* 262 * This loop needs to count one more than the number read in from 263 * the bitstream - look at reference [1]. 264 */ 265 266 for (i = pPulseInfo->number_pulse; i > 0; i--) 267 { 268 /* 269 * Read in both fields. Original lines: 270 * *pPulseOffset++ = getbits(LEN_PULSE_POFF, pInputStream); 271 * *pPulseAmp++ = getbits(LEN_PULSE_PAMP, pInputStream); 272 */ 273 274 temp = 275 get9_n_lessbits( 276 LEN_PULSE_POFF + LEN_PULSE_PAMP, 277 pInputStream); 278 279 *pPulseOffset++ = (Int)(temp >> LEN_PULSE_PAMP); 280 281 *pPulseAmp++ = (Int)(temp & ((1 << LEN_PULSE_PAMP) - 1)); 282 } 283 284 return (status); 285 } 286 287