| 593 | } |
| 594 | |
| 595 | void WriteBand_Fmt29(Encoder &enc, int32_t colIndex, uint32_t formatId) { |
| 596 | const float currBitValue = (float)enc.m_currBlockBitValue; |
| 597 | const float halfCurrBitValue = currBitValue * 0.5f; |
| 598 | const int32_t minValue = (int32_t)ceilf(-32767.0f / currBitValue); |
| 599 | const int32_t maxValue = (int32_t)floorf(32767.0f / currBitValue); |
| 600 | |
| 601 | const float *pColumnData = &enc.m_levelSlots[enc.m_levels][colIndex]; |
| 602 | int32_t currSampleIndex = enc.m_samples_per_subband; |
| 603 | while (currSampleIndex) { |
| 604 | --currSampleIndex; |
| 605 | |
| 606 | int32_t val = (int32_t)floorf((*pColumnData + halfCurrBitValue) / currBitValue); |
| 607 | if (minValue > val) { |
| 608 | val = minValue; |
| 609 | } else if (maxValue < val) { |
| 610 | val = maxValue; |
| 611 | } |
| 612 | |
| 613 | int32_t baseValue = val + 5; |
| 614 | pColumnData += enc.m_numColumns; |
| 615 | if (currSampleIndex != 0) { |
| 616 | --currSampleIndex; |
| 617 | |
| 618 | val = (int32_t)floorf((*pColumnData + halfCurrBitValue) / currBitValue); |
| 619 | if (minValue > val) { |
| 620 | val = minValue; |
| 621 | } else if (maxValue < val) { |
| 622 | val = maxValue; |
| 623 | } |
| 624 | |
| 625 | pColumnData += enc.m_numColumns; |
| 626 | } else { |
| 627 | val = 0; |
| 628 | } |
| 629 | |
| 630 | enc.m_bits.WriteBits(11 * val + 55 + baseValue, 7); |
| 631 | } |
| 632 | } |
| 633 | |
| 634 | int ReadSample_init(Encoder &enc, ReadSampleFunction *read, void *data) { |
| 635 | enc.m_reader = read; |