| 328 | } |
| 329 | |
| 330 | void WriteBand_Fmt21(Encoder &enc, int32_t colIndex, uint32_t formatId) { |
| 331 | const float currBlockValue = static_cast<float>(enc.m_currBlockBitValue); |
| 332 | const float halfCurrBlockValue = currBlockValue * 0.5f; |
| 333 | const int32_t minValue = (int32_t)ceilf(-32767.0f / currBlockValue); |
| 334 | const int32_t maxValue = (int32_t)floorf(32767.0f / currBlockValue); |
| 335 | |
| 336 | const float *pCurrSample = &enc.m_levelSlots[enc.m_levels][colIndex]; |
| 337 | int32_t currSampleIndex = enc.m_samples_per_subband; |
| 338 | while (currSampleIndex) { |
| 339 | --currSampleIndex; |
| 340 | int32_t val = (int32_t)floorf((*pCurrSample + halfCurrBlockValue) / currBlockValue); |
| 341 | if (minValue > val) { |
| 342 | val = minValue; |
| 343 | } else if (maxValue < val) { |
| 344 | val = maxValue; |
| 345 | } |
| 346 | |
| 347 | pCurrSample += enc.m_numColumns; |
| 348 | if (!val) { |
| 349 | enc.m_bits.WriteBits(0, 1); |
| 350 | continue; |
| 351 | } |
| 352 | enc.m_bits.WriteBits(1, 1); |
| 353 | |
| 354 | if (val < 0) { |
| 355 | val += 2; |
| 356 | } else { |
| 357 | ++val; |
| 358 | } |
| 359 | |
| 360 | enc.m_bits.WriteBits(val, 2); |
| 361 | } |
| 362 | } |
| 363 | |
| 364 | void WriteBand_Fmt22(Encoder &enc, int32_t colIndex, uint32_t formatId) { |
| 365 | const float currBlockValue = static_cast<float>(enc.m_currBlockBitValue); |