aboutsummaryrefslogtreecommitdiffstats
path: root/src/atrac/atrac_scale.h
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2016-03-13 09:49:33 +0300
committerDaniil Cherednik <dan.cherednik@gmail.com>2016-09-02 21:21:28 +0300
commitcfaa2cd39b7256a868a4f5cd83aac207df6bd1b3 (patch)
tree75efff26584e046566d17cd308d45b6b0fd5abfc /src/atrac/atrac_scale.h
parentb4df8a7c2dd12eea27c8cc52bd52a1bb8c00943f (diff)
downloadatracdenc-cfaa2cd39b7256a868a4f5cd83aac207df6bd1b3.tar.gz
Dirty implementation of atrac3 encoder:
- no JS mode - constant quantiser for tonal components - gain controll implemented but produces some artifacts with real signals. - etc...
Diffstat (limited to 'src/atrac/atrac_scale.h')
-rw-r--r--src/atrac/atrac_scale.h46
1 files changed, 41 insertions, 5 deletions
diff --git a/src/atrac/atrac_scale.h b/src/atrac/atrac_scale.h
index dd437a2..499fac2 100644
--- a/src/atrac/atrac_scale.h
+++ b/src/atrac/atrac_scale.h
@@ -4,24 +4,60 @@
#include <cstdint>
#include "atrac1.h"
+#include "../config.h"
+
namespace NAtracDEnc {
struct TScaledBlock {
TScaledBlock(uint8_t sfi) : ScaleFactorIndex(sfi) {}
- const uint8_t ScaleFactorIndex = 0;
- std::vector<double> Values;
+ /* const */ uint8_t ScaleFactorIndex = 0;
+ std::vector<TFloat> Values;
};
+class TBlockSize;
+
template <class TBaseData>
class TScaler : public TBaseData {
- std::map<double, uint8_t>ScaleIndex;
+ std::map<TFloat, uint8_t>ScaleIndex;
public:
TScaler() {
for (int i = 0; i < 64; i++) {
ScaleIndex[TBaseData::ScaleTable[i]] = i;
}
}
- std::vector<TScaledBlock> Scale(const std::vector<double>& specs, const TBlockSize& blockSize);
+ TScaledBlock Scale(const TFloat* in, uint16_t len);
+ std::vector<TScaledBlock> ScaleFrame(const std::vector<TFloat>& 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}})
+ {}
+ const std::array<int, 4> LogCount;
};
-}
+} //namespace NAtracDEnc