OLD | NEW |
1 /* Copyright (c) 2007-2008 CSIRO | 1 /* Copyright (c) 2007-2008 CSIRO |
2 Copyright (c) 2007-2009 Xiph.Org Foundation | 2 Copyright (c) 2007-2009 Xiph.Org Foundation |
3 Written by Jean-Marc Valin */ | 3 Written by Jean-Marc Valin */ |
4 /* | 4 /* |
5 Redistribution and use in source and binary forms, with or without | 5 Redistribution and use in source and binary forms, with or without |
6 modification, are permitted provided that the following conditions | 6 modification, are permitted provided that the following conditions |
7 are met: | 7 are met: |
8 | 8 |
9 - Redistributions of source code must retain the above copyright | 9 - Redistributions of source code must retain the above copyright |
10 notice, this list of conditions and the following disclaimer. | 10 notice, this list of conditions and the following disclaimer. |
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
326 we just signaled should be cocentrated in this band. */ | 326 we just signaled should be cocentrated in this band. */ |
327 if (j<=skip_start) | 327 if (j<=skip_start) |
328 { | 328 { |
329 /* Give the bit we reserved to end skipping back. */ | 329 /* Give the bit we reserved to end skipping back. */ |
330 total += skip_rsv; | 330 total += skip_rsv; |
331 break; | 331 break; |
332 } | 332 } |
333 /*Figure out how many left-over bits we would be adding to this band. | 333 /*Figure out how many left-over bits we would be adding to this band. |
334 This can include bits we've stolen back from higher, skipped bands.*/ | 334 This can include bits we've stolen back from higher, skipped bands.*/ |
335 left = total-psum; | 335 left = total-psum; |
336 percoeff = left/(m->eBands[codedBands]-m->eBands[start]); | 336 percoeff = celt_udiv(left, m->eBands[codedBands]-m->eBands[start]); |
337 left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; | 337 left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; |
338 rem = IMAX(left-(m->eBands[j]-m->eBands[start]),0); | 338 rem = IMAX(left-(m->eBands[j]-m->eBands[start]),0); |
339 band_width = m->eBands[codedBands]-m->eBands[j]; | 339 band_width = m->eBands[codedBands]-m->eBands[j]; |
340 band_bits = (int)(bits[j] + percoeff*band_width + rem); | 340 band_bits = (int)(bits[j] + percoeff*band_width + rem); |
341 /*Only code a skip decision if we're above the threshold for this band. | 341 /*Only code a skip decision if we're above the threshold for this band. |
342 Otherwise it is force-skipped. | 342 Otherwise it is force-skipped. |
343 This ensures that we have enough bits to code the skip flag.*/ | 343 This ensures that we have enough bits to code the skip flag.*/ |
344 if (band_bits >= IMAX(thresh[j], alloc_floor+(1<<BITRES))) | 344 if (band_bits >= IMAX(thresh[j], alloc_floor+(1<<BITRES))) |
345 { | 345 { |
346 if (encode) | 346 if (encode) |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
407 if (encode) | 407 if (encode) |
408 ec_enc_bit_logp(ec, *dual_stereo, 1); | 408 ec_enc_bit_logp(ec, *dual_stereo, 1); |
409 else | 409 else |
410 *dual_stereo = ec_dec_bit_logp(ec, 1); | 410 *dual_stereo = ec_dec_bit_logp(ec, 1); |
411 } | 411 } |
412 else | 412 else |
413 *dual_stereo = 0; | 413 *dual_stereo = 0; |
414 | 414 |
415 /* Allocate the remaining bits */ | 415 /* Allocate the remaining bits */ |
416 left = total-psum; | 416 left = total-psum; |
417 percoeff = left/(m->eBands[codedBands]-m->eBands[start]); | 417 percoeff = celt_udiv(left, m->eBands[codedBands]-m->eBands[start]); |
418 left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; | 418 left -= (m->eBands[codedBands]-m->eBands[start])*percoeff; |
419 for (j=start;j<codedBands;j++) | 419 for (j=start;j<codedBands;j++) |
420 bits[j] += ((int)percoeff*(m->eBands[j+1]-m->eBands[j])); | 420 bits[j] += ((int)percoeff*(m->eBands[j+1]-m->eBands[j])); |
421 for (j=start;j<codedBands;j++) | 421 for (j=start;j<codedBands;j++) |
422 { | 422 { |
423 int tmp = (int)IMIN(left, m->eBands[j+1]-m->eBands[j]); | 423 int tmp = (int)IMIN(left, m->eBands[j+1]-m->eBands[j]); |
424 bits[j] += tmp; | 424 bits[j] += tmp; |
425 left -= tmp; | 425 left -= tmp; |
426 } | 426 } |
427 /*for (j=0;j<end;j++)printf("%d ", bits[j]);printf("\n");*/ | 427 /*for (j=0;j<end;j++)printf("%d ", bits[j]);printf("\n");*/ |
(...skipping 30 matching lines...) Expand all Loading... |
458 offset += den<<BITRES>>2; | 458 offset += den<<BITRES>>2; |
459 | 459 |
460 /* Changing the offset for allocating the second and third | 460 /* Changing the offset for allocating the second and third |
461 fine energy bit */ | 461 fine energy bit */ |
462 if (bits[j] + offset < den*2<<BITRES) | 462 if (bits[j] + offset < den*2<<BITRES) |
463 offset += NClogN>>2; | 463 offset += NClogN>>2; |
464 else if (bits[j] + offset < den*3<<BITRES) | 464 else if (bits[j] + offset < den*3<<BITRES) |
465 offset += NClogN>>3; | 465 offset += NClogN>>3; |
466 | 466 |
467 /* Divide with rounding */ | 467 /* Divide with rounding */ |
468 ebits[j] = IMAX(0, (bits[j] + offset + (den<<(BITRES-1))) / (den<<BITRE
S)); | 468 ebits[j] = IMAX(0, (bits[j] + offset + (den<<(BITRES-1)))); |
| 469 ebits[j] = celt_udiv(ebits[j], den)>>BITRES; |
469 | 470 |
470 /* Make sure not to bust */ | 471 /* Make sure not to bust */ |
471 if (C*ebits[j] > (bits[j]>>BITRES)) | 472 if (C*ebits[j] > (bits[j]>>BITRES)) |
472 ebits[j] = bits[j] >> stereo >> BITRES; | 473 ebits[j] = bits[j] >> stereo >> BITRES; |
473 | 474 |
474 /* More than that is useless because that's about as far as PVQ can go
*/ | 475 /* More than that is useless because that's about as far as PVQ can go
*/ |
475 ebits[j] = IMIN(ebits[j], MAX_FINE_BITS); | 476 ebits[j] = IMIN(ebits[j], MAX_FINE_BITS); |
476 | 477 |
477 /* If we rounded down or capped this band, make it a candidate for the | 478 /* If we rounded down or capped this band, make it a candidate for the |
478 final fine energy pass */ | 479 final fine energy pass */ |
(...skipping 150 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
629 bits1[j] = bits1j; | 630 bits1[j] = bits1j; |
630 bits2[j] = bits2j; | 631 bits2[j] = bits2j; |
631 } | 632 } |
632 codedBands = interp_bits2pulses(m, start, end, skip_start, bits1, bits2, thre
sh, cap, | 633 codedBands = interp_bits2pulses(m, start, end, skip_start, bits1, bits2, thre
sh, cap, |
633 total, balance, skip_rsv, intensity, intensity_rsv, dual_stereo, dual_s
tereo_rsv, | 634 total, balance, skip_rsv, intensity, intensity_rsv, dual_stereo, dual_s
tereo_rsv, |
634 pulses, ebits, fine_priority, C, LM, ec, encode, prev, signalBandwidth)
; | 635 pulses, ebits, fine_priority, C, LM, ec, encode, prev, signalBandwidth)
; |
635 RESTORE_STACK; | 636 RESTORE_STACK; |
636 return codedBands; | 637 return codedBands; |
637 } | 638 } |
638 | 639 |
OLD | NEW |