| 654 | |
| 655 | |
| 656 | static int decodeChannelSoundUnit (ATRAC3Context *q, GetBitContext *gb, channel_unit *pSnd, float *pOut, int channelNum, int codingMode) |
| 657 | { |
| 658 | int band, result=0, numSubbands, lastTonal, numBands; |
| 659 | |
| 660 | if (codingMode == JOINT_STEREO && channelNum == 1) { |
| 661 | if (get_bits(gb,2) != 3) { |
| 662 | av_log(NULL,AV_LOG_ERROR,"JS mono Sound Unit id != 3.\n"); |
| 663 | return -1; |
| 664 | } |
| 665 | } else { |
| 666 | if (get_bits(gb,6) != 0x28) { |
| 667 | av_log(NULL,AV_LOG_ERROR,"Sound Unit id != 0x28.\n"); |
| 668 | return -1; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | /* number of coded QMF bands */ |
| 673 | pSnd->bandsCoded = get_bits(gb,2); |
| 674 | |
| 675 | result = decodeGainControl (gb, &(pSnd->gainBlock[pSnd->gcBlkSwitch]), pSnd->bandsCoded); |
| 676 | if (result) return result; |
| 677 | |
| 678 | pSnd->numComponents = decodeTonalComponents (gb, pSnd->components, pSnd->bandsCoded); |
| 679 | if (pSnd->numComponents == -1) return -1; |
| 680 | |
| 681 | numSubbands = decodeSpectrum (gb, pSnd->spectrum); |
| 682 | |
| 683 | /* Merge the decoded spectrum and tonal components. */ |
| 684 | lastTonal = addTonalComponents (pSnd->spectrum, pSnd->numComponents, pSnd->components); |
| 685 | |
| 686 | |
| 687 | /* calculate number of used MLT/QMF bands according to the amount of coded spectral lines */ |
| 688 | numBands = (subbandTab[numSubbands] - 1) >> 8; |
| 689 | if (lastTonal >= 0) |
| 690 | numBands = FFMAX((lastTonal + 256) >> 8, numBands); |
| 691 | |
| 692 | |
| 693 | /* Reconstruct time domain samples. */ |
| 694 | for (band=0; band<4; band++) { |
| 695 | /* Perform the IMDCT step without overlapping. */ |
| 696 | if (band <= numBands) { |
| 697 | IMLT(&(pSnd->spectrum[band*256]), pSnd->IMDCT_buf, band&1); |
| 698 | } else |
| 699 | memset(pSnd->IMDCT_buf, 0, 512 * sizeof(float)); |
| 700 | |
| 701 | /* gain compensation and overlapping */ |
| 702 | gainCompensateAndOverlap (pSnd->IMDCT_buf, &(pSnd->prevFrame[band*256]), &(pOut[band*256]), |
| 703 | &((pSnd->gainBlock[1 - (pSnd->gcBlkSwitch)]).gBlock[band]), |
| 704 | &((pSnd->gainBlock[pSnd->gcBlkSwitch]).gBlock[band])); |
| 705 | } |
| 706 | |
| 707 | /* Swap the gain control buffers for the next frame. */ |
| 708 | pSnd->gcBlkSwitch ^= 1; |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
| 713 | /** |
no test coverage detected