aboutsummaryrefslogtreecommitdiffstats
path: root/src/atrac
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2024-12-12 23:26:24 +0100
committerDaniil Cherednik <dan.cherednik@gmail.com>2024-12-12 23:52:19 +0100
commit39986e653def9d1130235c1cd6a38c3251bb6d79 (patch)
tree0d84f0c219a8784d6ab22c74face2be230fd939a /src/atrac
parent2ca3d7fb3cfdc0b311bb20426d53782910dee64e (diff)
downloadatracdenc-39986e653def9d1130235c1cd6a38c3251bb6d79.tar.gz
[refactoring] Get rid of inheritance from data.
Diffstat (limited to 'src/atrac')
-rw-r--r--src/atrac/atrac1.cpp2
-rw-r--r--src/atrac/atrac1.h20
-rw-r--r--src/atrac/atrac1_bitalloc.cpp52
-rw-r--r--src/atrac/atrac1_bitalloc.h5
-rw-r--r--src/atrac/atrac1_dequantiser.cpp21
-rw-r--r--src/atrac/atrac1_dequantiser.h2
-rw-r--r--src/atrac/atrac3.cpp2
-rw-r--r--src/atrac/atrac3.h3
-rw-r--r--src/atrac/atrac3_bitstream.cpp44
-rw-r--r--src/atrac/atrac3_bitstream.h10
-rw-r--r--src/atrac/atrac_psy_common.cpp1
-rw-r--r--src/atrac/atrac_scale.cpp19
-rw-r--r--src/atrac/atrac_scale.h11
13 files changed, 101 insertions, 91 deletions
diff --git a/src/atrac/atrac1.cpp b/src/atrac/atrac1.cpp
index e128609..d463a1c 100644
--- a/src/atrac/atrac1.cpp
+++ b/src/atrac/atrac1.cpp
@@ -29,5 +29,7 @@ constexpr uint32_t TAtrac1Data::BfuAmountTab[8];
TFloat TAtrac1Data::ScaleTable[64] = {0};
TFloat TAtrac1Data::SineWindow[32] = {0};
+const static TAtrac1Data Atrac1Data;
+
} //namespace NAtrac1
} //namespace NAtracDEnc
diff --git a/src/atrac/atrac1.h b/src/atrac/atrac1.h
index 67c869f..54beedc 100644
--- a/src/atrac/atrac1.h
+++ b/src/atrac/atrac1.h
@@ -55,18 +55,18 @@ class TAtrac1Data {
public:
static constexpr uint8_t MaxBfus = 52;
static constexpr uint8_t NumQMF = 3;
-protected:
- static constexpr uint32_t SpecsPerBlock[MaxBfus] = {
+
+ static constexpr uint32_t SpecsPerBlock[MaxBfus] = {
8, 8, 8, 8, 4, 4, 4, 4, 8, 8, 8, 8, 6, 6, 6, 6, 6, 6, 6, 6, // low band
6, 6, 6, 6, 7, 7, 7, 7, 9, 9, 9, 9, 10, 10, 10, 10, // middle band
12, 12, 12, 12, 12, 12, 12, 12, 20, 20, 20, 20, 20, 20, 20, 20 // high band
- };
- static constexpr uint32_t BlocksPerBand[NumQMF + 1] = {0, 20, 36, 52};
- static constexpr uint32_t SpecsStartLong[MaxBfus] = {
+ };
+ static constexpr uint32_t BlocksPerBand[NumQMF + 1] = {0, 20, 36, 52};
+ static constexpr uint32_t SpecsStartLong[MaxBfus] = {
0, 8, 16, 24, 32, 36, 40, 44, 48, 56, 64, 72, 80, 86, 92, 98, 104, 110, 116, 122,
128, 134, 140, 146, 152, 159, 166, 173, 180, 189, 198, 207, 216, 226, 236, 246,
256, 268, 280, 292, 304, 316, 328, 340, 352, 372, 392, 412, 432, 452, 472, 492,
- };
+ };
static constexpr uint32_t SpecsStartShort[MaxBfus] = {
0, 32, 64, 96, 8, 40, 72, 104, 12, 44, 76, 108, 20, 52, 84, 116, 26, 58, 90, 122,
128, 160, 192, 224, 134, 166, 198, 230, 141, 173, 205, 237, 150, 182, 214, 246,
@@ -74,13 +74,13 @@ protected:
};
static const uint32_t SoundUnitSize = 212;
static constexpr uint32_t BfuAmountTab[8] = {20, 28, 32, 36, 40, 44, 48, 52};
- static const uint32_t BitsPerBfuAmountTabIdx = 3;
- static const uint32_t BitsPerIDWL = 4;
- static const uint32_t BitsPerIDSF = 6;
+ static const uint32_t BitsPerBfuAmountTabIdx = 3;
+ static const uint32_t BitsPerIDWL = 4;
+ static const uint32_t BitsPerIDSF = 6;
static TFloat ScaleTable[64];
static TFloat SineWindow[32];
- uint32_t BfuToBand(uint32_t i) {
+ static uint32_t BfuToBand(uint32_t i) {
if (i < 20)
return 0;
if (i < 36)
diff --git a/src/atrac/atrac1_bitalloc.cpp b/src/atrac/atrac1_bitalloc.cpp
index bb83056..a4b6cd0 100644
--- a/src/atrac/atrac1_bitalloc.cpp
+++ b/src/atrac/atrac1_bitalloc.cpp
@@ -33,29 +33,29 @@ using std::cerr;
using std::endl;
using std::pair;
-static const uint32_t FixedBitAllocTableLong[TAtrac1BitStreamWriter::MaxBfus] = {
+static const uint32_t FixedBitAllocTableLong[TAtrac1Data::MaxBfus] = {
7, 7, 7, 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, 5, 4,
4, 4, 3, 3, 3, 3, 3, 3, 2, 1, 1, 1, 1, 0, 0, 0
};
-static const uint32_t FixedBitAllocTableShort[TAtrac1BitStreamWriter::MaxBfus] = {
+static const uint32_t FixedBitAllocTableShort[TAtrac1Data::MaxBfus] = {
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[TAtrac1BitStreamWriter::MaxBfus] = {
+static const uint32_t BitBoostMask[TAtrac1Data::MaxBfus] = {
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,
1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
TBitsBooster::TBitsBooster() {
- for (uint32_t i = 0; i < MaxBfus; ++i) {
+ for (uint32_t i = 0; i < TAtrac1Data::MaxBfus; ++i) {
if (BitBoostMask[i] == 0)
continue;
- const uint32_t nBits = SpecsPerBlock[i];
+ const uint32_t nBits = TAtrac1Data::SpecsPerBlock[i];
BitsBoostMap.insert(pair<uint32_t, uint32_t>(nBits, i));
}
MaxBitsPerIteration = BitsBoostMap.size() ? (--BitsBoostMap.end())->first : 0;
@@ -108,13 +108,13 @@ TAtrac1SimpleBitAlloc::TAtrac1SimpleBitAlloc(ICompressedOutput* container, uint3
if (ATHLong.size()) {
return;
}
- ATHLong.reserve(MaxBfus);
+ ATHLong.reserve(TAtrac1Data::MaxBfus);
auto ATHSpec = CalcATH(512, 44100);
- for (size_t bandNum = 0; bandNum < this->NumQMF; ++bandNum) {
- for (size_t blockNum = this->BlocksPerBand[bandNum]; blockNum < this->BlocksPerBand[bandNum + 1]; ++blockNum) {
- const size_t specNumStart = this->SpecsStartLong[blockNum];
+ for (size_t bandNum = 0; bandNum < TAtrac1Data::NumQMF; ++bandNum) {
+ for (size_t blockNum = TAtrac1Data::BlocksPerBand[bandNum]; blockNum < TAtrac1Data::BlocksPerBand[bandNum + 1]; ++blockNum) {
+ const size_t specNumStart = TAtrac1Data::SpecsStartLong[blockNum];
float x = 999;
- for (size_t line = specNumStart; line < specNumStart + this->SpecsPerBlock[blockNum]; line++) {
+ for (size_t line = specNumStart; line < specNumStart + TAtrac1Data::SpecsPerBlock[blockNum]; line++) {
x = fmin(x, ATHSpec[line]);
}
x = pow(10, 0.1 * x);
@@ -131,7 +131,7 @@ vector<uint32_t> TAtrac1SimpleBitAlloc::CalcBitsAllocation(const std::vector<TSc
const float loudness) {
vector<uint32_t> bitsPerEachBlock(bfuNum);
for (size_t i = 0; i < bitsPerEachBlock.size(); ++i) {
- bool shortBlock = blockSize.LogCount[BfuToBand(i)];
+ bool shortBlock = blockSize.LogCount[TAtrac1Data::BfuToBand(i)];
const uint32_t fix = shortBlock ? FixedBitAllocTableShort[i] : FixedBitAllocTableLong[i];
float ath = ATHLong[i] * loudness;
//std::cerr << "block: " << i << " Loudness: " << loudness << " " << 10 * log10(scaledBlocks[i].MaxEnergy / ath) << std::endl;
@@ -154,14 +154,14 @@ vector<uint32_t> TAtrac1SimpleBitAlloc::CalcBitsAllocation(const std::vector<TSc
uint32_t TAtrac1SimpleBitAlloc::GetMaxUsedBfuId(const vector<uint32_t>& bitsPerEachBlock) {
uint32_t idx = 7;
for (;;) {
- uint32_t bfuNum = BfuAmountTab[idx];
+ uint32_t bfuNum = TAtrac1Data::BfuAmountTab[idx];
if (bfuNum > bitsPerEachBlock.size()) {
idx--;
} else if (idx != 0) {
assert(bfuNum == bitsPerEachBlock.size());
uint32_t i = 0;
while (idx && bitsPerEachBlock[bfuNum - 1 - i] == 0) {
- if (++i >= (BfuAmountTab[idx] - BfuAmountTab[idx-1])) {
+ if (++i >= (TAtrac1Data::BfuAmountTab[idx] - TAtrac1Data::BfuAmountTab[idx-1])) {
idx--;
bfuNum -= i;
i = 0;
@@ -191,13 +191,15 @@ uint32_t TAtrac1SimpleBitAlloc::Write(const std::vector<TScaledBlock>& scaledBlo
bool autoBfu = !BfuIdxConst;
TFloat spread = AnalizeScaleFactorSpread(scaledBlocks);
- vector<uint32_t> bitsPerEachBlock(BfuAmountTab[bfuIdx]);
+ vector<uint32_t> bitsPerEachBlock(TAtrac1Data::BfuAmountTab[bfuIdx]);
uint32_t targetBitsPerBfus;
uint32_t curBitsPerBfus;
for (;;) {
- bitsPerEachBlock.resize(BfuAmountTab[bfuIdx]);
- const uint32_t bitsAvaliablePerBfus = SoundUnitSize * 8 - BitsPerBfuAmountTabIdx - 32 - 2 - 3 -
- bitsPerEachBlock.size() * (BitsPerIDWL + BitsPerIDSF);
+ bitsPerEachBlock.resize(TAtrac1Data::BfuAmountTab[bfuIdx]);
+ const uint32_t bitsAvaliablePerBfus = TAtrac1Data::SoundUnitSize * 8 -
+ TAtrac1Data::BitsPerBfuAmountTabIdx - 32 - 2 - 3 -
+ bitsPerEachBlock.size() * (TAtrac1Data::BitsPerIDWL + TAtrac1Data::BitsPerIDSF);
+
TFloat maxShift = 15;
TFloat minShift = -3;
TFloat shift = 3.0;
@@ -206,11 +208,11 @@ uint32_t TAtrac1SimpleBitAlloc::Write(const std::vector<TScaledBlock>& scaledBlo
bool bfuNumChanged = false;
for (;;) {
- const vector<uint32_t>& tmpAlloc = CalcBitsAllocation(scaledBlocks, BfuAmountTab[bfuIdx],
+ const vector<uint32_t>& tmpAlloc = CalcBitsAllocation(scaledBlocks, TAtrac1Data::BfuAmountTab[bfuIdx],
spread, shift, blockSize, loudness);
uint32_t bitsUsed = 0;
for (size_t i = 0; i < tmpAlloc.size(); i++) {
- bitsUsed += SpecsPerBlock[i] * tmpAlloc[i];
+ bitsUsed += TAtrac1Data::SpecsPerBlock[i] * tmpAlloc[i];
}
if (bitsUsed < minBits) {
@@ -247,7 +249,7 @@ uint32_t TAtrac1SimpleBitAlloc::Write(const std::vector<TScaledBlock>& scaledBlo
}
ApplyBoost(&bitsPerEachBlock, curBitsPerBfus, targetBitsPerBfus);
WriteBitStream(bitsPerEachBlock, scaledBlocks, bfuIdx, blockSize);
- return BfuAmountTab[bfuIdx];
+ return TAtrac1Data::BfuAmountTab[bfuIdx];
}
TAtrac1BitStreamWriter::TAtrac1BitStreamWriter(ICompressedOutput* container)
@@ -262,7 +264,7 @@ void TAtrac1BitStreamWriter::WriteBitStream(const vector<uint32_t>& bitsPerEachB
const TBlockSize& blockSize) {
NBitStream::TBitStream bitStream;
size_t bitUsed = 0;
- if (bfuAmountIdx >= (1 << BitsPerBfuAmountTabIdx)) {
+ if (bfuAmountIdx >= (1 << TAtrac1Data::BitsPerBfuAmountTabIdx)) {
cerr << "Wrong bfuAmountIdx (" << bfuAmountIdx << "), frame skiped" << endl;
return;
}
@@ -276,8 +278,8 @@ void TAtrac1BitStreamWriter::WriteBitStream(const vector<uint32_t>& bitsPerEachB
bitStream.Write(0, 2);
bitUsed+=4;
- bitStream.Write(bfuAmountIdx, BitsPerBfuAmountTabIdx);
- bitUsed += BitsPerBfuAmountTabIdx;
+ bitStream.Write(bfuAmountIdx, TAtrac1Data::BitsPerBfuAmountTabIdx);
+ bitUsed += TAtrac1Data::BitsPerBfuAmountTabIdx;
bitStream.Write(0, 2);
bitStream.Write(0, 3);
@@ -318,8 +320,8 @@ void TAtrac1BitStreamWriter::WriteBitStream(const vector<uint32_t>& bitsPerEachB
bitStream.Write(0x0, 8);
bitUsed+=8;
- if (bitUsed > SoundUnitSize * 8) {
- cerr << "ATRAC1 bitstream corrupted, used: " << bitUsed << " exp: " << SoundUnitSize * 8 << endl;
+ if (bitUsed > TAtrac1Data::SoundUnitSize * 8) {
+ cerr << "ATRAC1 bitstream corrupted, used: " << bitUsed << " exp: " << TAtrac1Data::SoundUnitSize * 8 << endl;
abort();
}
Container->WriteFrame(bitStream.GetBytes());
diff --git a/src/atrac/atrac1_bitalloc.h b/src/atrac/atrac1_bitalloc.h
index 4c541b8..4a33cb0 100644
--- a/src/atrac/atrac1_bitalloc.h
+++ b/src/atrac/atrac1_bitalloc.h
@@ -19,7 +19,6 @@
#pragma once
#include "atrac_scale.h"
#include "../aea.h"
-#include "../atrac/atrac1.h"
#include <vector>
#include <map>
#include <cstdint>
@@ -36,7 +35,7 @@ public:
virtual uint32_t Write(const std::vector<TScaledBlock>& scaledBlocks, const TBlockSize& blockSize, float loudness) = 0;
};
-class TBitsBooster : public virtual TAtrac1Data {
+class TBitsBooster {
std::multimap<uint32_t, uint32_t> BitsBoostMap; //bits needed -> position
uint32_t MaxBitsPerIteration;
uint32_t MinKey;
@@ -45,7 +44,7 @@ public:
uint32_t ApplyBoost(std::vector<uint32_t>* bitsPerEachBlock, uint32_t cur, uint32_t target);
};
-class TAtrac1BitStreamWriter : public virtual TAtrac1Data {
+class TAtrac1BitStreamWriter {
ICompressedOutput* Container;
public:
explicit TAtrac1BitStreamWriter(ICompressedOutput* container);
diff --git a/src/atrac/atrac1_dequantiser.cpp b/src/atrac/atrac1_dequantiser.cpp
index a259f42..0b1c065 100644
--- a/src/atrac/atrac1_dequantiser.cpp
+++ b/src/atrac/atrac1_dequantiser.cpp
@@ -27,9 +27,9 @@ TAtrac1Dequantiser::TAtrac1Dequantiser() {
}
void TAtrac1Dequantiser::Dequant(TBitStream* stream, const TBlockSize& bs, TFloat specs[512]) {
- uint32_t wordLens[MaxBfus];
- uint32_t idScaleFactors[MaxBfus];
- const uint32_t numBFUs = BfuAmountTab[stream->Read(3)];
+ uint32_t wordLens[TAtrac1Data::MaxBfus];
+ uint32_t idScaleFactors[TAtrac1Data::MaxBfus];
+ const uint32_t numBFUs = TAtrac1Data::BfuAmountTab[stream->Read(3)];
stream->Read(2);
stream->Read(3);
@@ -40,16 +40,17 @@ void TAtrac1Dequantiser::Dequant(TBitStream* stream, const TBlockSize& bs, TFloa
for (uint32_t i = 0; i < numBFUs; i++) {
idScaleFactors[i] = stream->Read(6);
}
- for (uint32_t i = numBFUs; i < MaxBfus; i++) {
+ for (uint32_t i = numBFUs; i < TAtrac1Data::MaxBfus; i++) {
wordLens[i] = idScaleFactors[i] = 0;
}
- for (uint32_t bandNum = 0; bandNum < NumQMF; bandNum++) {
- for (uint32_t bfuNum = BlocksPerBand[bandNum]; bfuNum < BlocksPerBand[bandNum + 1]; bfuNum++) {
- const uint32_t numSpecs = SpecsPerBlock[bfuNum];
+ for (uint32_t bandNum = 0; bandNum < TAtrac1Data::NumQMF; bandNum++) {
+ for (uint32_t bfuNum = TAtrac1Data::BlocksPerBand[bandNum]; bfuNum < TAtrac1Data::BlocksPerBand[bandNum + 1]; bfuNum++) {
+ const uint32_t numSpecs = TAtrac1Data::SpecsPerBlock[bfuNum];
const uint32_t wordLen = !!wordLens[bfuNum] + wordLens[bfuNum];
- const TFloat scaleFactor = ScaleTable[idScaleFactors[bfuNum]];
- const uint32_t startPos = bs.LogCount[bandNum] ? SpecsStartShort[bfuNum] : SpecsStartLong[bfuNum];
+ const TFloat scaleFactor = TAtrac1Data::ScaleTable[idScaleFactors[bfuNum]];
+ const uint32_t startPos = bs.LogCount[bandNum] ?
+ TAtrac1Data::SpecsStartShort[bfuNum] : TAtrac1Data::SpecsStartLong[bfuNum];
if (wordLen) {
TFloat maxQuant = 1.0 / (TFloat)((1 << (wordLen - 1)) - 1);
//cout << "BFU ("<< bfuNum << ") :" << "wordLen " << wordLen << " maxQuant " << maxQuant << " scaleFactor " << scaleFactor << " id " << idScaleFactors[bfuNum] << " num Specs " << numSpecs << " short: "<< (int)bs.LogCount[bandNum] << endl;
@@ -61,7 +62,7 @@ void TAtrac1Dequantiser::Dequant(TBitStream* stream, const TBlockSize& bs, TFloa
}
}
- }
+ }
}
} //namespace NAtrac1
diff --git a/src/atrac/atrac1_dequantiser.h b/src/atrac/atrac1_dequantiser.h
index d3c25bd..95fd250 100644
--- a/src/atrac/atrac1_dequantiser.h
+++ b/src/atrac/atrac1_dequantiser.h
@@ -24,7 +24,7 @@
namespace NAtracDEnc {
namespace NAtrac1 {
-class TAtrac1Dequantiser : public TAtrac1Data {
+class TAtrac1Dequantiser {
public:
TAtrac1Dequantiser();
void Dequant(NBitStream::TBitStream* stream, const TBlockSize& bs, TFloat specs[512]);
diff --git a/src/atrac/atrac3.cpp b/src/atrac/atrac3.cpp
index 82fb34b..363a32e 100644
--- a/src/atrac/atrac3.cpp
+++ b/src/atrac/atrac3.cpp
@@ -42,6 +42,8 @@ double TAtrac3Data::ScaleTable[64] = {0};
double TAtrac3Data::GainLevel[16];
double TAtrac3Data::GainInterpolation[31];
+static const TAtrac3Data Atrac3Data;
+
const TContainerParams* TAtrac3Data::GetContainerParamsForBitrate(uint32_t bitrate) {
// Set default to LP2 mode
if (bitrate == 0) {
diff --git a/src/atrac/atrac3.h b/src/atrac/atrac3.h
index caf49f7..6ce0283 100644
--- a/src/atrac/atrac3.h
+++ b/src/atrac/atrac3.h
@@ -54,7 +54,7 @@ class TAtrac3Data {
public:
static constexpr uint8_t MaxBfus = 32;
static constexpr uint32_t NumSamples = 1024;
-//protected:
+
static const uint32_t MDCTSz = 512;
static double ScaleTable[64];
static double EncodeWindow[256];
@@ -248,6 +248,7 @@ public:
typedef std::vector<TTonalVal> TTonalComponents;
};
+
struct TAtrac3EncoderSettings {
TAtrac3EncoderSettings(uint32_t bitrate, bool noGainControll,
bool noTonalComponents, uint8_t sourceChannels, uint32_t bfuIdxConst)
diff --git a/src/atrac/atrac3_bitstream.cpp b/src/atrac/atrac3_bitstream.cpp
index 9362ca0..e3194b1 100644
--- a/src/atrac/atrac3_bitstream.cpp
+++ b/src/atrac/atrac3_bitstream.cpp
@@ -50,13 +50,13 @@ TAtrac3BitStreamWriter::TAtrac3BitStreamWriter(ICompressedOutput* container, con
if (ATH.size()) {
return;
}
- ATH.reserve(MaxBfus);
+ ATH.reserve(TAtrac3Data::MaxBfus);
auto ATHSpec = CalcATH(1024, 44100);
- for (size_t bandNum = 0; bandNum < this->NumQMF; ++bandNum) {
- for (size_t blockNum = this->BlocksPerBand[bandNum]; blockNum < this->BlocksPerBand[bandNum + 1]; ++blockNum) {
- const size_t specNumStart = this->SpecsStartLong[blockNum];
+ for (size_t bandNum = 0; bandNum < TAtrac3Data::NumQMF; ++bandNum) {
+ for (size_t blockNum = TAtrac3Data::BlocksPerBand[bandNum]; blockNum < TAtrac3Data::BlocksPerBand[bandNum + 1]; ++blockNum) {
+ const size_t specNumStart = TAtrac3Data::SpecsStartLong[blockNum];
float x = 999;
- for (size_t line = specNumStart; line < specNumStart + this->SpecsPerBlock[blockNum]; line++) {
+ for (size_t line = specNumStart; line < specNumStart + TAtrac3Data::SpecsPerBlock[blockNum]; line++) {
x = fmin(x, ATHSpec[line]);
}
x = pow(10, 0.1 * x);
@@ -65,10 +65,10 @@ TAtrac3BitStreamWriter::TAtrac3BitStreamWriter(ICompressedOutput* container, con
}
}
-uint32_t TAtrac3BitStreamWriter::CLCEnc(const uint32_t selector, const int mantissas[MaxSpecsPerBlock],
+uint32_t TAtrac3BitStreamWriter::CLCEnc(const uint32_t selector, const int mantissas[TAtrac3Data::MaxSpecsPerBlock],
const uint32_t blockSize, NBitStream::TBitStream* bitStream)
{
- const uint32_t numBits = ClcLengthTab[selector];
+ const uint32_t numBits = TAtrac3Data::ClcLengthTab[selector];
const uint32_t bitsUsed = (selector > 1) ? numBits * blockSize : numBits * blockSize / 2;
if (!bitStream)
return bitsUsed;
@@ -78,8 +78,8 @@ uint32_t TAtrac3BitStreamWriter::CLCEnc(const uint32_t selector, const int manti
}
} else {
for (uint32_t i = 0; i < blockSize / 2; ++i) {
- uint32_t code = MantissaToCLcIdx(mantissas[i * 2]) << 2;
- code |= MantissaToCLcIdx(mantissas[i * 2 + 1]);
+ uint32_t code = TAtrac3Data::MantissaToCLcIdx(mantissas[i * 2]) << 2;
+ code |= TAtrac3Data::MantissaToCLcIdx(mantissas[i * 2 + 1]);
ASSERT(numBits == 4);
bitStream->Write(code, numBits);
}
@@ -87,12 +87,12 @@ uint32_t TAtrac3BitStreamWriter::CLCEnc(const uint32_t selector, const int manti
return bitsUsed;
}
-uint32_t TAtrac3BitStreamWriter::VLCEnc(const uint32_t selector, const int mantissas[MaxSpecsPerBlock],
+uint32_t TAtrac3BitStreamWriter::VLCEnc(const uint32_t selector, const int mantissas[TAtrac3Data::MaxSpecsPerBlock],
const uint32_t blockSize, NBitStream::TBitStream* bitStream)
{
ASSERT(selector > 0);
- const THuffEntry* huffTable = HuffTables[selector - 1].Table;
- const uint8_t tableSz = HuffTables[selector - 1].Sz;
+ const TAtrac3Data::THuffEntry* huffTable = TAtrac3Data::HuffTables[selector - 1].Table;
+ const uint8_t tableSz = TAtrac3Data::HuffTables[selector - 1].Sz;
uint32_t bitsUsed = 0;
if (selector > 1) {
for (uint32_t i = 0; i < blockSize; ++i) {
@@ -111,7 +111,7 @@ uint32_t TAtrac3BitStreamWriter::VLCEnc(const uint32_t selector, const int manti
for (uint32_t i = 0; i < blockSize / 2; ++i) {
const int ma = mantissas[i * 2];
const int mb = mantissas[i * 2 + 1];
- const uint32_t huffS = MantissasToVlcIndex(ma, mb);
+ const uint32_t huffS = TAtrac3Data::MantissasToVlcIndex(ma, mb);
bitsUsed += huffTable[huffS].Bits;
if (bitStream)
bitStream->Write(huffTable[huffS].Code, huffTable[huffS].Bits);
@@ -153,10 +153,10 @@ std::pair<uint8_t, uint32_t> TAtrac3BitStreamWriter::CalcSpecsBitsConsumption(co
if (precisionPerEachBlocks[i] == 0)
continue;
bits += 6; //sfi
- const uint32_t first = BlockSizeTab[i];
- const uint32_t last = BlockSizeTab[i+1];
+ const uint32_t first = TAtrac3Data::BlockSizeTab[i];
+ const uint32_t last = TAtrac3Data::BlockSizeTab[i+1];
const uint32_t blockSize = last - first;
- const TFloat mul = MaxQuant[std::min(precisionPerEachBlocks[i], (uint32_t)7)];
+ const TFloat mul = TAtrac3Data::MaxQuant[std::min(precisionPerEachBlocks[i], (uint32_t)7)];
if (calcMant) {
const TFloat* values = scaledBlocks[i].Values.data();
CalcMantisas(values, first, last, mul, mantisas);
@@ -190,7 +190,7 @@ static inline bool CheckBfus(uint16_t* numBfu, const vector<uint32_t>& precision
static const std::pair<uint8_t, vector<uint32_t>> DUMMY_ALLOC{1, vector<uint32_t>{0}};
std::pair<uint8_t, vector<uint32_t>> TAtrac3BitStreamWriter::CreateAllocation(const TSingleChannelElement& sce,
- const uint16_t targetBits, int mt[MaxSpecs], float laudness)
+ const uint16_t targetBits, int mt[TAtrac3Data::MaxSpecs], float laudness)
{
const vector<TScaledBlock>& scaledBlocks = sce.ScaledBlocks;
if (scaledBlocks.empty()) {
@@ -253,7 +253,7 @@ std::pair<uint8_t, vector<uint32_t>> TAtrac3BitStreamWriter::CreateAllocation(co
}
void TAtrac3BitStreamWriter::EncodeSpecs(const TSingleChannelElement& sce, NBitStream::TBitStream* bitStream,
- const std::pair<uint8_t, vector<uint32_t>>& allocation, const int mt[MaxSpecs])
+ const std::pair<uint8_t, vector<uint32_t>>& allocation, const int mt[TAtrac3Data::MaxSpecs])
{
const vector<TScaledBlock>& scaledBlocks = sce.ScaledBlocks;
@@ -278,8 +278,8 @@ void TAtrac3BitStreamWriter::EncodeSpecs(const TSingleChannelElement& sce, NBitS
if (precisionPerEachBlocks[i] == 0)
continue;
- const uint32_t first = BlockSizeTab[i];
- const uint32_t last = BlockSizeTab[i+1];
+ const uint32_t first = TAtrac3Data::BlockSizeTab[i];
+ const uint32_t last = TAtrac3Data::BlockSizeTab[i+1];
const uint32_t blockSize = last - first;
if (codingMode == 1) {
@@ -451,7 +451,7 @@ uint16_t TAtrac3BitStreamWriter::EncodeTonalComponents(const TSingleChannelEleme
ASSERT(curGroup.SubGroupPtr[k]->ScaledBlock.Values.size() < 8);
int mantisas[256];
- const TFloat mul = MaxQuant[std::min((uint32_t)(i>>3), (uint32_t)7)];
+ const TFloat mul = TAtrac3Data::MaxQuant[std::min((uint32_t)(i>>3), (uint32_t)7)];
ASSERT(codedValues == curGroup.SubGroupPtr[k]->ScaledBlock.Values.size());
for (uint32_t z = 0; z < curGroup.SubGroupPtr[k]->ScaledBlock.Values.size(); ++z) {
mantisas[z] = lrint(curGroup.SubGroupPtr[k]->ScaledBlock.Values[z] * mul);
@@ -588,7 +588,7 @@ void TAtrac3BitStreamWriter::WriteSoundUnit(const vector<TSingleChannelElement>&
bitsToAlloc[channel] -= bitsUsedByGainInfoAndHeader;
}
- int mt[2][MaxSpecs];
+ int mt[2][TAtrac3Data::MaxSpecs];
std::pair<uint8_t, vector<uint32_t>> allocations[2];
const int32_t msBytesShift = Params.Js ? CalcMSBytesShift(Params.FrameSz, singleChannelElements, bitsToAlloc) : 0; // positive - gain to m, negative to s. Must be zero if no joint stereo mode
diff --git a/src/atrac/atrac3_bitstream.h b/src/atrac/atrac3_bitstream.h
index e67f726..75a39ea 100644
--- a/src/atrac/atrac3_bitstream.h
+++ b/src/atrac/atrac3_bitstream.h
@@ -39,7 +39,7 @@ struct TTonalBlock {
TScaledBlock ScaledBlock;
};
-class TAtrac3BitStreamWriter : public virtual TAtrac3Data {
+class TAtrac3BitStreamWriter {
public:
struct TSingleChannelElement {
TAtrac3Data::SubbandInfo SubbandInfo;
@@ -59,24 +59,24 @@ private:
const uint32_t BfuIdxConst;
std::vector<char> OutBuffer;
- uint32_t CLCEnc(const uint32_t selector, const int mantissas[MaxSpecsPerBlock],
+ uint32_t CLCEnc(const uint32_t selector, const int mantissas[TAtrac3Data::MaxSpecsPerBlock],
const uint32_t blockSize, NBitStream::TBitStream* bitStream);
- uint32_t VLCEnc(const uint32_t selector, const int mantissas[MaxSpecsPerBlock],
+ uint32_t VLCEnc(const uint32_t selector, const int mantissas[TAtrac3Data::MaxSpecsPerBlock],
const uint32_t blockSize, NBitStream::TBitStream* bitStream);
std::vector<uint32_t> CalcBitsAllocation(const std::vector<TScaledBlock>& scaledBlocks,
uint32_t bfuNum, TFloat spread, TFloat shift, TFloat loudness);
std::pair<uint8_t, std::vector<uint32_t>> CreateAllocation(const TSingleChannelElement& sce,
- uint16_t targetBits, int mt[MaxSpecs], float laudness);
+ uint16_t targetBits, int mt[TAtrac3Data::MaxSpecs], float laudness);
std::pair<uint8_t, uint32_t> CalcSpecsBitsConsumption(const TSingleChannelElement& sce,
const std::vector<uint32_t>& precisionPerEachBlocks,
int* mantisas);
void EncodeSpecs(const TSingleChannelElement& sce, NBitStream::TBitStream* bitStream,
- const std::pair<uint8_t, std::vector<uint32_t>>&, const int mt[MaxSpecs]);
+ const std::pair<uint8_t, std::vector<uint32_t>>&, const int mt[TAtrac3Data::MaxSpecs]);
uint8_t GroupTonalComponents(const std::vector<TTonalBlock>& tonalComponents,
const std::vector<uint32_t>& allocTable,
diff --git a/src/atrac/atrac_psy_common.cpp b/src/atrac/atrac_psy_common.cpp
index 71c1190..a034a78 100644
--- a/src/atrac/atrac_psy_common.cpp
+++ b/src/atrac/atrac_psy_common.cpp
@@ -18,6 +18,7 @@
#include "atrac_psy_common.h"
+#include <cmath>
////////////////////////////////////////////////////////////////////////////////
namespace {
diff --git a/src/atrac/atrac_scale.cpp b/src/atrac/atrac_scale.cpp
index edc44a6..fffabbe 100644
--- a/src/atrac/atrac_scale.cpp
+++ b/src/atrac/atrac_scale.cpp
@@ -36,6 +36,13 @@ using std::abs;
static const TFloat MAX_SCALE = 1.0;
template<class TBaseData>
+TScaler<TBaseData>::TScaler() {
+ for (int i = 0; i < 64; i++) {
+ ScaleIndex[TBaseData::ScaleTable[i]] = i;
+ }
+}
+
+template<class TBaseData>
TScaledBlock TScaler<TBaseData>::Scale(const TFloat* in, uint16_t len) {
TFloat maxAbsSpec = 0;
for (uint16_t i = 0; i < len; ++i) {
@@ -71,14 +78,14 @@ template<class TBaseData>
vector<TScaledBlock> TScaler<TBaseData>::ScaleFrame(const vector<TFloat>& specs, const TBlockSize& blockSize) {
vector<TScaledBlock> scaledBlocks;
scaledBlocks.reserve(TBaseData::MaxBfus);
- for (uint8_t bandNum = 0; bandNum < this->NumQMF; ++bandNum) {
+ for (uint8_t bandNum = 0; bandNum < TBaseData::NumQMF; ++bandNum) {
const bool shortWinMode = !!blockSize.LogCount[bandNum];
- for (uint8_t blockNum = this->BlocksPerBand[bandNum]; blockNum < this->BlocksPerBand[bandNum + 1]; ++blockNum) {
- const uint16_t specNumStart = shortWinMode ? TBaseData::SpecsStartShort[blockNum] :
+ for (uint8_t blockNum = TBaseData::BlocksPerBand[bandNum]; blockNum < TBaseData::BlocksPerBand[bandNum + 1]; ++blockNum) {
+ const uint16_t specNumStart = shortWinMode ? TBaseData::SpecsStartShort[blockNum] :
TBaseData::SpecsStartLong[blockNum];
- scaledBlocks.emplace_back(Scale(&specs[specNumStart], this->SpecsPerBlock[blockNum]));
- }
- }
+ scaledBlocks.emplace_back(Scale(&specs[specNumStart], TBaseData::SpecsPerBlock[blockNum]));
+ }
+ }
return scaledBlocks;
}
diff --git a/src/atrac/atrac_scale.h b/src/atrac/atrac_scale.h
index ec83059..f15b14b 100644
--- a/src/atrac/atrac_scale.h
+++ b/src/atrac/atrac_scale.h
@@ -21,7 +21,6 @@
#include <map>
#include <cstdint>
-#include "atrac1.h"
#include "lib/bitstream/bitstream.h"
#include "../config.h"
@@ -37,14 +36,10 @@ struct TScaledBlock {
class TBlockSize;
template <class TBaseData>
-class TScaler : public TBaseData {
- std::map<TFloat, uint8_t>ScaleIndex;
+class TScaler {
+ std::map<TFloat, uint8_t> ScaleIndex;
public:
- TScaler() {
- for (int i = 0; i < 64; i++) {
- ScaleIndex[TBaseData::ScaleTable[i]] = i;
- }
- }
+ TScaler();
TScaledBlock Scale(const TFloat* in, uint16_t len);
std::vector<TScaledBlock> ScaleFrame(const std::vector<TFloat>& specs, const TBlockSize& blockSize);
};