aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2015-12-31 03:33:17 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2015-12-31 03:33:17 +0300
commit2a96455b748d86c3a93c19da77c5f43b614df869 (patch)
tree3c98c0b9a85c0b7e868306561ffa362690e11c95
parent016da62160aaeba4da182cd80f8b6dfe8c767fad (diff)
downloadatracdenc-2a96455b748d86c3a93c19da77c5f43b614df869.tar.gz
split fixed bit allocation table for short and long blocks
-rw-r--r--src/atrac/atrac1.h7
-rw-r--r--src/atrac/atrac1_bitalloc.cpp13
-rw-r--r--src/atrac/atrac1_bitalloc.h2
3 files changed, 18 insertions, 4 deletions
diff --git a/src/atrac/atrac1.h b/src/atrac/atrac1.h
index e372ac3..37241f6 100644
--- a/src/atrac/atrac1.h
+++ b/src/atrac/atrac1.h
@@ -34,6 +34,13 @@ protected:
static double ScaleTable[64];
static double SineWindow[32];
+ uint32_t BfuToBand(uint32_t i) {
+ if (i < 20)
+ return 0;
+ if (i < 36)
+ return 1;
+ return 2;
+ }
public:
TAtrac1Data() {
if (ScaleTable[0] == 0) {
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];
diff --git a/src/atrac/atrac1_bitalloc.h b/src/atrac/atrac1_bitalloc.h
index 5081a07..1188263 100644
--- a/src/atrac/atrac1_bitalloc.h
+++ b/src/atrac/atrac1_bitalloc.h
@@ -35,7 +35,7 @@ public:
};
class TAtrac1SimpleBitAlloc : public TAtrac1BitStreamWriter, public TBitsBooster, public virtual IAtrac1BitAlloc {
- std::vector<uint32_t> CalcBitsAllocation(const std::vector<TScaledBlock>& scaledBlocks, const uint32_t bfuNum, const double spread, const double shift);
+ std::vector<uint32_t> CalcBitsAllocation(const std::vector<TScaledBlock>& scaledBlocks, const uint32_t bfuNum, const double spread, const double shift, const TBlockSize& blockSize);
const uint32_t BfuIdxConst;
const bool FastBfuNumSearch;
uint32_t GetMaxUsedBfuId(const std::vector<uint32_t>& bitsPerEachBlock);