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: ./src/apply_ms_synt.c 21 22 23 ------------------------------------------------------------------------------ 24 REVISION HISTORY 25 26 Description: Updated pseudocode to correct capitalized format for the IF 27 FOR and WHILE statements. 28 29 Description: Delete local variable start_indx, since it is never used. 30 31 Who: Date: 32 Description: 33 ------------------------------------------------------------------------------ 34 INPUT AND OUTPUT DEFINITIONS 35 36 Inputs: 37 38 pFrameInfo = Pointer to structure that holds information about each group. 39 (long block flag, number of windows, scalefactor bands 40 per group, etc.) 41 [const pFrameInfo * const] 42 43 group = Array that contains indexes of the 44 first window in the next group. 45 [const Int *, length 8] 46 47 mask_map = Array that denotes whether M/S stereo is turned on for 48 each grouped scalefactor band. 49 [const Int *, length MAX_SFB] 50 51 codebook_map = Array that denotes which Huffman codebook was used for 52 the encoding of each grouped scalefactor band. 53 [const Int *, length MAX_SFB] 54 55 coefLeft = Array containing the fixed-point spectral coefficients 56 for the left channel. 57 [Int32 *, length 1024] 58 59 coefRight = Array containing the fixed-point spectral coefficients 60 for the right channel. 61 [Int32 *, length 1024] 62 63 q_formatLeft = The Q-format for the left channel's fixed-point spectral 64 coefficients, on a per-scalefactor band, non-grouped basis. 65 [Int *, length MAX_SFB] 66 67 q_formatRight = The Q-format for the right channel's fixed-point spectral 68 coefficients, on a per-scalefactor band, non-grouped basis. 69 [Int *, length MAX_SFB] 70 71 Local Stores/Buffers/Pointers Needed: 72 None 73 74 Global Stores/Buffers/Pointers Needed: 75 None 76 77 Outputs: 78 None 79 80 Pointers and Buffers Modified: 81 coefLeft = Contains the new spectral information. 82 83 coefRight = Contains the new spectral information. 84 85 q_formatLeft = Q-format may be updated with changed to fixed-point 86 data in coefLeft. 87 88 q_formatRight = Q-format may be updated with changed to fixed-point 89 data in coefRight. 90 91 Local Stores Modified: 92 None 93 94 Global Stores Modified: 95 None 96 97 ------------------------------------------------------------------------------ 98 FUNCTION DESCRIPTION 99 100 This function steps through all of the tools that are applied on a 101 scalefactor band basis. 102 103 The use of M/S stereo is checked for. For M/S decoding to take 104 place, ms_mask_map must be TRUE for that particular SFB, AND the Huffman 105 codebook used must be < NOISE_HCB. 106 107 ------------------------------------------------------------------------------ 108 REQUIREMENTS 109 110 111 ------------------------------------------------------------------------------ 112 REFERENCES 113 114 (1) ISO/IEC 14496-3:1999(E) 115 Part 3 116 Subpart 4.6.7.1 M/S stereo 117 Subpart 4.6.2 ScaleFactors 118 119 (2) MPEG-2 NBC Audio Decoder 120 "This software module was originally developed by AT&T, Dolby 121 Laboratories, Fraunhofer Gesellschaft IIS in the course of development 122 of the MPEG-2 NBC/MPEG-4 Audio standard ISO/IEC 13818-7, 14496-1,2 and 123 3. This software module is an implementation of a part of one or more 124 MPEG-2 NBC/MPEG-4 Audio tools as specified by the MPEG-2 NBC/MPEG-4 125 Audio standard. ISO/IEC gives users of the MPEG-2 NBC/MPEG-4 Audio 126 standards free license to this software module or modifications thereof 127 for use in hardware or software products claiming conformance to the 128 MPEG-2 NBC/MPEG-4 Audio standards. Those intending to use this software 129 module in hardware or software products are advised that this use may 130 infringe existing patents. The original developer of this software 131 module and his/her company, the subsequent editors and their companies, 132 and ISO/IEC have no liability for use of this software module or 133 modifications thereof in an implementation. Copyright is not released 134 for non MPEG-2 NBC/MPEG-4 Audio conforming products.The original 135 developer retains full right to use the code for his/her own purpose, 136 assign or donate the code to a third party and to inhibit third party 137 from using the code for non MPEG-2 NBC/MPEG-4 Audio conforming products. 138 This copyright notice must be included in all copies or derivative 139 works." 140 Copyright(c)1996. 141 142 ------------------------------------------------------------------------------ 143 PSEUDO-CODE 144 145 pCoefRight = coefRight; 146 pCoefLeft = coefLeft; 147 148 window_start = 0; 149 tot_sfb = 0; 150 151 coef_per_win = pFrameInfo->coef_per_win[0]; 152 153 sfb_per_win = pFrameInfo->sfb_per_win[0]; 154 155 DO 156 157 pBand = pFrameInfo->win_sfb_top[window_start]; 158 159 partition = *(pGroup); 160 161 pGroup = pGroup + 1; 162 163 band_start = 0; 164 165 wins_in_group = (partition - window_start); 166 167 FOR (sfb = sfb_per_win; sfb > 0; sfb--) 168 169 band_stop = *(pBand); 170 171 pBand = pBand + 1; 172 173 codebook = *(pCodebookMap); 174 175 pCodebookMap = pCodebookMap + 1; 176 177 mask_enabled = *(pMaskMap); 178 179 pMaskMap = pMaskMap + 1; 180 181 IF (codebook < NOISE_HCB) 182 THEN 183 IF (mask_enabled != FALSE) 184 THEN 185 band_length = band_stop - band_start; 186 187 CALL 188 ms_synt( 189 wins_in_group, 190 coef_per_win, 191 sfb_per_win, 192 band_length, 193 &(pCoefLeft[band_start]), 194 &(pCoefRight[band_start]), 195 &(q_formatLeft[tot_sfb]), 196 &(q_formatRight[tot_sfb]) ); 197 198 MODIFYING 199 &(pCoefLeft[band_start]), 200 &(pCoefRight[band_start]), 201 &(q_formatLeft[tot_sfb]), 202 &(q_formatRight[tot_sfb]) 203 204 RETURNING 205 None 206 ENDIF 207 ENDIF 208 band_start = band_stop; 209 210 tot_sfb = tot_sfb + 1; 211 212 ENDFOR 213 214 pCoefRight = pCoefRight + coef_per_win * wins_in_group; 215 pCoefLeft = pCoefLeft + coef_per_win * wins_in_group; 216 217 wins_in_group = wins_in_group - 1; 218 219 tot_sfb = tot_sfb + sfb_per_win * wins_in_group; 220 221 window_start = partition; 222 223 WHILE (partition < pFrameInfo->num_win); 224 225 return; 226 ------------------------------------------------------------------------------ 227 RESOURCES USED 228 When the code is written for a specific target processor the 229 resources used should be documented below. 230 231 STACK USAGE: [stack count for this module] + [variable to represent 232 stack usage for each subroutine called] 233 234 where: [stack usage variable] = stack usage for [subroutine 235 name] (see [filename].ext) 236 237 DATA MEMORY USED: x words 238 239 PROGRAM MEMORY USED: x words 240 241 CLOCK CYCLES: [cycle count equation for this module] + [variable 242 used to represent cycle count for each subroutine 243 called] 244 245 where: [cycle count variable] = cycle count for [subroutine 246 name] (see [filename].ext) 247 248 ------------------------------------------------------------------------------ 249 */ 250 251 252 /*---------------------------------------------------------------------------- 253 ; INCLUDES 254 ----------------------------------------------------------------------------*/ 255 #include "pv_audio_type_defs.h" 256 #include "apply_ms_synt.h" 257 #include "e_huffmanconst.h" 258 #include "ms_synt.h" 259 260 /*---------------------------------------------------------------------------- 261 ; MACROS 262 ; Define module specific macros here 263 ----------------------------------------------------------------------------*/ 264 265 /*---------------------------------------------------------------------------- 266 ; DEFINES 267 ; Include all pre-processor statements here. Include conditional 268 ; compile variables also. 269 ----------------------------------------------------------------------------*/ 270 271 /*---------------------------------------------------------------------------- 272 ; LOCAL FUNCTION DEFINITIONS 273 ; Function Prototype declaration 274 ----------------------------------------------------------------------------*/ 275 276 /*---------------------------------------------------------------------------- 277 ; LOCAL STORE/BUFFER/POINTER DEFINITIONS 278 ; Variable declaration - defined here and used outside this module 279 ----------------------------------------------------------------------------*/ 280 281 /*---------------------------------------------------------------------------- 282 ; EXTERNAL FUNCTION REFERENCES 283 ; Declare functions defined elsewhere and referenced in this module 284 ----------------------------------------------------------------------------*/ 285 286 287 /*---------------------------------------------------------------------------- 288 ; EXTERNAL GLOBAL STORE/BUFFER/POINTER REFERENCES 289 ; Declare variables used in this module but defined elsewhere 290 ----------------------------------------------------------------------------*/ 291 292 /*---------------------------------------------------------------------------- 293 ; FUNCTION CODE 294 ----------------------------------------------------------------------------*/ 295 296 void apply_ms_synt( 297 const FrameInfo * const pFrameInfo, 298 const Int group[], 299 const Bool mask_map[], 300 const Int codebook_map[], 301 Int32 coefLeft[], 302 Int32 coefRight[], 303 Int q_formatLeft[MAXBANDS], 304 Int q_formatRight[MAXBANDS]) 305 306 { 307 308 Int32 *pCoefRight; 309 310 Int32 *pCoefLeft; 311 312 Int tot_sfb; 313 Int sfb; 314 315 Int band_length; 316 Int band_start; 317 Int band_stop; 318 Int coef_per_win; 319 320 Int codebook; 321 Int partition; 322 Int window_start; 323 324 Int sfb_per_win; 325 Int wins_in_group; 326 327 const Int16 *pBand; 328 const Int *pCodebookMap = codebook_map; 329 const Int *pGroup = group; 330 const Bool *pMaskMap = mask_map; 331 332 Bool mask_enabled; 333 334 pCoefRight = coefRight; 335 pCoefLeft = coefLeft; 336 337 window_start = 0; 338 tot_sfb = 0; 339 340 /* 341 * Each window in the frame should have the same number of coef's, 342 * so coef_per_win is constant in all the loops 343 */ 344 coef_per_win = pFrameInfo->coef_per_win[0]; 345 346 /* 347 * Because the number of scalefactor bands per window should be 348 * constant for each frame, sfb_per_win can be determined outside 349 * of the loop. 350 * 351 * For 44.1 kHz sampling rate sfb_per_win = 14 for short windows 352 * sfb_per_win = 49 for long windows 353 */ 354 355 sfb_per_win = pFrameInfo->sfb_per_win[0]; 356 357 do 358 { 359 pBand = pFrameInfo->win_sfb_top[window_start]; 360 361 /* 362 * Partition is equal to the first window in the next group 363 * 364 * { Group 0 }{ Group 1 }{ Group 2 }{Group 3} 365 * [win 0][win 1][win 2][win 3][win 4][win 5][win 6][win 7] 366 * 367 * pGroup[0] = 2 368 * pGroup[1] = 5 369 * pGroup[2] = 7 370 * pGroup[3] = 8 371 */ 372 373 partition = *(pGroup++); 374 375 band_start = 0; 376 377 wins_in_group = (partition - window_start); 378 379 for (sfb = sfb_per_win; sfb > 0; sfb--) 380 { 381 /* band is offset table, band_stop is last coef in band */ 382 band_stop = *(pBand++); 383 384 codebook = *(pCodebookMap++); 385 386 mask_enabled = *(pMaskMap++); 387 388 /* 389 * When a codebook < NOISE_HCB is found, apply M/S to that 390 * scalefactorband. 391 * 392 * Example... sfb[3] == NOISE_HCB 393 * 394 * [ Group 1 ] 395 * [win 0 ][win 1 ] 396 * [0][1][2][X][4][5][6][7][0][1][2][X][4][5][6][7] 397 * 398 * The for(sfb) steps through the sfb's 0-7 in win 0. 399 * 400 * Finding sfb[3]'s codebook == NOISE_HCB, the code 401 * steps through all the windows in the group (they share 402 * the same scalefactors) and replaces that sfb with noise. 403 */ 404 405 if (codebook < NOISE_HCB) 406 { 407 if (mask_enabled != FALSE) 408 { 409 band_length = band_stop - band_start; 410 411 ms_synt( 412 wins_in_group, 413 coef_per_win, 414 sfb_per_win, 415 band_length, 416 &(pCoefLeft[band_start]), 417 &(pCoefRight[band_start]), 418 &(q_formatLeft[tot_sfb]), 419 &(q_formatRight[tot_sfb])); 420 } 421 } 422 band_start = band_stop; 423 424 tot_sfb++; 425 426 } /* for (sfb) */ 427 428 /* 429 * Increment pCoefRight and pCoefLeft by 430 * coef_per_win * the number of windows 431 */ 432 433 pCoefRight += coef_per_win * wins_in_group; 434 pCoefLeft += coef_per_win * wins_in_group--; 435 436 /* 437 * Increase tot_sfb by sfb_per_win times the number of windows minus 1. 438 * The minus 1 comes from the fact that tot_sfb is already pointing 439 * to the first sfb in the 2nd window of the group. 440 */ 441 tot_sfb += sfb_per_win * wins_in_group; 442 443 window_start = partition; 444 445 } 446 while (partition < pFrameInfo->num_win); 447 448 /* pFrameInfo->num_win = 1 for long windows, 8 for short_windows */ 449 450 return; 451 452 } /* apply_ms_synt() */ 453 454 455