aboutsummaryrefslogtreecommitdiffstats
path: root/src/atrac/atrac_scale.cpp
diff options
context:
space:
mode:
authorDaniil Cherednik <dan.cherednik@gmail.com>2024-12-24 22:59:03 +0100
committerDaniil Cherednik <dan.cherednik@gmail.com>2024-12-24 22:59:03 +0100
commitbddbeb98b3db8d435de6b2d10269640121475538 (patch)
tree1a791f5dd49b94ead503b9b77c6b9277f2701a89 /src/atrac/atrac_scale.cpp
parentc73a0e24a0d5c510a65efbe5c2fbc7fd39a3c003 (diff)
parent74d6e04c21bddd435bd74c34dbe027b883772a76 (diff)
downloadatracdenc-bddbeb98b3db8d435de6b2d10269640121475538.tar.gz
Merge branch 'master' into at3plus-dev
Diffstat (limited to 'src/atrac/atrac_scale.cpp')
-rw-r--r--src/atrac/atrac_scale.cpp45
1 files changed, 29 insertions, 16 deletions
diff --git a/src/atrac/atrac_scale.cpp b/src/atrac/atrac_scale.cpp
index f24f7b0..d6f5960 100644
--- a/src/atrac/atrac_scale.cpp
+++ b/src/atrac/atrac_scale.cpp
@@ -33,13 +33,20 @@ using std::endl;
using std::abs;
-static const TFloat MAX_SCALE = 1.0;
+static const float MAX_SCALE = 1.0;
template<class TBaseData>
-TScaledBlock TScaler<TBaseData>::Scale(const TFloat* in, uint16_t len) {
- TFloat maxAbsSpec = 0;
+TScaler<TBaseData>::TScaler() {
+ for (int i = 0; i < 64; i++) {
+ ScaleIndex[TBaseData::ScaleTable[i]] = i;
+ }
+}
+
+template<class TBaseData>
+TScaledBlock TScaler<TBaseData>::Scale(const float* in, uint16_t len) {
+ float maxAbsSpec = 0;
for (uint16_t i = 0; i < len; ++i) {
- const TFloat absSpec = abs(in[i]);
+ const float absSpec = abs(in[i]);
if (absSpec > maxAbsSpec) {
maxAbsSpec = absSpec;
}
@@ -48,33 +55,39 @@ TScaledBlock TScaler<TBaseData>::Scale(const TFloat* in, uint16_t len) {
cerr << "Scale error: absSpec > MAX_SCALE, val: " << maxAbsSpec << endl;
maxAbsSpec = MAX_SCALE;
}
- const map<TFloat, uint8_t>::const_iterator scaleIter = ScaleIndex.lower_bound(maxAbsSpec);
- const TFloat scaleFactor = scaleIter->first;
+ const map<float, uint8_t>::const_iterator scaleIter = ScaleIndex.lower_bound(maxAbsSpec);
+ const float scaleFactor = scaleIter->first;
const uint8_t scaleFactorIndex = scaleIter->second;
TScaledBlock res(scaleFactorIndex);
+ float maxEnergy = 0.0;
for (uint16_t i = 0; i < len; ++i) {
- TFloat scaledValue = in[i] / scaleFactor;
+ float scaledValue = in[i] / scaleFactor;
+ float energy = in[i] * in[i];
+ maxEnergy = std::max(maxEnergy, energy);
if (abs(scaledValue) >= 1.0) {
- cerr << "got "<< scaledValue << " it is wrong scalling" << endl;
+ if (abs(scaledValue) > 1.0) {
+ cerr << "clipping, scaled value: "<< scaledValue << endl;
+ }
scaledValue = (scaledValue > 0) ? 0.99999 : -0.99999;
}
res.Values.push_back(scaledValue);
- }
+ }
+ res.MaxEnergy = maxEnergy;
return res;
}
template<class TBaseData>
-vector<TScaledBlock> TScaler<TBaseData>::ScaleFrame(const vector<TFloat>& specs, const TBlockSize& blockSize) {
+vector<TScaledBlock> TScaler<TBaseData>::ScaleFrame(const vector<float>& 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;
}