aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/atrac/atrac1.cpp10
-rw-r--r--src/atrac/atrac1.h33
-rw-r--r--src/atrac/atrac1_bitalloc.cpp6
-rw-r--r--src/atrac/atrac1_bitalloc.h10
-rw-r--r--src/atrac/atrac1_dequantiser.cpp2
-rw-r--r--src/atrac/atrac1_dequantiser.h2
-rw-r--r--src/atrac/atrac3.h7
-rw-r--r--src/atrac/atrac_scale.cpp5
-rw-r--r--src/atrac/atrac_scale.h35
-rw-r--r--src/atrac1denc.cpp10
-rw-r--r--src/atrac1denc.h4
-rw-r--r--src/atrac3denc.cpp2
-rw-r--r--src/atracdenc_ut.cpp5
13 files changed, 76 insertions, 55 deletions
diff --git a/src/atrac/atrac1.cpp b/src/atrac/atrac1.cpp
index 0c1c053..b361ad5 100644
--- a/src/atrac/atrac1.cpp
+++ b/src/atrac/atrac1.cpp
@@ -17,6 +17,7 @@
*/
#include "atrac1.h"
+#include "bitstream/bitstream.h"
namespace NAtracDEnc {
namespace NAtrac1 {
@@ -31,5 +32,14 @@ float TAtrac1Data::SineWindow[32] = {0};
const static TAtrac1Data Atrac1Data;
+std::array<int, 3> TAtrac1Data::TBlockSizeMod::Parse(NBitStream::TBitStream* stream) {
+ std::array<int, 3> tmp;
+ tmp[0] = 2 - stream->Read(2);
+ tmp[1] = 2 - stream->Read(2);
+ tmp[2] = 3 - stream->Read(2);
+ stream->Read(2); //skip unused 2 bits
+ return tmp;
+}
+
} //namespace NAtrac1
} //namespace NAtracDEnc
diff --git a/src/atrac/atrac1.h b/src/atrac/atrac1.h
index ae1809b..dfd0fd3 100644
--- a/src/atrac/atrac1.h
+++ b/src/atrac/atrac1.h
@@ -22,6 +22,11 @@
#include <map>
#include <math.h>
#include "config.h"
+
+namespace NBitStream {
+ class TBitStream;
+}
+
namespace NAtracDEnc {
namespace NAtrac1 {
@@ -53,6 +58,34 @@ public:
class TAtrac1Data {
public:
+ class TBlockSizeMod {
+ static std::array<int, 3> Parse(NBitStream::TBitStream* stream);
+ static std::array<int, 3> Create(bool lowShort, bool midShort, bool hiShort) {
+ std::array<int, 3> tmp;
+ tmp[0] = lowShort ? 2 : 0;
+ tmp[1] = midShort ? 2 : 0;
+ tmp[2] = hiShort ? 3 : 0;
+ return tmp;
+ }
+ public:
+ bool ShortWin(uint8_t band) const noexcept {
+ return LogCount[band];
+ }
+
+ TBlockSizeMod(NBitStream::TBitStream* stream)
+ : LogCount(Parse(stream))
+ {}
+
+ TBlockSizeMod(bool lowShort, bool midShort, bool hiShort)
+ : LogCount(Create(lowShort, midShort, hiShort))
+ {}
+
+ TBlockSizeMod()
+ : LogCount({{0, 0, 0}})
+ {}
+
+ std::array<int, 3> LogCount;
+ };
static constexpr uint8_t MaxBfus = 52;
static constexpr uint8_t NumQMF = 3;
diff --git a/src/atrac/atrac1_bitalloc.cpp b/src/atrac/atrac1_bitalloc.cpp
index 5b20cc8..f40ebe2 100644
--- a/src/atrac/atrac1_bitalloc.cpp
+++ b/src/atrac/atrac1_bitalloc.cpp
@@ -127,7 +127,7 @@ vector<uint32_t> TAtrac1SimpleBitAlloc::CalcBitsAllocation(const std::vector<TSc
const uint32_t bfuNum,
const float spread,
const float shift,
- const TBlockSize& blockSize,
+ const TAtrac1Data::TBlockSizeMod& blockSize,
const float loudness) {
vector<uint32_t> bitsPerEachBlock(bfuNum);
for (size_t i = 0; i < bitsPerEachBlock.size(); ++i) {
@@ -186,7 +186,7 @@ uint32_t TAtrac1SimpleBitAlloc::CheckBfuUsage(bool* changed,
return curBfuId;
}
-uint32_t TAtrac1SimpleBitAlloc::Write(const std::vector<TScaledBlock>& scaledBlocks, const TBlockSize& blockSize, float loudness) {
+uint32_t TAtrac1SimpleBitAlloc::Write(const std::vector<TScaledBlock>& scaledBlocks, const TAtrac1Data::TBlockSizeMod& blockSize, float loudness) {
uint32_t bfuIdx = BfuIdxConst ? BfuIdxConst - 1 : 7;
bool autoBfu = !BfuIdxConst;
float spread = AnalizeScaleFactorSpread(scaledBlocks);
@@ -261,7 +261,7 @@ TAtrac1BitStreamWriter::TAtrac1BitStreamWriter(ICompressedOutput* container)
void TAtrac1BitStreamWriter::WriteBitStream(const vector<uint32_t>& bitsPerEachBlock,
const std::vector<TScaledBlock>& scaledBlocks,
uint32_t bfuAmountIdx,
- const TBlockSize& blockSize) {
+ const TAtrac1Data::TBlockSizeMod& blockSize) {
NBitStream::TBitStream bitStream;
size_t bitUsed = 0;
if (bfuAmountIdx >= (1 << TAtrac1Data::BitsPerBfuAmountTabIdx)) {
diff --git a/src/atrac/atrac1_bitalloc.h b/src/atrac/atrac1_bitalloc.h
index ca01b13..a93eba3 100644
--- a/src/atrac/atrac1_bitalloc.h
+++ b/src/atrac/atrac1_bitalloc.h
@@ -18,6 +18,7 @@
#pragma once
#include "atrac_scale.h"
+#include "atrac/atrac1.h"
#include "../aea.h"
#include <vector>
#include <map>
@@ -32,7 +33,7 @@ class IAtrac1BitAlloc {
public:
IAtrac1BitAlloc() {};
virtual ~IAtrac1BitAlloc() {};
- virtual uint32_t Write(const std::vector<TScaledBlock>& scaledBlocks, const TBlockSize& blockSize, float loudness) = 0;
+ virtual uint32_t Write(const std::vector<TScaledBlock>& scaledBlocks, const TAtrac1Data::TBlockSizeMod& blockSize, float loudness) = 0;
};
class TBitsBooster {
@@ -50,12 +51,13 @@ public:
explicit TAtrac1BitStreamWriter(ICompressedOutput* container);
void WriteBitStream(const std::vector<uint32_t>& bitsPerEachBlock, const std::vector<TScaledBlock>& scaledBlocks,
- uint32_t bfuAmountIdx, const TBlockSize& blockSize);
+ uint32_t bfuAmountIdx, const TAtrac1Data::TBlockSizeMod& blockSize);
};
class TAtrac1SimpleBitAlloc : public TAtrac1BitStreamWriter, public TBitsBooster, public virtual IAtrac1BitAlloc {
std::vector<uint32_t> CalcBitsAllocation(const std::vector<TScaledBlock>& scaledBlocks, const uint32_t bfuNum,
- const float spread, const float shift, const TBlockSize& blockSize,
+ const float spread, const float shift,
+ const TAtrac1Data::TBlockSizeMod& blockSize,
const float loudness);
const uint32_t BfuIdxConst;
const bool FastBfuNumSearch;
@@ -66,7 +68,7 @@ class TAtrac1SimpleBitAlloc : public TAtrac1BitStreamWriter, public TBitsBooster
public:
TAtrac1SimpleBitAlloc(ICompressedOutput* container, uint32_t bfuIdxConst, bool fastBfuNumSearch);
~TAtrac1SimpleBitAlloc() {};
- uint32_t Write(const std::vector<TScaledBlock>& scaledBlocks, const TBlockSize& blockSize, float loudness) override;
+ uint32_t Write(const std::vector<TScaledBlock>& scaledBlocks, const TAtrac1Data::TBlockSizeMod& blockSize, float loudness) override;
};
} //namespace NAtrac1
diff --git a/src/atrac/atrac1_dequantiser.cpp b/src/atrac/atrac1_dequantiser.cpp
index bcc087d..74ccc9b 100644
--- a/src/atrac/atrac1_dequantiser.cpp
+++ b/src/atrac/atrac1_dequantiser.cpp
@@ -26,7 +26,7 @@ using namespace NBitStream;
TAtrac1Dequantiser::TAtrac1Dequantiser() {
}
-void TAtrac1Dequantiser::Dequant(TBitStream* stream, const TBlockSize& bs, float specs[512]) {
+void TAtrac1Dequantiser::Dequant(TBitStream* stream, const TAtrac1Data::TBlockSizeMod& bs, float specs[512]) {
uint32_t wordLens[TAtrac1Data::MaxBfus];
uint32_t idScaleFactors[TAtrac1Data::MaxBfus];
const uint32_t numBFUs = TAtrac1Data::BfuAmountTab[stream->Read(3)];
diff --git a/src/atrac/atrac1_dequantiser.h b/src/atrac/atrac1_dequantiser.h
index 0b57c08..8cb58f1 100644
--- a/src/atrac/atrac1_dequantiser.h
+++ b/src/atrac/atrac1_dequantiser.h
@@ -27,7 +27,7 @@ namespace NAtrac1 {
class TAtrac1Dequantiser {
public:
TAtrac1Dequantiser();
- void Dequant(NBitStream::TBitStream* stream, const TBlockSize& bs, float specs[512]);
+ void Dequant(NBitStream::TBitStream* stream, const TAtrac1Data::TBlockSizeMod& bs, float specs[512]);
};
} //namespace NAtrac1
diff --git a/src/atrac/atrac3.h b/src/atrac/atrac3.h
index 103f6fc..ba14773 100644
--- a/src/atrac/atrac3.h
+++ b/src/atrac/atrac3.h
@@ -52,6 +52,13 @@ inline bool operator> (const TContainerParams& x, const unsigned int y)
class TAtrac3Data {
public:
+ class TBlockSizeMod {
+ public:
+ constexpr bool ShortWin(uint8_t) const noexcept {
+ return false;
+ }
+ };
+
static constexpr uint8_t MaxBfus = 32;
static constexpr uint32_t NumSamples = 1024;
diff --git a/src/atrac/atrac_scale.cpp b/src/atrac/atrac_scale.cpp
index d6f5960..911aaa3 100644
--- a/src/atrac/atrac_scale.cpp
+++ b/src/atrac/atrac_scale.cpp
@@ -77,11 +77,12 @@ TScaledBlock TScaler<TBaseData>::Scale(const float* in, uint16_t len) {
}
template<class TBaseData>
-vector<TScaledBlock> TScaler<TBaseData>::ScaleFrame(const vector<float>& specs, const TBlockSize& blockSize) {
+vector<TScaledBlock> TScaler<TBaseData>::ScaleFrame(const vector<float>& specs, const typename TBaseData::TBlockSizeMod& blockSize) {
vector<TScaledBlock> scaledBlocks;
scaledBlocks.reserve(TBaseData::MaxBfus);
for (uint8_t bandNum = 0; bandNum < TBaseData::NumQMF; ++bandNum) {
- const bool shortWinMode = !!blockSize.LogCount[bandNum];
+ const bool shortWinMode = blockSize.ShortWin(bandNum);
+
for (uint8_t blockNum = TBaseData::BlocksPerBand[bandNum]; blockNum < TBaseData::BlocksPerBand[bandNum + 1]; ++blockNum) {
const uint16_t specNumStart = shortWinMode ? TBaseData::SpecsStartShort[blockNum] :
TBaseData::SpecsStartLong[blockNum];
diff --git a/src/atrac/atrac_scale.h b/src/atrac/atrac_scale.h
index 059360d..eff2026 100644
--- a/src/atrac/atrac_scale.h
+++ b/src/atrac/atrac_scale.h
@@ -34,46 +34,13 @@ struct TScaledBlock {
float MaxEnergy;
};
-class TBlockSize;
-
template <class TBaseData>
class TScaler {
std::map<float, uint8_t> ScaleIndex;
public:
TScaler();
TScaledBlock Scale(const float* in, uint16_t len);
- std::vector<TScaledBlock> ScaleFrame(const std::vector<float>& specs, const TBlockSize& blockSize);
-};
-
-class TBlockSize {
- static std::array<int, 4> Parse(NBitStream::TBitStream* stream) {
- //ATRAC1 - 3 subbands, ATRAC3 - 4 subbands.
- //TODO: rewrite
- std::array<int, 4> tmp;
- tmp[0] = 2 - stream->Read(2);
- tmp[1] = 2 - stream->Read(2);
- tmp[2] = 3 - stream->Read(2);
- stream->Read(2); //skip unused 2 bits
- return tmp;
- }
- static std::array<int, 4> Create(bool lowShort, bool midShort, bool hiShort) {
- std::array<int, 4> tmp;
- tmp[0] = lowShort ? 2 : 0;
- tmp[1] = midShort ? 2 : 0;
- tmp[2] = hiShort ? 3 : 0;
- return tmp;
- }
-public:
- TBlockSize(NBitStream::TBitStream* stream)
- : LogCount(Parse(stream))
- {}
- TBlockSize(bool lowShort, bool midShort, bool hiShort)
- : LogCount(Create(lowShort, midShort, hiShort))
- {}
- TBlockSize()
- : LogCount({{0, 0, 0, 0}})
- {}
- std::array<int, 4> LogCount;
+ std::vector<TScaledBlock> ScaleFrame(const std::vector<float>& specs, const typename TBaseData::TBlockSizeMod& blockSize);
};
} //namespace NAtracDEnc
diff --git a/src/atrac1denc.cpp b/src/atrac1denc.cpp
index 0b0ca07..4ac10c1 100644
--- a/src/atrac1denc.cpp
+++ b/src/atrac1denc.cpp
@@ -64,7 +64,7 @@ static void vector_fmul_window(float *dst, const float *src0,
}
}
-void TAtrac1MDCT::Mdct(float Specs[512], float* low, float* mid, float* hi, const TBlockSize& blockSize) {
+void TAtrac1MDCT::Mdct(float Specs[512], float* low, float* mid, float* hi, const TAtrac1Data::TBlockSizeMod& blockSize) {
uint32_t pos = 0;
for (uint32_t band = 0; band < TAtrac1Data::NumQMF; band++) {
const uint32_t numMdctBlocks = 1 << blockSize.LogCount[band];
@@ -97,7 +97,7 @@ void TAtrac1MDCT::Mdct(float Specs[512], float* low, float* mid, float* hi, cons
pos += bufSz;
}
}
-void TAtrac1MDCT::IMdct(float Specs[512], const TBlockSize& mode, float* low, float* mid, float* hi) {
+void TAtrac1MDCT::IMdct(float Specs[512], const TAtrac1Data::TBlockSizeMod& mode, float* low, float* mid, float* hi) {
uint32_t pos = 0;
for (size_t band = 0; band < TAtrac1Data::NumQMF; band++) {
const uint32_t numMdctBlocks = 1 << mode.LogCount[band];
@@ -142,7 +142,7 @@ TPCMEngine::TProcessLambda TAtrac1Decoder::GetLambda() {
TBitStream bitstream(frame->Get(), frame->Size());
- TBlockSize mode(&bitstream);
+ TAtrac1Data::TBlockSizeMod mode(&bitstream);
TAtrac1Dequantiser dequantiser;
vector<float> specs;
specs.resize(512);;
@@ -186,7 +186,7 @@ TPCMEngine::TProcessLambda TAtrac1Encoder::GetLambda() {
auto buf = std::make_shared<TData>(srcChannels);
return [this, srcChannels, bitAlloc, buf](float* data, const TPCMEngine::ProcessMeta& /*meta*/) {
- TBlockSize blockSz[2];
+ TAtrac1Data::TBlockSizeMod blockSz[2];
uint32_t windowMasks[2] = {0};
for (uint32_t channel = 0; channel < srcChannels; channel++) {
@@ -213,7 +213,7 @@ TPCMEngine::TProcessLambda TAtrac1Encoder::GetLambda() {
windowMask = Settings.GetWindowMask();
}
- blockSz[channel] = TBlockSize(windowMask & 0x1, windowMask & 0x2, windowMask & 0x4); //low, mid, hi
+ blockSz[channel] = TAtrac1Data::TBlockSizeMod(windowMask & 0x1, windowMask & 0x2, windowMask & 0x4); //low, mid, hi
auto& specs = (*buf)[channel].Specs;
diff --git a/src/atrac1denc.h b/src/atrac1denc.h
index 86b8546..9756ee2 100644
--- a/src/atrac1denc.h
+++ b/src/atrac1denc.h
@@ -44,8 +44,8 @@ class TAtrac1MDCT {
NMDCT::TMIDCT<256> Midct256;
NMDCT::TMIDCT<64> Midct64;
public:
- void IMdct(float specs[512], const TBlockSize& mode, float* low, float* mid, float* hi);
- void Mdct(float specs[512], float* low, float* mid, float* hi, const TBlockSize& blockSize);
+ void IMdct(float specs[512], const NAtrac1::TAtrac1Data::TBlockSizeMod& mode, float* low, float* mid, float* hi);
+ void Mdct(float specs[512], float* low, float* mid, float* hi, const NAtrac1::TAtrac1Data::TBlockSizeMod& blockSize);
TAtrac1MDCT()
: Mdct512(1)
, Mdct256(0.5)
diff --git a/src/atrac3denc.cpp b/src/atrac3denc.cpp
index f49f1bd..3dc9027 100644
--- a/src/atrac3denc.cpp
+++ b/src/atrac3denc.cpp
@@ -349,7 +349,7 @@ TPCMEngine::TProcessLambda TAtrac3Encoder::GetLambda()
sce->Loudness = l;
//TBlockSize for ATRAC3 - 4 subband, all are long (no short window)
- sce->ScaledBlocks = Scaler.ScaleFrame(specs, TBlockSize());
+ sce->ScaledBlocks = Scaler.ScaleFrame(specs, TAtrac3Data::TBlockSizeMod());
}
if (meta.Channels == 2 && !Params.ConteinerParams->Js) {
diff --git a/src/atracdenc_ut.cpp b/src/atracdenc_ut.cpp
index 416b972..d100bfe 100644
--- a/src/atracdenc_ut.cpp
+++ b/src/atracdenc_ut.cpp
@@ -23,6 +23,7 @@
#include <vector>
using std::vector;
using namespace NAtracDEnc;
+using namespace NAtrac1;
void CheckResult128(const vector<float>& a, const vector<float>& b) {
float m = 0.0;
@@ -69,7 +70,7 @@ TEST(TAtrac1MDCT, TAtrac1MDCTLongEncDec) {
for (int i = 0; i < 256; i++) {
hi[i] = i;
}
- const TBlockSize blockSize(false, false, false);
+ const TAtrac1Data::TBlockSizeMod blockSize(false, false, false);
mdct.Mdct(&specs[0], &low[0], &mid[0], &hi[0], blockSize);
@@ -102,7 +103,7 @@ TEST(TAtrac1MDCT, TAtrac1MDCTShortEncDec) {
}
const vector<float> hiCopy = hi;
- const TBlockSize blockSize(true, true, true); //short
+ const TAtrac1Data::TBlockSizeMod blockSize(true, true, true); //short
mdct.Mdct(&specs[0], &low[0], &mid[0], &hi[0], blockSize);