diff options
author | Daniil Cherednik <[email protected]> | 2015-12-31 03:33:17 +0300 |
---|---|---|
committer | Daniil Cherednik <[email protected]> | 2015-12-31 03:33:17 +0300 |
commit | 2a96455b748d86c3a93c19da77c5f43b614df869 (patch) | |
tree | 3c98c0b9a85c0b7e868306561ffa362690e11c95 /src/atrac/atrac1_bitalloc.cpp | |
parent | 016da62160aaeba4da182cd80f8b6dfe8c767fad (diff) |
split fixed bit allocation table for short and long blocks
Diffstat (limited to 'src/atrac/atrac1_bitalloc.cpp')
-rw-r--r-- | src/atrac/atrac1_bitalloc.cpp | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/src/atrac/atrac1_bitalloc.cpp b/src/atrac/atrac1_bitalloc.cpp index 971e392..0f5b68f 100644 --- a/src/atrac/atrac1_bitalloc.cpp +++ b/src/atrac/atrac1_bitalloc.cpp @@ -17,6 +17,12 @@ static const uint32_t FixedBitAllocTableLong[MAX_BFUS] = { 4, 4, 3, 3, 3, 3, 3, 3, 2, 2, 2, 1, 1, 0, 0, 0 }; +static const uint32_t FixedBitAllocTableShort[MAX_BFUS] = { + 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, 6, + 6, 6, 6, 6, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, + 4, 4, 4, 4, 4, 4, 4, 4, 0, 0, 0, 0, 0, 0, 0, 0 +}; + static const uint32_t BitBoostMask[MAX_BFUS] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, @@ -96,10 +102,11 @@ uint32_t TBitsBooster::ApplyBoost(std::vector<uint32_t>* bitsPerEachBlock, uint3 } -vector<uint32_t> TAtrac1SimpleBitAlloc::CalcBitsAllocation(const std::vector<TScaledBlock>& scaledBlocks, const uint32_t bfuNum, const double spread, const double shift) { +vector<uint32_t> TAtrac1SimpleBitAlloc::CalcBitsAllocation(const std::vector<TScaledBlock>& scaledBlocks, const uint32_t bfuNum, const double spread, const double shift, const TBlockSize& blockSize) { vector<uint32_t> bitsPerEachBlock(bfuNum); for (int i = 0; i < bitsPerEachBlock.size(); ++i) { - int tmp = spread * ( (double)scaledBlocks[i].ScaleFactorIndex/3.2) + (1.0 - spread) * (FixedBitAllocTableLong[i]) - shift; + const uint32_t fix = blockSize.LogCount[BfuToBand(i)] ? FixedBitAllocTableShort[i] : FixedBitAllocTableLong[i]; + int tmp = spread * ( (double)scaledBlocks[i].ScaleFactorIndex/3.2) + (1.0 - spread) * fix - shift; if (tmp > 16) { bitsPerEachBlock[i] = 16; } else if (tmp < 2) { @@ -163,7 +170,7 @@ uint32_t TAtrac1SimpleBitAlloc::Write(const std::vector<TScaledBlock>& scaledBlo bool bfuNumChanged = false; for (;;) { - const vector<uint32_t>& tmpAlloc = CalcBitsAllocation(scaledBlocks, BfuAmountTab[bfuIdx], spread, shift); + const vector<uint32_t>& tmpAlloc = CalcBitsAllocation(scaledBlocks, BfuAmountTab[bfuIdx], spread, shift, blockSize); uint32_t bitsUsed = 0; for (int i = 0; i < tmpAlloc.size(); i++) { bitsUsed += SpecsPerBlock[i] * tmpAlloc[i]; |