Changeset 219 for libmpc/branches/r2d/libmpcdec/mpc_decoder.c
- Timestamp:
- 02/17/07 16:14:53 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libmpc/branches/r2d/libmpcdec/mpc_decoder.c
r203 r219 34 34 /// \file mpc_decoder.c 35 35 /// Core decoding routines and logic. 36 #include <string.h> 36 37 37 #include <mpc/mpcdec.h> 38 38 #include <mpc/minimax.h> … … 42 42 #include "math.h" 43 43 #include "requant.h" 44 45 mpc_uint32_t mpc_bits_read(mpc_bits_reader * r, const unsigned int nb_bits); 46 mpc_int32_t mpc_bits_huff_dec(mpc_bits_reader * r, const mpc_huffman *Table); 47 mpc_uint32_t mpc_bits_enum_dec(mpc_bits_reader * r, mpc_uint_t k, mpc_uint_t n); 48 mpc_uint32_t mpc_bits_log_dec(mpc_bits_reader * r, mpc_uint_t max); 44 #include "mpc_bits_reader.h" 49 45 50 46 //SV7 tables … … 233 229 if ( d->Res_L [Band] ) { 234 230 if ( d->Res_R [Band] ) { // M!=0, S!=0 235 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][0]);236 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][0]);231 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); 232 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); 237 233 for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { 238 234 *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); 239 235 *YR = templ - tempr; 240 236 } 241 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][1]);242 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][1]);237 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); 238 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); 243 239 for ( ; n < 24; n++, YL += 32, YR += 32 ) { 244 240 *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); 245 241 *YR = templ - tempr; 246 242 } 247 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][2]);248 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][2]);243 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); 244 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); 249 245 for ( ; n < 36; n++, YL += 32, YR += 32 ) { 250 246 *YL = (templ = MPC_MULTIPLY_FLOAT_INT(facL,*L++))+(tempr = MPC_MULTIPLY_FLOAT_INT(facR,*R++)); … … 252 248 } 253 249 } else { // M!=0, S==0 254 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][0]);250 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); 255 251 for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { 256 252 *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); 257 253 } 258 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][1]);254 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); 259 255 for ( ; n < 24; n++, YL += 32, YR += 32 ) { 260 256 *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); 261 257 } 262 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][2]);258 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); 263 259 for ( ; n < 36; n++, YL += 32, YR += 32 ) { 264 260 *YR = *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); … … 268 264 if (d->Res_R[Band]) // M==0, S!=0 269 265 { 270 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][0]);266 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); 271 267 for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { 272 268 *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); 273 269 } 274 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][1]);270 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); 275 271 for ( ; n < 24; n++, YL += 32, YR += 32 ) { 276 272 *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); 277 273 } 278 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][2]);274 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); 279 275 for ( ; n < 36; n++, YL += 32, YR += 32 ) { 280 276 *YR = - (*YL = MPC_MULTIPLY_FLOAT_INT(facR,*(R++))); … … 291 287 if ( d->Res_L [Band] ) { 292 288 if ( d->Res_R [Band] ) { // L!=0, R!=0 293 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][0]);294 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][0]);289 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); 290 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); 295 291 for (n = 0; n < 12; n++, YL += 32, YR += 32 ) { 296 292 *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); 297 293 *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); 298 294 } 299 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][1]);300 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][1]);295 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); 296 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); 301 297 for (; n < 24; n++, YL += 32, YR += 32 ) { 302 298 *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); 303 299 *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); 304 300 } 305 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][2]);306 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][2]);301 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); 302 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); 307 303 for (; n < 36; n++, YL += 32, YR += 32 ) { 308 304 *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); … … 310 306 } 311 307 } else { // L!=0, R==0 312 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][0]);308 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][0] & 0xFF); 313 309 for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { 314 310 *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); 315 311 *YR = 0; 316 312 } 317 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][1]);313 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][1] & 0xFF); 318 314 for ( ; n < 24; n++, YL += 32, YR += 32 ) { 319 315 *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); 320 316 *YR = 0; 321 317 } 322 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , (mpc_uint8_t) d->SCF_Index_L[Band][2]);318 facL = MPC_MULTIPLY_SCF( Cc[d->Res_L[Band]] , d->SCF_Index_L[Band][2] & 0xFF); 323 319 for ( ; n < 36; n++, YL += 32, YR += 32 ) { 324 320 *YL = MPC_MULTIPLY_FLOAT_INT(facL,*L++); … … 329 325 else { 330 326 if ( d->Res_R [Band] ) { // L==0, R!=0 331 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][0]);327 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][0] & 0xFF); 332 328 for ( n = 0; n < 12; n++, YL += 32, YR += 32 ) { 333 329 *YL = 0; 334 330 *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); 335 331 } 336 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][1]);332 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][1] & 0xFF); 337 333 for ( ; n < 24; n++, YL += 32, YR += 32 ) { 338 334 *YL = 0; 339 335 *YR = MPC_MULTIPLY_FLOAT_INT(facR,*R++); 340 336 } 341 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , (mpc_uint8_t) d->SCF_Index_R[Band][2]);337 facR = MPC_MULTIPLY_SCF( Cc[d->Res_R[Band]] , d->SCF_Index_R[Band][2] & 0xFF); 342 338 for ( ; n < 36; n++, YL += 32, YR += 32 ) { 343 339 *YL = 0; … … 619 615 do { 620 616 mpc_int32_t k = 0, idx = 1; 621 switch (Res) { 622 case -1: 623 for ( ; k<36; k++ ) { 624 mpc_uint32_t tmp = mpc_random_int(d); 625 q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; 626 } 627 break; 628 case 0: 629 break; 630 case 1: 631 Table = mpc_table_HuffQ_8 [0][0]; 632 for( ; k < 36; ){ 633 int kmax = k + 18; 634 mpc_uint_t cnt = mpc_bits_huff_dec(r, Table); 635 idx = 0; 636 if (cnt > 0 && cnt < 18) 637 idx = mpc_bits_enum_dec(r, cnt <= 9 ? cnt : 18 - cnt, 18); 638 if (cnt > 9) idx = ~idx; 639 for ( ; k < kmax; k++) { 640 q[k] = 0; 641 if ( idx & (1 << 17) ) 642 q[k] = (mpc_bits_read(r, 1) << 1) - 1; 643 idx <<= 1; 644 } 645 } 646 break; 647 case 2: 617 if (Res != 0) { 618 if (Res == 2) { 648 619 Tables[0] = mpc_table_HuffQ_8 [0][1]; 649 620 Tables[1] = mpc_table_HuffQ_8 [1][1]; … … 656 627 idx = (idx >> 1) + HuffQ2_var[tmp]; 657 628 } 658 break; 659 case 3: 660 case 4: 629 } else if (Res == 1) { 630 Table = mpc_table_HuffQ_8 [0][0]; 631 for( ; k < 36; ){ 632 int kmax = k + 18; 633 mpc_uint_t cnt = mpc_bits_huff_dec(r, Table); 634 idx = 0; 635 if (cnt > 0 && cnt < 18) 636 idx = mpc_bits_enum_dec(r, cnt <= 9 ? cnt : 18 - cnt, 18); 637 if (cnt > 9) idx = ~idx; 638 for ( ; k < kmax; k++) { 639 q[k] = 0; 640 if ( idx & (1 << 17) ) 641 q[k] = (mpc_bits_read(r, 1) << 1) - 1; 642 idx <<= 1; 643 } 644 } 645 } else if (Res == -1) { 646 for ( ; k<36; k++ ) { 647 mpc_uint32_t tmp = mpc_random_int(d); 648 q[k] = ((tmp >> 24) & 0xFF) + ((tmp >> 16) & 0xFF) + ((tmp >> 8) & 0xFF) + ((tmp >> 0) & 0xFF) - 510; 649 } 650 } else if (Res <= 4) { 661 651 Table = mpc_table_HuffQ_8[0][Res - 1]; 662 652 for ( ; k < 36; k += 2 ) { … … 669 659 q[k + 1] = tmp.s2; 670 660 } 671 break; 672 case 5: 673 case 6: 674 case 7: 675 case 8: 661 } else if (Res <= 8) { 676 662 Tables[0] = mpc_table_HuffQ_8 [0][Res - 1]; 677 663 Tables[1] = mpc_table_HuffQ_8 [1][Res - 1]; … … 681 667 idx = (idx >> 1) + absi(q[k]); 682 668 } 683 break; 684 default : 669 } else { 685 670 for ( ; k < 36; k++ ) { 686 671 q[k] = mpc_bits_huff_dec(r, mpc_table_HuffQ9up_8); … … 689 674 q[k] -= Dc[Res]; 690 675 } 691 break;676 } 692 677 } 693 678
Note: See TracChangeset
for help on using the changeset viewer.