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: getgroup.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: (1) Modified to bring code in-line with PV standards 31 (2) Eliminated if(first_short) statement, move for-loop 32 inside if statement 33 (3) Modified UChar -> Int on data types of group 34 35 Description: Replace some instances of getbits to get9_n_lessbits 36 when the number of bits read is 9 or less. 37 38 Who: Date: MM/DD/YYYY 39 Description: 40 41 ------------------------------------------------------------------------------ 42 INPUT AND OUTPUT DEFINITIONS 43 44 Inputs: 45 pInputStream = pointer to structure that holds input bitstream 46 information. Type BITS 47 48 group[] = array that holds the index of the first window in each 49 group. Type Int 50 51 Local Stores/Buffers/Pointers Needed: 52 None 53 54 Global Stores/Buffers/Pointers Needed: 55 None 56 57 Outputs: 58 None 59 60 Pointers and Buffers Modified: 61 group contains the index of first windows in each group 62 63 Local Stores Modified: 64 None 65 66 Global Stores Modified: 67 None 68 69 ------------------------------------------------------------------------------ 70 FUNCTION DESCRIPTION 71 72 This function reads the window grouping information associated with an 73 Individual Channel Stream (ICS). If the window sequence is 74 EIGHT_SHORT_SEQUENCE, scalefactor grouping information is transmitted. If a 75 set of short windows form a group then they share scalefactors, intensity 76 positions and PNS information. The first short window is always a new group 77 so no grouping bit is transmitted. Subsequent short windows are in the same 78 group if the associated grouping bit is 1. A new group is started if the 79 associated grouping bit is 0. 80 The pointer pGroup points to an array that stores the first window index 81 of next group. For example, if the window grouping is: 82 83 window index: | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 84 grouping : |<- 0 ->| 1 |<- 2 ->|<- 3 ->| 85 86 Then: 87 88 group[] : | 2 | 3 | 6 | 8 | 89 90 ------------------------------------------------------------------------------ 91 REQUIREMENTS 92 93 This function should replace the contents of the array pointed to by pGroup 94 with the first window indexes of groups starting from the second group. 95 96 ------------------------------------------------------------------------------ 97 REFERENCES 98 99 (1) MPEG-2 NBC Audio Decoder 100 "This software module was originally developed by AT&T, Dolby 101 Laboratories, Fraunhofer Gesellschaft IIS in the course of development 102 of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 103 3. This software module is an implementation of a part of one or more 104 MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 105 Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio 106 standards free license to this software module or modifications thereof 107 for use in hardware or software products claiming conformance to the 108 MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software 109 module in hardware or software products are advised that this use may 110 infringe existing patents. The original developer of this software 111 module and his/her company, the subsequent editors and their companies, 112 and ISO/IEC have no liability for use of this software module or 113 modifications thereof in an implementation. Copyright is not released 114 for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original 115 developer retains full right to use the code for his/her own purpose, 116 assign or donate the code to a third party and to inhibit third party 117 from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products. 118 This copyright notice must be included in all copies or derivative 119 works." 120 Copyright(c)1996. 121 122 (2) ISO/IEC 14496-3: 1999(E) 123 Subpart 4 124 p16 (Table 4.4.6) 125 p55 (Recovering ics_info) 126 127 ------------------------------------------------------------------------------ 128 PSEUDO-CODE 129 130 IF (pFrameInfo->coef_per_win[0] > SN2) 131 132 *pGroup++ = 1; 133 *pGroup = 1; 134 135 ELSE 136 137 FOR (win = 1; win < pFrameInfo->num_win; win++) 138 139 IF (getbits(1,pInputStream) == 0) 140 141 *pGroup++ = win; 142 143 ENDIF 144 145 ENDFOR (win) 146 147 *pGroup = win; 148 149 ENDIF(pFrameInfo) 150 151 ------------------------------------------------------------------------------ 152 RESOURCES USED 153 When the code is written for a specific target processor the 154 the resources used should be documented below. 155 156 STACK USAGE: [stack count for this module] + [variable to represent 157 stack usage for each subroutine called] 158 159 where: [stack usage variable] = stack usage for [subroutine 160 name] (see [filename].ext) 161 162 DATA MEMORY USED: x words 163 164 PROGRAM MEMORY USED: x words 165 166 CLOCK CYCLES: [cycle count equation for this module] + [variable 167 used to represent cycle count for each subroutine 168 called] 169 170 where: [cycle count variable] = cycle count for [subroutine 171 name] (see [filename].ext) 172 173 ------------------------------------------------------------------------------ 174 */ 175 176 /*---------------------------------------------------------------------------- 177 ; INCLUDES 178 ----------------------------------------------------------------------------*/ 179 #include "pv_audio_type_defs.h" 180 #include "huffman.h" 181 182 /*---------------------------------------------------------------------------- 183 ; MACROS 184 ; Define module specific macros here 185 ----------------------------------------------------------------------------*/ 186 187 /*---------------------------------------------------------------------------- 188 ; DEFINES 189 ; Include all pre-processor statements here. Include conditional 190 ; compile variables also. 191 ----------------------------------------------------------------------------*/ 192 #define SEVEN 7 193 194 /*---------------------------------------------------------------------------- 195 ; LOCAL FUNCTION DEFINITIONS 196 ; Function Prototype declaration 197 ----------------------------------------------------------------------------*/ 198 199 /*---------------------------------------------------------------------------- 200 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS 201 ; Variable declaration - defined here and used outside this module 202 ----------------------------------------------------------------------------*/ 203 204 /*---------------------------------------------------------------------------- 205 ; EXTERNAL FUNCTION REFERENCES 206 ; Declare functions defined elsewhere and referenced in this module 207 ----------------------------------------------------------------------------*/ 208 209 /*---------------------------------------------------------------------------- 210 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 211 ; Declare variables used in this module but defined elsewhere 212 ----------------------------------------------------------------------------*/ 213 214 /*---------------------------------------------------------------------------- 215 ; FUNCTION CODE 216 ----------------------------------------------------------------------------*/ 217 void getgroup( 218 Int group[], 219 BITS *pInputStream) 220 { 221 Int win; 222 Int *pGroup; 223 UInt mask; 224 UInt groupBits; 225 226 pGroup = group; 227 228 mask = 0x40; 229 230 /* only short-window sequences are grouped! 231 * first short window is always a new group, 232 * start reading bitstream from the second 233 * window, a new group is indicated by an 234 * "0" bit in the input stream 235 */ 236 groupBits = 237 get9_n_lessbits( 238 SEVEN, 239 pInputStream); 240 241 for (win = 1; win < NUM_SHORT_WINDOWS; win++) 242 { 243 if ((groupBits & mask) == 0) 244 { 245 *pGroup++ = win; 246 247 } /* if (groupBits) */ 248 249 mask >>= 1; 250 251 } /* for (win) */ 252 253 *pGroup = win; 254 255 } /* getgroup */ 256