| 468 | } |
| 469 | |
| 470 | void WriteBand_Fmt24(Encoder &enc, int32_t colIndex, uint32_t formatId) { |
| 471 | const float currBlockBitValue = static_cast<float>(enc.m_currBlockBitValue); |
| 472 | const float halfCurrBlockBitValue = currBlockBitValue * 0.5f; |
| 473 | const int32_t minValue = (int32_t)ceilf(-32767.0f / currBlockBitValue); |
| 474 | const int32_t maxValue = (int32_t)floorf(32767.0f / currBlockBitValue); |
| 475 | |
| 476 | const float *pCurrSample = &enc.m_levelSlots[enc.m_levels][colIndex]; |
| 477 | int32_t currSampleIndex = enc.m_samples_per_subband; |
| 478 | while (currSampleIndex) { |
| 479 | --currSampleIndex; |
| 480 | int32_t val = (int32_t)floorf((*pCurrSample + halfCurrBlockBitValue) / currBlockBitValue); |
| 481 | if (minValue > val) { |
| 482 | val = minValue; |
| 483 | } else if (maxValue < val) { |
| 484 | val = maxValue; |
| 485 | } |
| 486 | |
| 487 | pCurrSample += enc.m_numColumns; |
| 488 | if (!val) { |
| 489 | enc.m_bits.WriteBits(0, 1); |
| 490 | continue; |
| 491 | } |
| 492 | |
| 493 | enc.m_bits.WriteBits(1, 1); |
| 494 | |
| 495 | if (val != -1 && val != 1) { |
| 496 | enc.m_bits.WriteBits(1, 1); |
| 497 | |
| 498 | if (val < 0) { |
| 499 | val += 3; |
| 500 | } |
| 501 | enc.m_bits.WriteBits(val, 2); |
| 502 | continue; |
| 503 | } |
| 504 | |
| 505 | enc.m_bits.WriteBits(0, 1); |
| 506 | enc.m_bits.WriteBits((val == 1) ? 1 : 0, 1); |
| 507 | } |
| 508 | } |
| 509 | |
| 510 | void WriteBand_Fmt26(Encoder &enc, int32_t colIndex, uint32_t formatId) { |
| 511 | const float currBlockValue = static_cast<float>(enc.m_currBlockBitValue); |